//original source code
//http://www.queness.com/post/152/simple-jquery-image-slide-show-with-semi-transparent-caption

$(document).ready(function() {		
	
//Execute the slideShow
	slideShow();

});

var slideshowId = 0;
var slideshowSpeed = 6000;
var slideshowDoFade = true;

function slideShow() {

	// IE6 fix
	if($.browser.msie && $.browser.version.substring(0,1) == '6') {
		slideshowDoFade = false;
	}
	
	if(slideshowDoFade) {
		//Set the opacity of all images to 0
		$('#homeslide a.item').show().css({opacity: 0.0}).find(".caption").hide();
		
		//Get the first image and display it (set it to full opacity)
		$('#homeslide a.item:first').css({opacity: 1.0}).find(".caption").show();
	} else {
		$('#homeslide a.item').hide();
		$('#homeslide a.item:first').show();
	}
	
	//Resize the width of the caption according to the image width
	$('#homeslide .caption').width($('#homeslide a.item').width());
	
	//Get the caption of the first image from the title attribute and display it
//	$('#homeslide .content').html($('#homeslide a.item:first').find('.image').attr('slide_header'));
	
	$('#homeslide .panel a').toggle(
			function() {
				resumeSlideshow();
			},
			function() {
				pauseSlideshow();
			}
	).click();
}

function animation() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#homeslide a.show')?  $('#homeslide a.show') : $('#homeslide a.item: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().hasClass('caption'))? $('#homeslide a.item:first') :current.next()) : $('#homeslide a.item:first'));	
	
	//Get next image caption
//	var caption = next.find('.image').attr('slide_header');	

	
	if(slideshowDoFade) {
		//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 current image
		current.animate({opacity: 0.0}, 1000)
		.removeClass('show');
	} else {
		current.hide().removeClass('show');
		next.addClass('show').show();
	}
	
	$('#homeslide .caption').animate({height: '1px'}, { queue:true, duration:300, complete:function() {
        $(this).hide();
    } });
	next.find(".caption").animate({height: '35px'}, { queue:true, duration:500 });
}

function pauseSlideshow() {
	$('#homeslide .panel a').html('Resume');

	if(slideshowId) {
		clearInterval(slideshowId);
	}
}

function resumeSlideshow() {
	$('#homeslide .panel a').html('Pause');
	
	//Call the  function to run the slideshow, 6000 = change to next image after 6 seconds
	slideshowId = setInterval('animation()', slideshowSpeed);
}