$(function() {
	//---------------------------------------------------
	// Positionement bloc centre de la Home
	//---------------------------------------------------
	$(window).load(function() {
		$width_visuel_home	= $('.taille-contenu').width();
		$('#contenu').width($width_visuel_home);
	})
	
	$(window).resize(function() {
		$width_visuel_home	= $('.taille-contenu').width();
		$('#contenu').width($width_visuel_home);
	});
	
	//---------------------------------------------------
	// Pour faire rentrer l'actualité
	//---------------------------------------------------
	$test_act	= "ok";
	$height_actu = $('#actualite').height();
	$('#titre-actu a').click(function() {
		if ( $test_act == "ok" )
		{
			$('#actualite').animate({
	    		height: 24
	    	}, 500, function(){
	    		$('#titre-actu a').attr('class', 'montant');
				$test_act	= "no";
			});
		}
		if ( $test_act == "no" )
		{
			$('#actualite').animate({
	    		height: $height_actu+'px'
	    	}, 500, function(){
	    		$('#titre-actu a').attr('class', 'descendant');
				$test_act	= "ok";
			});
		}
		return false;
	});
	
	//---------------------------------------------------
	// On lance la diaporama de la home
	//---------------------------------------------------
	$i = 1;
	$nb_visuel	= 10; // Le nombre de visuel a faire tourner
	$("body").everyTime(8000,function() {
		$i++;
		showVisuelHome($i);
		
		if ($i == $nb_visuel) $i=0;
	});
	$('#fleche-gauche, #fleche-droite').click(function(){
		$("body").stopTime();
	});
});

//-----------------------------------------------------
// On fait tourner les visuels sur la Home page
//-----------------------------------------------------
function showVisuelHome(id){
	$('img.visuel-home').fadeOut(function() {
		$('img.visuel-home').attr('src', 'images/visuel-ambiance-home-'+id+'.jpg');
		$('img.visuel-home').fadeIn();
	});
	
	// On change lavalue des flèches
	$valeur_id_gauche = id - 1;
	$valeur_id_droite = id + 1;
	if ( id == $nb_visuel )
	{
		$('#fleche-droite').attr('onclick', 'showVisuelHome(1);');
	}
	else
	{
		$('#fleche-droite').attr('onclick', 'showVisuelHome('+$valeur_id_droite+');');
	}
	if ( id == 1 )
	{
		$('#fleche-gauche').attr('onclick', 'showVisuelHome('+$nb_visuel+');');
	}
	else
	{
		$('#fleche-gauche').attr('onclick', 'showVisuelHome('+$valeur_id_gauche+');');
	}
};
