var nextDescription = "";
function slideShow(speed) {
	var desc;
	//append a LI item to the UL list for displaying caption
	$('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><p class="slideshow-caption-desc"></p></div></li>');

	//Set the opacity of all images to 0
	$('ul.slideshow li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.slideshow li:first').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	desc = $('ul.slideshow img').attr('alt');
	$('.slideshow-caption-desc').html(desc);
		
	//Display the caption
	$('#slideshow-caption').css({opacity: 0.7, bottom:0});
	
	//Call the gallery function to run the slideshow	
	var timer = setInterval('changeImage()',speed);
}

function changeImage() {

	//if no IMGs have the show class, grab the first image
	var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));
		
	//Get next image caption
	//var title = next.find('img').attr('title');	
	var desc = "<div>";
	desc += next.children('img').attr('alt');	
	desc += "</div>";

	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	
	//Hide the caption first, and then set and display the caption
	nextDescription = desc;
		
	$('#slideshow-caption').slideUp(300);
	setTimeout("changeCaption()", 320);
	
	//Hide the current image
	current.animate({opacity: 0.0}, 1000).removeClass('show');

}

function changeCaption() {
	$('.slideshow-caption-desc').html(nextDescription);
	$('#slideshow-caption').slideDown(300);
}

function showContainer(desc) {
	//$('#slideshow-caption').animate({bottom:0}, 500);
}
