// JavaScript Document

$(document).ready(function() {
	var timeout		= 4000,
		nbpic   	= 0,
		slidetimer 	= 0,
		currentpic 	= 0;
	
	nbpic = $('#headerSlideshow img').length;
	
	if(nbpic==0) {
		$('#headerSlideshow').hide();
	} else {
		$('#headerSlideshow img').hide();
		$('#headerSlideshow img:first-child').fadeIn();
	
		$(window).load(function() {
			function displayNextPicture() {
				currentpic++;
				if(currentpic == nbpic) currentpic = 0;
				
				$('#headerSlideshow img:visible').hide();
				$('#headerSlideshow img:nth-child('+eval(currentpic+1)+')').fadeIn();
				slidetimer = window.setTimeout(displayNextPicture, timeout);
			};
			
			if(nbpic>1) {
				slidetimer = window.setTimeout(displayNextPicture, timeout);
			}
		});
	}
						   
});
