;
var Homefreeze=0;
var Homeplay=1;
function animateHome(){
	$("#accordion").bind('mousemove',function(){Homefreeze=2;}).bind('mouseleave',function(){Homefreeze=1;}).keypress(function(){if (Homeplay){Homeplay=0;$("#pause").hide();$("#play").show()}});
	var count=0;
	$("#accordion .ui-accordion-header").each(function(){
		$(this).attr('data-order',count++).bind('mouseover',function(){
			if ($(this).is('.ui-state-active')) return;
			$("#accordion").activatewithoutfocus($(this).attr('data-order'));
		});
	});
	$("#pause").click(function(){Homeplay=0;$(this).hide();$("#play").show();return false;});
	$("#play").click(function(){Homeplay=1;$(this).hide();$("#pause").show();return false;});
	$("#accordion .ui-accordion-header")
		.bind('click',function(){window.location.href = $(this).find('a').get(0).href;})
		.bind('keypress',function(e){if (e.keyCode=='13') window.location.href = $(this).find('a').get(0).href;})
	setInterval(changeHome,3000);
}
function changeHome(){
	if (Homefreeze==0 && Homeplay==1){
		var active = $("#accordion").accordion('option','active');
		active++;
		if (active>2) active=0;
		$("#accordion").accordion('option','active',active);
		$("#accordion").activatewithoutfocus(active);
	}
	else if (Homefreeze==1){
		Homefreeze--;
	}
}
/**
 * pour eviter que l'animation auto ne perturbe le focus,
 * on fake les deux methodes focus et blur de jquery avant cet appel
 * et on les retablit juste apres
 */
jQuery.fn.activatewithoutfocus = function(active){
	active = parseInt(active);
	var f = jQuery.fn.focus;
	var b = jQuery.fn.blur;
	jQuery.fn.focus = function(){return this;}
	jQuery.fn.blur = function(){return this;}
	$(this).accordion('activate',active);
	jQuery.fn.focus = f;
	jQuery.fn.blur = b;
}

$(document).ready(function(){
		/* charge l'effet d'accordeon sur la page d'accueil */
		if ($("#accordion").length){
			$("#accordion h3 img").hide().eq(0).show();
			$("#accordion").accordion({
				//event: 'mouseover',
				active: 0,
				changestart: function(event, ui) {
					$(ui.oldHeader).find('img').fadeOut();
					$(ui.newHeader).find('img').fadeIn();
				}
			});
			animateHome();
		}
		$('#accordion2').accordion({
		    event: 'mouseover'
		});


		/* charge l'effet de silder pour la galerie photo */
		$("#slider").css("overflow","hidden");
		$("#slider li").css("overflow","hidden");
		$("#slider").easySlider({
			prevText:'',
			nextText:'',
			orientation:'vertical',
			nbli:'3'
		});

		/* charge l'effet de silder pour la galerie photo */
		$("#sliderh").css("overflow","hidden");
		$("#sliderh li").css("overflow","hidden");
		$("#sliderh").easySlider({
			prevText:'',
			nextText:'',
			orientation:'horizontal',
			nbli:'4'
		});
		
		$("#sliderh li a").click(function() {
			var titre  = $(this).attr("title");
			var tableau=titre.split("|");
			var pathimage = $(this).attr("href");
			var num_diapo_cours = tableau[0];
			var titre_diapo_cours = tableau[2];
			var desc_diapo_cours = tableau[1];
			desc_diapo_cours = desc_diapo_cours.replace(/_/g,'<br/>');
			$("#galeriehbig").attr("src", pathimage).fadeIn('slow');
			$("#galeriehbig").attr({style:"max-width:500px"});
			$("#credit_diapo").replaceWith("<span class='credit' id='credit_diapo'>"+titre_diapo_cours+"</span>");
			$("#titre_diapo").replaceWith("<h3 id='titre_diapo'>"+desc_diapo_cours+"</h3>");
			$("#num_diapo").replaceWith("<span id='num_diapo'>"+num_diapo_cours+"</span>");
			return false;
			});
		
		
		/* Permet d'ouvrir les liens dans un nouveau navigateur */
		$("#liens_utiles a").attr({ target: "_blank" });
		//$("#voir_aussi_article a").attr({ target: "_blank" });

		/* charge l'effet d'affichage du menu niveau 1 et 2 */
		$("#contentfooter_planbg a#contentfooter_planbg_a").click(function() {

			var etat = $("#contentfooter_planbg #contentfooter_plan").attr('class');

			if ( etat == "close")
			{
			/*	$("#contentfooter_planbg #contentfooter_plan").slideDown("fast",function(){*/
					$("#contentfooter_planbg #contentfooter_plan").removeClass("close");
					$("#contentfooter_planbg #contentfooter_plan").addClass("open");
			/*	});*/
				$("#contentfooter_planbg a#contentfooter_planbg_a").addClass("open");
			}
			else
			{
			/*	$("#contentfooter_planbg #contentfooter_plan").slideUp("fast",function(){*/
					$("#contentfooter_planbg #contentfooter_plan").removeClass("open");
					$("#contentfooter_planbg #contentfooter_plan").addClass("close");
			/*	});*/
				$("#contentfooter_planbg a#contentfooter_planbg_a").removeClass("open");
			}

			// On emp�che le navigateur de suivre le lien :
			return false;
		});

	});

