// Slideshow
$(document).ready(function(){
	// Only activate the slideshow if there are more than two records.
	if(document.getElementById("slideshow_records") && document.getElementById("slideshow_records").value >= 2){
		// Settings
		images_total = document.getElementById("slideshow_records").value;
		current_image = 1;
		fade_direction = "out";
		
		// Set an interval to rotate the images.
		setInterval("rotate_images()",4000);
	}
});

// Rotate the images.
function rotate_images(){
	// Fade out the image.
	if(fade_direction == "out"){
		$("#slideshow_"+current_image).fadeOut(2000);
	}else{
		$("#slideshow_"+current_image).fadeIn(2000);
	}
	
	// Tally up the current image.
	current_image = (current_image+1);

	// Restart back at the first image if we're at the last.
	if(current_image >= images_total){
		current_image = 1;
		
		// Reverse the fade direction
		if(fade_direction == "out"){
			fade_direction = "in";
		}else{
			fade_direction = "out";
		}
	}
}