/**
 * @author elz
 * elz064@gmail.com Dzi-nëo et Nëo-tekk
 * inspiré par http://www.alohatechsupport.net/webdesignmaui/maui-web-site-design/easy_jquery_auto_image_rotator.html
 */


function theRotator() {
	//Set the opacity of all images to 0
	$('div.diapos ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div.diapos #diapos1 ul li:first').css({opacity: 1.0});
	$('div.diapos #diapos2 ul li:first').css({opacity: 1.0});
	$('div.diapos #diapos3 ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('enchaine()',3500);
	
}

function enchaine() {	
	//Get the first image
var current1 = ($('div.diapos #diapos1 ul li.show')?  $('div.diapos #diapos1 ul li.show') : $('div.diapos #diapos1 ul li:first'));
var current2 = ($('div.diapos #diapos2 ul li.show')?  $('div.diapos #diapos2 ul li.show') : $('div.diapos #diapos2 ul li:first'));
var current3 = ($('div.diapos #diapos3 ul li.show')?  $('div.diapos #diapos3 ul li.show') : $('div.diapos #diapos3 ul li:first'));
	//Get next image, when it reaches the end, rotate it back to the first image
	var next1 = ((current1.next().length) ? ((current1.next().hasClass('show')) ? $('div.diapos #diapos1 ul li:first') :current1.next()) : $('div.diapos #diapos1 ul li:first'));	
	var next2 = ((current2.next().length) ? ((current2.next().hasClass('show')) ? $('div.diapos #diapos2 ul li:first') :current2.next()) : $('div.diapos #diapos2 ul li:first'));	
	var next3 = ((current3.next().length) ? ((current3.next().hasClass('show')) ? $('div.diapos #diapos3 ul li:first') :current3.next()) : $('div.diapos #diapos3 ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next1.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	
	next2.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1800);
	
	next3.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 3600);

	//Hide the current image
	current1.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	current2.animate({opacity: 0.0}, 1700)
	.removeClass('show');
	
	current3.animate({opacity: 0.0}, 2300)
	.removeClass('show');
	
};

function intro(){
	//$('div#intro').hide();
	setInterval('moving_intro()',7000);
}

function moving_intro(){
	$('div#intro').fadeOut(800);
	$('div#intro').css({ left: "10" });
	$('div#intro').fadeIn('slow');
	//$('div#intro').fadeTo("4000", 1.0, function(){
	//$(this).fadeTo("7000", 0.2);
	//});
	
	
	
	
	$('div#intro').animate({
  		color: '#7C1908'}, 4000, function(){
			$(this).animate({color: '#EA300F'}, 7000);
			}
		);
	
	
	
}



$(document).ready(function() {		
	//Load the slideshow
	theRotator();
	intro();

});


  

