$(function() {
	initSlideShowPhotos();
});

var wait = 4000;
var duration = 1750;
var currentSlideShowPhoto = 0;
var homePhotosSlideShowTimeout;

function initSlideShowPhotos() {
	$('#slideshow img').eq(currentSlideShowPhoto).addClass('active').fadeIn(0);
	
	continueSlideShowPhotosSlideShow();
}

function continueSlideShowPhotosSlideShow() {
	var nextPhoto = currentSlideShowPhoto + 1;
	var numPhotos = $('#slideshow img').length;
	
	if (nextPhoto > (numPhotos - 1)) nextPhoto = 0;
	
	homePhotosSlideShowTimeout = setTimeout(function() {
		revealSlideShowPhoto(nextPhoto);
	}, wait);
}

function revealSlideShowPhoto(nextPhoto) {
	$('#slideshow img.active').css('z-index', '1');
	
	$('#slideshow img').eq(nextPhoto).css('z-index', '5').fadeIn(
		duration,
		'easeOutQuint',
		function() {
			$('#slideshow img.active').fadeOut(0).removeClass('active');
			$(this).addClass('active');
			currentSlideShowPhoto = nextPhoto;
			continueSlideShowPhotosSlideShow();
	});
}
