/* Gallery Javascript */

/* Load-time stuff */
$(document).ready(function() {
	//Add the handlers
	initialiseGallery();

});

/*
* Initialise
*/
function initialiseGallery() {
	$('.imagesBlock a').bind("mouseover",function(e){
		//Mouse enters position over an image
		
		//Set the text
		$('#galleryText').html("<strong>"+$(this).attr('title')+"</strong><br>\n"+$(this).children('img').attr('alt').replace(/\s*\r?\n\s*/,"<br>\n"));
		
		//Show/hide the various bits
		$('.galleryText em').hide();
		$('#galleryText').show();
	});

	$('.imagesBlock a').bind("mouseout",function(e){
		//Mouse leaves position over an image
		
		//Set the text
		$('#galleryText').html('');
		
		//Show/hide the various bits
		$('#galleryText').hide();
		$('.galleryText em').show();
	});
	
	//Check enable/disabling of arrows
	checkArrows();
}

/**
 * Change the gallery page
 *
 * @var string Direction ("previous" or "next")
 */
function changeGallery(direction) {
	if (direction=='previous' && currentPage>1) {
		$(".imagesBlock").scrollTo("-=953px",1000, {axis: 'x'});
		--currentPage;
	} else if (direction=='next' && currentPage<pages) {
		$(".imagesBlock").scrollTo("+=953px",1000, {axis: 'x'});
		++currentPage;
	}
	
	//Enable/disable the arrows
	checkArrows();
	
	//Enable / disable UI buttons
	//Defined in galleySort.js but not always present.
	if(typeof enableDisableButtons == 'function') {
		enableDisableButtons();
	}
	
	return false; //Stop the link firing
}

/**
 * Check whether arrows should be enabled or disabled
 */
function checkArrows() {
	if (currentPage>1) {
		//Enable back	
		$('a.previous').removeClass("disabled");
	} else {
		$('a.previous').addClass("disabled");
	}
	if (currentPage<pages) {
		//Enable next
		$('a.next').removeClass("disabled");
	} else {
		$('a.next').addClass("disabled");	
	}
}