// hide busy cursor
Exhibit.UI.showBusyIndicator = function (){}
Exhibit.UI.hideBusyIndicator = function (){}

// Handle items dynamically loading from Exhibit
var count = 0;
function onItemShow (e)
{
	//console.log("count = " + window.database.getAllItemsCount());
	count++;
	if (window.database.getAllItemsCount() == count && count > 0)
		var t=setTimeout("configureListItems()",10);
}

function configureListItems ()
{	
	if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
		jQuery(function($) {
			$("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
				return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
			});
		});
	}
	
	// Exhibit ex:showFooter="false" is causing the footer to position incorrectly
	// so implementing custom hide code
	$(".exhibit-collectionView-footer").css("height", "0px").css("overflow", "hidden");
	
	// Add zoom icon on rollover
	$(".dynamic-image a").css("position", "relative");
	$(".dynamic-image a").css("float", "left");
	$(".dynamic-image a").append("<span></span>");
	
	$(".dynamic-image a span").css("background-image", "url(images/zoom.jpg)");
	$(".dynamic-image a span").css("background-repeat", "no-repeat");
	$(".dynamic-image a span").css("width", "24px");
	$(".dynamic-image a span").css("height", "24px");
	$(".dynamic-image a span").css("display", "none");
	$(".dynamic-image a span").css("position", "absolute");
	$(".dynamic-image a span").css("right", "10px");
	$(".dynamic-image a span").css("top", "10px");
	
	$(".dynamic-image img").mouseover(function (e) {
		// check there is an image
		var image = window.database.getObject($(this).attr( "alt" ),"imageDetailsURL1");
		console.log(image);
		if (image)
		{
			$(this).css("border", "7px solid #FDBBC5")
				   .siblings("span").fadeIn(600);
		}
	}).mouseout(function (e) {
		$(this).css("border", "7px solid #F7E3E4")
			   .siblings("span").fadeOut(200);
	}).mouseup(function (e) {
		$(this).css("border", "7px solid #F7E3E4")
			   .siblings("span").fadeOut(200);
	});
	
	//$(".dynamic-title a h1").css('font-family', 'Corben');
	//$(".dynamic-title a h1").css('font-size', '22px');
	//$(".dynamic-title a h1").css('color', '#F597A7');
	
	$(".dynamic-title a").mouseover(function (e) {
		$(this).find("h1").css("color", "#F57283");
		$target = $(this).parent().parent().prev().children(".dynamic-image").find("a img");
		$target.css("border", "7px solid #FDBBC5")
				   .siblings("span").fadeIn(600);
		//$target.fadeIn(600);	
		//console.log($target);
	}).mouseout(function (e) {
		$(this).find("h1").css("color", "#F597A7");
		$target = $(this).parent().parent().prev().children(".dynamic-image").find("a img");
		$target.css("border", "7px solid #F7E3E4")
				   .siblings("span").fadeOut(200);
	}).mouseup(function (e) {
		$(this).find("h1").css("color", "#F597A7");
		$target = $(this).parent().parent().prev().children(".dynamic-image").find("a img");
		$target.css("border", "7px solid #F7E3E4")
				   .siblings("span").fadeOut(200);
	});
}

function openLightBox (itemId)
{
	var image1 = window.database.getObject(itemId,"imageDetailsURL1");
	var image2 = window.database.getObject(itemId,"imageDetailsURL2");
	var image3 = window.database.getObject(itemId,"imageDetailsURL3");
	
	// more than one image
	if (image2)
	{
		var images = [];
		images.push([image1]);
		images.push([image2]);
		if (image3)
			images.push([image3]);
		jQuery.slimbox(images, 0, {loop: true});
	}
	// else at least one image
	else if (image1)
	{
		jQuery.slimbox(image1);
	}
	
	//console.log(itemId);
}
