// Javascript for the gallery thumbnail scroller
// (C) Steph Reed 2009

var current_photo = 0;

function scrollUp() {
 
	if( current_photo > 0 ) {
		current_photo --;
		$("#thumbnail_scroller").scrollTo( "#thumb-" + current_photo,  500, {axis:'y'} );
		}

}

function scrollDown() {
	// Scroll to the next thumbnail if it exists

	if( $("#thumbnail_scroller").scrollTop() < ( $("#thumbnails").height() - $("#thumbnail_scroller").height() ) ) {
		current_photo ++;

		if( $("#thumb-" + current_photo).length > 0 )
			$("#thumbnail_scroller").scrollTo( "#thumb-" + current_photo,  500, {axis:'y'} );
		}
}


function fadePhoto( photo, comment, alt ) {
 // Crossfade to a new photo
 debug("fadePhoto called", 0 );

 // Show the loading animation
 debug( "Show Loader", 1 );
 $("#loader").show();

 // Setup the photo fade
 $("#photo2").unbind().load( function () {
	debug( "#photo2.load called", 0 );
	// Hide the loading animation
	debug( "Hide Loader", 1 );
	$("#loader").hide();

	// Set the comment
	debug( "Set comment", 1 );
	$("#photoComment").html( '<span>' + comment + '</span>' );

	// Fade out the old photo
	debug( "Fade out(2000) #photo1", 1 );
	$("#photo1").fadeOut( 2000 );

	// Fade in the new photo
	$(this).fadeIn( 2000, function () {
		// Set the same photo for the first image
		debug( "Set #photo1 source", 2 );
		$("#photo1").attr('src', $("#photo2").attr('src') );
		
		// Show the first photo, hide the second
		debug( "Fade in(0) #photo1", 2 );
		$("#photo1").fadeIn( 0 );
		debug( "fade out(0) #photo2", 2 );
		$("#photo2").fadeOut( 0 );
		} );
	} );

 // Set the source of the new photo
 debug( "Set #photo2 source", 1 );
 $("#photo2").attr('src', photo);

 // Set the 'alt' text for the photo
 debug( "Set alt text", 1 );
 $("#photo1").attr( 'alt', alt );
 }
