function slideShow(speed) {  
    //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"><h3></h3><p></p></div></li>');  
      
    //Get the first image and display it (set it to full opacity)  
    $('ul.slideshow li:first').css({opacity: 1.0});  

	// fill the caption
	$('#caption').html($('#caption1').html());

    // display the caption
	$('#caption').css({opacity: 1, bottom: 0});  

	// get the offset for the initial caption
	offset = $('.slideshow a img').offset();
	left = offset.left;
	$('#caption').css('top', offset.top + $('.slideshow a img').height() + 5).css('left', left);

    //Call the gallery function to run the slideshow      
    var timer = setInterval('gallery()',speed);  
}  
  
function gallery() {  
    //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's index
    var nextIndex = next.find('img').attr('title');   

	// get the next caption
	nextCaption = $('#caption' + nextIndex).html();
          
    //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  
	$('#caption').fadeOut(300, function () {
		// get the image's height and position
		height = next.height();
		offset = next.children('a').children('img').offset();

		// set the caption offset
		left = offset.left;
		
		// Set the content for the background
		$('#caption').html(nextCaption).css('top', offset.top + height + 5).css('left', left).fadeIn(500);     
    });
  
    //Hide the current image  
    current.animate({opacity: 0.0}, 1000).removeClass('show');
}
