// JavaScript Document
var homeSwitchActu = 1;
var handleTimer = null;

$(document).ready(function () {
	MM_preloadImages('images/photos/ble.jpg','images/photos/usinediurne.jpg','images/photos/usinenocturne.jpg','images/photos/vegetal.jpg','images/photos/carton.jpg','images/photos/marrebasse.jpg');			

	$('.logo').hide();
	$('.baseline').hide();
	//if ($('#content-1')) $('#content-1').hide();
	//if ($('#content-2')) $('#content-2').hide();
	//if ($('#content-3')) $('#content-3').hide();
	
	if ($('#content-1').length) $('#content-1').css('opacity', '0').animate({top: '+=10'}, 1);
	if ($('#content-2').length) $('#content-2').css('opacity', '0').animate({top: '+=10'}, 1);
	if ($('#content-3').length) $('#content-3').css('opacity', '0').animate({top: '+=20'}, 1);
	
	if ($('#actus').length) {
		$('.news_box').css('opacity', '0').css('display', 'none');
		$('#actus').css('opacity', '0').animate({top: '+=10'}, 1);
		homeSwitchActu = 1;
	}
	
	
	$('.logo').fadeIn(1000);
	$('.baseline').fadeIn(1500);
	//if ($('#content-1')) $('#content-1').fadeIn(2000);
	//if ($('#content-2')) $('#content-2').fadeIn(3000);
	//if ($('#content-3')) $('#content-3').fadeIn(4000);
	
	if ($('#content-1').length) $('#content-1').animate({opacity: 1, top: '-=10'}, 300);
	if ($('#content-2').length) $('#content-2').animate({opacity: 1, top: '-=10'}, 300);
	if ($('#content-3').length) $('#content-3').animate({opacity: 1, top: '-=20'}, 600);
	
	if ($('#actus').length) $('#actus').animate({opacity: 1, top: '-=10'}, 1000, function () { switchactus(); });
	
	$('.logo').click(function () {
		document.location.href="index.php";						   
	});
	
	if ($('#actus').length) {
		$('#actus').hover(
		  function () {
			clearTimeout(handleTimer);
		  },
		  function () {
			handleTimer = setTimeout(switchactus,1000);
		  }
		);
	}
});

function switchactus() {
	
	$('#news_box' + homeSwitchActu).css('opacity', '0').css('display', 'none');
	
	homeSwitchActu += 1;
	if (homeSwitchActu > 5) homeSwitchActu = 1;
	
	$('#news_box' + homeSwitchActu).css('display', 'block').animate({opacity: 1}, 300);
	
	handleTimer = setTimeout(switchactus,5000);
}

function switchactus_old() {
	$('#news_box' + homeSwitchActu).fadeOut(1000, function(element) {
		$('#news_box' + homeSwitchActu).hide('fast', function() {
			$('#news_box' + homeSwitchActu).css('opacity', '0');
			homeSwitchActu += 1;
			if (homeSwitchActu > 5) homeSwitchActu = 1;
			$('#news_box' + homeSwitchActu).css('opacity', '1');
			$('#news_box' + homeSwitchActu).fadeIn(600);
		});
	});

	setTimeout(switchactus,2000);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}