$.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)   this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback))  callback();  
    }); 
}; 
 
$.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback))  callback();  
    }); 
}; 
 
$.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 


$(function() {

		

    $(".toolprod").live("mouseover", function() {	$(this).find('.details').fadeIn(200);	});
    $(".toolprod").live("mouseout", function() {	$(this).find('.details').fadeOut(200);	});

    $("#ppanier").live("mouseover", function() {
			 $("#ppanier").stopTime("cartend");
			 $(this).oneTime(500, "carteon", function() {
				$(this).find('span.title').fadeOut(10);
				$(this).find('small.dts').fadeIn(10);
			  });
	});
	 $("#ppanier").live("mouseout", function() {
			 $("#ppanier").stopTime("carteon");
			 $(this).oneTime(200, "cartend", function() {
				$(this).find('small.dts').fadeOut(10);
				$(this).find('span.title').fadeIn(10);
			  });
	});
    $(".formule").live("mouseover", function() {
			 var monId=$(this).attr("id");
			 $(".formule").stopTime("bigen"+monId);
			 $(this).oneTime(500, "bigon"+monId, function() {
				$(this).find('p.details').fadeIn(500);
				$(this).find('img.illu').animate({width:'150px'},{queue:false,duration:500});
			  });
	});
	 $(".formule").live("mouseout", function() {
			 var monId=$(this).attr("id");
			 $(".formule").stopTime("bigon"+monId);
			 $(this).oneTime(1, "bigen"+monId, function() {
				$(this).find('p.details').fadeOut(100);
				$(this).find('img.illu').animate({width:'40px'},{queue:false,duration:500});
			  });
	});



});


/* connex ****************************************************************************************************************************** */

			function conex(login,mdp) { 
				printLoadingMessage('<p><img src=./img/loading.gif> &nbsp; &nbsp; <b>Chargement en cours...</b><p>');
				 $.ajax({
					type: "POST", url: "ajax.php",
					data:({ 'case' : 'conex', login : login, mdp : mdp }),
					success: function(msg){
						printLoadingMessage(msg);
						loadajax('load.php?load=validpanier','page','no');
						loadajax('load.php?load=connexion','htmlconnexion','no');
					}
				 });
			}

			function conexb(login,mdp) { 
				printLoadingMessage('<p><img src=./img/loading.gif> &nbsp; &nbsp; <b>Chargement en cours...</b><p>');
				 $.ajax({
					type: "POST", url: "ajax.php",
					data:({ 'case' : 'conex', login : login, mdp : mdp }),
					success: function(msg){
						printLoadingMessage(msg);
						loadajax('load.php?load=connexion','htmlconnexion','no');
					}
				 });
			}

/* inscription/mod/mdp ****************************************************************************************************************************** */

			function reg(nom,prenom,mail,mailb,email) { 
				printLoadingMessage('<p><img src=./img/loading.gif> &nbsp; &nbsp; <b>Enregistrement en cours...</b><p>');
				if (email == '') {
					if (mail != mailb) { printLoadingMessage('<p><img src=./img/no.png> &nbsp; &nbsp; <b>Vos deux adresses mail ne correspondent pas...</b><p>'); }
					else {
						if (nom == '' ||  prenom == '' ||  mail == '') { printLoadingMessage('<p><img src=./img/no.png> &nbsp; &nbsp; <b>Veuillez remplir tous les champs</b> pour valider votre inscription.<p>'); }
						else {
							 $.ajax({
								type: "POST", url: "ajax.php",
								data:({ 'case' : 'reg', nom : nom, prenom : prenom, mail : mail }),
								success: function(msg){ printLoadingMessage(msg); }
							 });
						}
					}
				}
			}

			function mod(nom,prenom,email,adresse,adresse_bis,adresse_info,cp,ville,tel,tel_bis)  { 
				printLoadingMessage('<p><img src=./img/loading.gif> &nbsp; &nbsp; <b>Chargement en cours...</b><p>');
				if (nom == '' ||  prenom == '' ||  email == '' ||  adresse == '' ||  cp == '' ||  ville == '' ||  tel == '') { printLoadingMessage('<p><img src=./img/no.png> &nbsp; &nbsp; <b>Veuillez remplir tous les champs obligatoires</b> marqués d\'un astérique.<p>'); }
				else {
					 $.ajax({
						type: "POST", url: "ajax.php",
						data:({ 'case' : 'mod',
								nom : nom, prenom : prenom, email : email, 
								adresse : adresse, adresse_bis : adresse_bis, adresse_info : adresse_info, 
								cp : cp, ville : ville, 
								tel : tel, tel_bis : tel_bis }),
						success: function(msg){ printLoadingMessage(msg); }
					 });
				}
			}

			function changemdp(old,mdp,mdp_bis)  { 
				printLoadingMessage('<p><img src=./img/loading.gif> &nbsp; &nbsp; <b>Chargement en cours...</b><p>');
				if (old == '' ||  mdp == '' ||  mdp_bis == '') { printLoadingMessage('<p><img src=./img/no.png> &nbsp; &nbsp; <b>Veuillez remplir tous les champs</b>.<p>'); }
				else if (mdp !=  mdp_bis) { printLoadingMessage('<p><img src=./img/no.png> &nbsp; &nbsp; <b>Vos deux nouveaux mots de passe ne correspondent pas</b>.<p>'); }
				else {
					 $.ajax({
						type: "POST", url: "ajax.php",
						data:({ 'case' : 'mdp', old : old, mdp : mdp, mdp_bis : mdp_bis }),
						success: function(msg){ printLoadingMessage(msg); }
					 });
				}
			}

			function sendmdp(email)  { 
				printLoadingMessage('<p><img src=./img/loading.gif> &nbsp; &nbsp; <b>Chargement en cours...</b><p>');
				 $.ajax({
					type: "POST", url: "ajax.php",
					data:({ 'case' : 'sendmdp', email : email }),
					success: function(msg){ printLoadingMessage(msg); }
				 });
			}

/* Panier ****************************************************************************************************************************** */

			function cart(action,type,id) { 
				printLoadingMessage('<p><img src=./img/loading.gif> &nbsp; &nbsp; <b>Chargement en cours...</b><p>');
				$.ajax({
					type: "POST", url: "ajax.php",
					data:({ 'case' : action, type : type, id : id }),
					success: function(msg){
						printLoadingMessage(msg);
						loadajax('load.php?load=panier','htmlpanier','no');
					}
				 });
			}

			function savepanier() { 
				printLoadingMessage('<p><img src=./img/loading.gif> &nbsp; &nbsp; <b>Chargement en cours...</b><p>');
				$.ajax({
					type: "POST", url: "ajax.php",
					data:({ 'case' : 'savepanier' }),
					success: function(msg){
						printLoadingMessage(msg);
						loadajax('load.php?load=panier','htmlpanier','no');
						loadajax('load.php?load=validpanier','page','no');
					}
				 });
			}

			function addpanier(id) { 
				printLoadingMessage('<p><img src=./img/loading.gif> &nbsp; &nbsp; <b>Ajout en cours...</b><p>');
				$.ajax({
					type: "POST", url: "ajax.php",
					data:({ 'case' : 'addpanier', id : id }),
					success: function(msg){
						printLoadingMessage(msg);
						loadajax('load.php?load=panier','htmlpanier','no');
					}
				 });
			}

			function delcomm(id) { 
				printLoadingMessage('<p><img src=./img/loading.gif> &nbsp; &nbsp; <b>Suppression en cours...</b><p>');
				$.ajax({
					type: "POST", url: "ajax.php",
					data:({ 'case' : 'delcomm', id : id }),
					success: function(msg){
						printLoadingMessage(msg);
						loadajax('load.php?load=validpanier','page','no');
					}
				 });
			}

/* Affichage réponses ****************************************************************************************************************** */

			function printLoadingMessage(loadingMessageText) { 
				$('#loadingMessage').stopTime('loadgmss');
				$('#loadingMessage').stopTime('loamss');
						
				$('#loadingMessage').fadeIn(500);
				setTimeout(function() { $('#loadingMessage').html(loadingMessageText); },500);
				
				$('#loadingMessage').oneTime(4000, 'loadgmss', function() { 
					$('#loadingMessage').fadeOut(1500);
					$('#loadingMessage').oneTime(1500, 'loamss', function() { $('#loadingMessage').html(''); }); 
				}); 
			}



			function closeajax(id) {
				$('#'+id).fadeOut(500);
				$('#'+id).html('');
				$('#bande').fadeOut(1000);
				$('#overlay').fadeOut(500);
				$(this).oneTime(300, "linkindex", function() { $('ul.link').css({'z-index':'101'}); });	
			}

			function loadajax(url,id,bg) {
				if (id == 'page') { $('#linkaccueil').removeClass("hover"); $('#linkcarte').removeClass("hover"); }
				if (bg != 'no') $('#bande').fadeIn(100);
				if (bg != 'no') $('#overlay').fadeIn(500);
				if (bg != 'no') $('ul.link').css({'z-index':'90'});		
				 $.ajax({
					type: "GET", url: url,
					success: function(msg){	     $('#'+id).fadeOut('200');
							 setTimeout(function() { $('#'+id).html(msg); },330); 
							 setTimeout(function() { $('#'+id).fadeIn('1500'); },700); 
					}
				 });
				 
			}


/* Autres... *************************************************************************************************************************** */

			var toggleDiv = function(name, id) {
				for (x=0; x<=99; x++) { 
					if (x != id && document.getElementById(name+x)) { 
						$('#'+name+'_'+x).removeClass("ok");
						$('#'+name+x).fadeOut(400);
					}
					if (document.getElementById(name+'__'+x)) $('#'+name+'__'+x).fadeOut(400);
				}
				$('#'+name+'_'+id).addClass("ok");

				$('#'+name+id).oneTime(500, "big", function() {
					$('#'+name+id).fadeIn(500);
					if (document.getElementById(name+'__'+id)) $('#'+name+'__'+id).fadeIn(400);

				});
			}
			function changemenu(lien,no) {
				$('#'+lien).addClass("hover");
				$('#'+no).removeClass("hover");
			}



/* ????????? *************************************************************************************************************************** */



