// -----------------------------------------------------------------------------
// Define Script Variables 
pause = 4000;
fadeIn = 1000;
fadeOut = 1000;

// -----------------------------------------------------------------------------
// When the document is ready


// -----------------------------------------------------------------------------
// Static Functions
function slideshow() {

	// Set the opacity of all images to 0
	$('#slideshow dt').css({opacity: 0.0});
	$('#slideshow dd').css({opacity: 0.0});

	showInitial();	
	setInterval('imageNext()', pause);
}

function imageNext() {

	// Find the current image, which is tagged with class 'show'
    var $current = ($('#slideshow dt.show')?  $('#slideshow dt.show') : $('#slideshow dt:first'));

	// Get the next image from the image list
	var $images = $('#slideshow dt');
	var index = $images.index($current);
	
	var nextIndex = 0
	if (index < $images.length - 1) {
		nextIndex = index + 1;
	} 
	var $nextImage = $($images.get(nextIndex));	

	// Hide current image
	hideImage($current);

	// Show next image
	showImage($nextImage);
}

function showInitial() {
	// Show the first image + caption
	$('#slideshow dt:first').css({opacity: 1.0});
	$('#slideshow dd:first').css({opacity: 1.0});	
}

function showImage($image) {
	// Show Image
	$image.animate({opacity: 1.0}, fadeIn);
	$image.addClass('show');
	
	// Show Caption
	$caption = $image.next('dd');
	$caption.animate({opacity: 1.0}, fadeIn);
}

function showImage($image) {
	// Show Image
	$image.animate({opacity: 1.0}, fadeIn);
	$image.addClass('show');
	
	// Show Caption
	$caption = $image.next('dd');
	$caption.animate({opacity: 1.0}, fadeIn);
}

function hideImage($image) {
	// Hide Image
	$image.animate({opacity: 0.0}, fadeOut);
	$image.removeClass('show');	
	
	// Hide Caption
	$caption = $image.next('dd');
	$caption.animate({opacity: 0.0}, fadeOut);
}

