$(document).ready(function(){

  /* ======= Inscription =========================================================================== */
  $("a.inscription").bind("click",function(e){
  	e.preventDefault();
  	window.location="inscription.php";
  });




  /* ======= Récupération de mot de passe ========================================================== */
  $("a.lost").bind("click",function(e){
  	e.preventDefault();
  	var email=$('input.presse-email').val();
  	if(email==''){
  		alert('Veuillez saisir votre adresse mail.');
  	}else{
  		$.ajax({
  			async:false,
  			cache:false,
  			type: "POST",
  			url:'email-resend.php',
  			data: '&mail='+email,
  			success: function(html){
  				switch(html){
  					case "1":
  						alert('Vous allez recevoir un mail contenant le rappel de votre mot de passe.');
  						break;
  					case "2":
  						alert('Cette adresse mail n\'est pas reconnue.');
  						break;
  				}

  			},
  			error: function(){
  				alert('Une erreur s\'est produit à la récupération de votre mot de passe.');
  			}
  		})
  	}
  });

	/* Comportement Rollover avec class="rollover" */
	$("img.rollover").each(function(){
		attachRollOverEvent(this);
	});
	/* Remplacement image actif avec class="actif" */
	$("img.actif").each( function(){
		attachActif(this);
	});


  /* ======= Menu gauche defilement =========================================================================== */

  $("#menu-gauche a.theme[href!='contacts.php']").click(function(event){
  	$(this).next("div").slideToggle("slow");
  	event.preventDefault();
  });


  /* AFFICHAGE DES LIENS DE CONTENU */
  $("#menu-gauche div h2").bind("click",function(){
  	$(this).next("div").slideToggle("slow");
  });
  /* ROLLOVER TITRES CONTENUS */
  $("#menu-gauche div .titreMenu").hover(
	  function(){
	  	//$(this).css("opactity","0.5").css("filter","alpha(opacity=60)");
//	  	$(this).css("backgroundColor","red");
	  	$(this).addClass("rolled");
	  },
	  function(){
	  	$(this).removeClass("rolled");
//	  	$(this).removeAttr("style");
	  }
  );




  //$("a#pub").fancybox({ 'overlayShow': true, 'overlayOpacity': 0.70, 'hideOnContentClick': true, 'frameWidth':250, 'frameHeight':250 });



  /* ======== Changement vignette fiche hotel ========================================================================== */

  /* Comportement changement vignette dans fiche produit */
	$("#fiche-vignettes a").bind("click",function(event){

		var maSource=$(this).attr("href");

		$(this).attr("class","actif");
		$("#fiche-photo").attr("src",maSource);

		event.preventDefault();
	});




	/* pub */

	/*date=new Date;
	date.setMonth(date.getMonth()+1); // expire dans un mois
	if(lire_cookie("deja_venu")==""){ecrire_cookie("deja_venu", "non", date);}
	deja_venu = lire_cookie("deja_venu");



	if(deja_venu=="non"){
		ecrire_cookie("deja_venu","oui",date);
		$("a#pub").click();
	}*/


}); /* fin doc ready */




/* ======== Fonctions ========================================================================== */

/* Comportement Rollover avec class="rollover" */
attachRollOverEvent = function(imageId){
	$(imageId).mouseover( function(){
		var b=$(this).attr("src").match(/[\/|\\]([^\\\/]+)$/);
//		alert( $(this).attr("src").replace(b[1],'') + b[1] );
		$(this).attr("src", $(this).attr("src").replace(b[1],'') + b[1].replace('.','_roll.'));
	} );
	$(imageId).mouseout( function(){
		var b=$(this).attr("src").match(/[\/|\\]([^\\\/]+)$/);
		$(this).attr("src", $(this).attr("src").replace(b[1],'') + b[1].replace('_roll',''));
	} );
}

/* Change image pour les "actif" */
attachActif = function(imageId){
	$(imageId).attr("src", $(imageId).attr("src").replace('.','_roll.'));
}

/* PLUS ICI L'OUVERTURE AUTOMATIQUE DU MENU DE LA PARTIE ACTIVE */
function afficheMenu(){
	$("#menu-gauche div div a.actif").parent("div").css("display","block").parent("div").css("display","block");
}


/* cookies */

function ecrire_cookie(nom, valeur, expires) {
  document.cookie=nom+"="+escape(valeur)+
  ((expires==null) ? "" : ("; expires="+expires.toGMTString()));
}

function lire_cookie(nom) {
        deb = document.cookie.indexOf(nom + "=")
        if (deb >= 0) {
            deb += nom.length + 1
            fin = document.cookie.indexOf(";",deb)
            if (fin < 0) fin = document.cookie.length
            return unescape(document.cookie.substring(deb,fin))
            }
        return ""
        }


