function slideShow(speed, container, captions, tabs, tabTitle) {

	// add tabs
	if(tabs=="yes") {
		$('#'+container).append('<ul class="slideshow-tabs">'+$('ul.slideshow').html()+'</ul>');
		$('#'+container+' ul.slideshow-tabs li').each(function() {
			$(this).html("<a href='/"+$(this).attr('id')+"/'>"+$(this).attr('title')+"</a>");
			$(this).attr('id', $(this).attr('id')+'Tab');
		});
		if(tabTitle) { $('#'+container+' ul.slideshow-tabs').prepend('<li><strong>'+tabTitle+'&nbsp;</strong></li>'); }
	}

	//append a LI item to the UL list for displaying caption
	if(captions=="yes") {
		$('#'+container+' ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h3></h3><p></p></div></li>');
	}

	//Set the opacity of all images to 0
//	$('#'+container+' ul.slideshow li').css({opacity: 0.0});
$('#'+container+' ul.slideshow li').hide();
	
	//Get the first image and display it (set it to full opacity)
//	$('#'+container+' ul.slideshow li:first').css({opacity: 1.0});
	$('#'+container+' ul.slideshow li:first').show();
	
	//Get the caption of the first image and display it
	$('#'+container+' .slideshow-caption-container h3').text($('#'+container+' ul.slideshow a:first').find('img').attr('title'));
	$('#'+container+' .slideshow-caption-container p').text($('#'+container+' ul.slideshow a:first').find('img').attr('alt'));
	
	// set the selected tab
	$('#'+container+' ul.slideshow-tabs li').removeClass("selected");
	$('#'+container+' ul.slideshow-tabs li#'+$('ul.slideshow li:first').attr("id")+'Tab').addClass("selected");
	
	//Display the caption
	$('#'+container+' #slideshow-caption').css({opacity: 0.65, bottom:0});
	$('#'+container+' #slideshow-caption').fadeIn("normal");	
	
	//Call the gallery function to run the slideshow	
	eval(container+"Timer = setInterval(function(){ gallery(container); },speed)");
	
	//pause the slideshow on mouse over (& hide caption)
	$('#'+container+' ul.slideshow').hover(
		function () {
			eval("clearInterval("+container+"Timer)");
			$('#'+container+' #slideshow-caption').animate({bottom:-350}, 300);
		}, 	
		function () {
			eval(container+"Timer = setInterval(function(){ gallery(container); },speed)");
			$('#'+container+' #slideshow-caption').animate({bottom:0}, 500);	
		}
	);
	
	// bind to tab's mouse over
	$('#'+container+" ul.slideshow-tabs li").mouseover(function(){
			eval("clearInterval("+container+"Timer)");
		    displaySlide($(this).attr("id").replace("Tab",""), container);
//			timer = setInterval('gallery()',speed);			
			eval(container+"Timer = setInterval(function(){ gallery(container); },speed)");
   });
}

function gallery(container) {
	//if no IMGs have the show class, grab the first image
	var current = ($('#'+container+' ul.slideshow li.show')?  $('#'+container+' ul.slideshow li.show') : $('#'+container+' #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')? $('#'+container+' ul.slideshow li:first') :current.next()) : $('#'+container+' ul.slideshow li:first'));
	if(current.attr("id")!=next.attr("id") && current.attr("id")!=undefined) { displaySlide(next.attr("id"), container); }
	}

function displaySlide(thisID, container) {
	var current = ($('#'+container+' ul.slideshow li.show')?  $('#'+container+' ul.slideshow li.show') : $('#'+container+' #ul.slideshow li:first')); // duplicated from previous function
	var next = $('#'+container+' ul.slideshow li#'+thisID);
	
	var title = next.find('img').attr('title');	
	var desc = next.find('img').attr('alt');
	
	//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);
next.fadeIn("normal").addClass("show");
	
	//Hide the caption first, and then set and display the caption
	$('#'+container+' ul.slideshow-tabs li').removeClass("selected");
	$('#'+container+' ul.slideshow-tabs li#'+thisID+'Tab').addClass("selected");
	$('#'+container+' #slideshow-caption').fadeOut("normal", function () {
		//Display the content
		$('#'+container+' #slideshow-caption h3').html(title);
		$('#'+container+' #slideshow-caption p').html(desc);

		$('#'+container+' #slideshow-caption').fadeIn("normal");	
	});		

//Hide the current image
//	current.animate({opacity: 0.0}, 1000).removeClass('show');
current.fadeOut("normal").removeClass("show");
}
