$(window).ready(function(){

  /* cufon */
	Cufon.replace('.delicious', { fontFamily: 'delicious' });

	/* Comportement Rollover avec class="rollover" */
	$("img.rollover").each(function(){
		attachRollOverEvent(this);
	});

	/* Remplacement image actif avec class="actif" */
	$("img.actif").each( function(){
		attachActif(this);
	});

	/* dossiers */
	changement = false;
	$("#links a:not('actif')").click(function(event) {
		if(!changement) {
			changement = true;
			event.preventDefault();
			$('#links a.actif').removeClass('actif');
			$(this).addClass('actif');
			var name = $("#links a").index(this);
			$("#bigs img.encours").removeClass('encours').fadeOut("100",function(){$('#bigs img').eq(name).fadeIn("200");changement = false;});
			$('#bigs img').eq(name).addClass('encours');
		} else {
			return false;
		}
	});

	/* Fancybox Propriétés */
  $("a.fancy").fancybox({ 'overlayShow': true, 'overlayOpacity': 0.70, 'hideOnContentClick': true });


	/* calendrier - sorties */

	$("a#btn_calendrier:not('here')").click(function(event){
		event.preventDefault();

		$("#sorties").removeClass('here').fadeOut("slow",function(){$('#calendrier').fadeIn("slow");});
	});
	$("a#btn_sorties:not('here')").click(function(event){
		event.preventDefault();
		$("#calendrier").removeClass('here').fadeOut("slow",function(){$('#sorties').fadeIn("slow");});
	});
	

	$("a#switchBreve").click(function(event){
		$("#breve p").slideToggle("slow");
	});

	$(function() {

	  var timer = setInterval( showDiv, 3000);

	  $("#links a:not('actif')").click(function(event) {
		clearInterval(timer);
	  });


	  var i = 0;
	  function showDiv() {	
		if(i==4)i=0;
		if(i==3){
			var ideux=0;
		}else{
			var ideux=i+1;
		}
	
		$('#links a.actif').removeClass('actif');
		$('#links a').eq(ideux).addClass('actif');
		$("#bigs img.encours").removeClass('encours').fadeOut("100",function(){$('#bigs img').eq(ideux).fadeIn("200");});
		$('#bigs img').eq(ideux).addClass('encours');

		i++;
	  }

	});




  /* PNG Fix */
  $(document).pngFix();


}); /* fin doc ready */


/* ======== Fonctions ========================================================================== */




/* Comportement Rollover avec class="rollover" */
attachRollOverEvent = function(imageId){

	var extension = getExtension($(imageId).attr("src"));
	
	$(imageId).mouseover( function(){
		//$(this).attr("src", $(this).attr("src").replace('.gif','_roll.gif'))} );
		$(this).attr("src", $(this).attr("src").replace(extension,'_roll'+extension))} );
		
	$(imageId).mouseout( function(){ $(this).attr("src", $(this).attr("src").replace('_roll','')) } );
}

/* Change image pour les "actif" */
attachActif = function(imageId){
	var extension = getExtension($(imageId).attr("src"));
	$(imageId).attr("src", $(imageId).attr("src").replace(extension,'_roll'+extension));
}

getExtension = function(acheck){
     nbchar = acheck.length;// on compte le nombre de caractere que compose ce chemin
     extension = acheck.substring(nbchar-4,nbchar); // on récupere les 4 derniers caracteres
     extension=extension.toLowerCase(); //on uniforme les caracteres en minuscules au cas ou cela aurait été écris en majuscule...
     return extension; // on renvoi l'extension vers la fonction appelante
}

