$(document).ready(function(){

    // Remplacement text flash
	Cufon.replace('.meta-b', { fontFamily: 'meta-b' });
	Cufon.replace('.police', { fontFamily: 'meta-r' });
	Cufon.replace('.meta-r', { fontFamily: 'meta-r' });

    /* ======= Defilement =========================================================================== */ 
    $("a.depliant").bind("click",function(e){
      e.preventDefault();
	    var offre=$(this).attr("title");
	  	$("#f_offre").val(offre);
//    	$("#candidature:visible").slideToggle("slow",function(){$("#candidature:hidden").slideToggle("slow");});
    	$("#candidature:hidden").slideToggle("slow");
    	
 		$("#candidature h2.sifr").unsifr();
 		setTimeout (function(){$("#candidature h2.texteOffre").text(offre);}, 200 );
 		setTimeout (function(){$("#candidature h2").sifr();}, 400 );
    		
    	$.scrollTo("#candidature","slow",{onAfter:function(){$.scrollTo({top:'-=10px', left: '+=0px'},"slow");}});
    	$(".messageForm").remove();
    });

  	
  	$("img.rollover").each(function(){
  		$(this).bind("mouseover",aHover);
  		$(this).bind("mouseout",aOut);
  	});
  	
  	// Remplacement image actif avec class="actif"
  	$("img.actif").each( function(){
  		attachActif(this);
  	});	
  	
  	// Remplacment image vignette
  	$ ("div.diapoPti a").bind("click",function(e){
  		e.preventDefault();
  		
  	var monHref = $(this).attr("href");
  	var monRev = $(this).attr("rev");
  	var monId = $(this).attr("rel");
  	
  	// Mise à Zero des rollovers images
  	$("div.diapoPti a").removeClass("actif");
  	$("div.diapoPti img").addClass("rollover");
    //		$("div.diapoPti img").each(function(){
    //		  $(this).attr("src",$(this).attr("src").replace('_roll.','.'));
    //    });
  		
		
		// Affichage de class roll sur l'actif
		$(this)
			.addClass("actif")
			.removeClass("rollover");
      //$(this).find("img").attr("src",$(this).find("img").attr("src").replace('.','_roll.'));
		
		//Affichage de la grande image
    //$("div.diapoGrd img").attr("src",monHref);
		$("div.diapoGrd").load("a_infos.php",{quoi: monRev,id: monId});

		/* PNG Fix */
  $(document).pngFix();
		
  });
  
  $(".liens a").bind("click",function(e){
    e.preventDefault();
  	$("#depli").slideToggle("slow");
  });  
  

   $("a.fancy").fancybox({ 'overlayShow': true, 'overlayOpacity': 0.70, 'hideOnContentClick': true });

   $('#defile1').cycle({
    fx:    'fade',
    speed:  2500,
    timeout:  6000
	});

	/*$('#defile2').cycle({
    fx:    'fade',
    speed:  2500,
    timeout:  6000,
	delay: 2000
	});*/

	 
}); /* fin doc ready */


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


function aHover(){
	if($(this).attr("class")!="actif"){
		$(this).attr(
			"src",
			$(this)
				.attr("src")
				.replace('.','_roll.')
		);
	}
}
function aOut(){
	if($(this).attr("class")!="actif"){
		$(this).attr(
			"src",
			$(this)
				.attr("src")
				.replace('_roll.','.')
		);
	}
}


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