//config
var slideContainerHome = '#homepage-slide-show';
var transitionSpeed = 1000;
var switchSpeed = 5000;

// retrieve a list of images from server 	
$(function() {    
	$.getJSON('../json/json_slideshow_home.php', startSlideshowHome); 
	
	function startSlideshowHome(slidesHome) {

		var startingImageSrc = '/' + $(slideContainerHome + ' > img').attr('src');

		$.each(slidesHome, function(index, value) {
			//ignore the first image
			if (value != startingImageSrc) {
				$('<img src="' + value + '"/>').appendTo(slideContainerHome);
			}
		});
		
		slideTimerHome();
	};	
});    

// switch the image 
function slideSwitchHome() {
	var $active = $(slideContainerHome + ' img.active');
	
	if ( $active.length == 0 ) {
		$active = $(slideContainerHome + ' img:first');
	}
	
	var $next =  $active.next('img').length ? $active.next('img') : $(slideContainerHome + ' img:first');
		
	$active.addClass('last-active');
		
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, transitionSpeed, function() {
			$active.removeClass('active last-active');
		});
};

// timer
function slideTimerHome() {
	setInterval ("slideSwitchHome()", switchSpeed);    
};
