$(document).ready(function() {		
	//Set the opacity of all images to 0
	$('#slideshow_home img').css({opacity: 0.0});		
	//Get the first image and display it
	$('#slideshow_home img:first').fadeTo("slow", 1.0); 	
	//Set Start Interval
	sliderIntervalID = setInterval(slideshow_home,3000); 
	//Mouse events
	$('#slideshow_home a').hover(function() {
		clearInterval(sliderIntervalID);
		hovergal($(this).attr('rel'), $(this)); 
	}, function() {
		sliderIntervalID = setInterval(slideshow_home,3000);
	});
});
function slideshow_home() {	
	//if no image have the show class go to the first
	var currentPic = ($('#slideshow_home img.show')?  $('#slideshow_home img.show') : $('#slideshow_home img:first'));
	var currentLink = ($('#slideshow_home a.show')?  $('#slideshow_home a.show') : $('#slideshow_home a:first'));		
	//Get next image or go back to the first
	var nextPic = ((currentPic.next().length) ? ((currentPic.next().hasClass('caption'))? $('#slideshow_home img:first') :currentPic.next()) : $('#slideshow_home img:first'));	
	var nextLink = ((currentLink.next().length) ? ((currentLink.next().hasClass('caption'))? $('#slideshow_home a:first') :currentLink.next()) : $('#slideshow_home a:first'));
	//Hide the current image
	currentPic.stop().animate({opacity: 0.0}, 800)
	.removeClass('show');		
	//Show the next image
	nextPic.stop().css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 800);		
	//Remove class to link
	currentLink.removeClass('show');		
	//Set class to link
	nextLink.addClass('show');
}
function hovergal(nextPic, nextLink) {  
	//if no image have the show class go to the first
	var currentPic = ($('#slideshow_home img.show')?  $('#slideshow_home img.show') : $('#slideshow_home img:first'));
	var currentLink = ($('#slideshow_home a.show')?  $('#slideshow_home a.show') : $('#slideshow_home a:first'));
	//check if show
	if(currentLink.attr('class')==nextLink.attr('class')){
		return false;
	}else{	
	//Hide the current image
	currentPic.stop().animate({opacity: 0.0}, 400)
	.removeClass('show');				
	//Show the next image
	 $('#slideshow_home img.'+nextPic).stop().css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 400);			
	//Remove class to link
	currentLink.removeClass('show'); 		
	//Set class to link
	nextLink.addClass('show');
	}
}  