$(function() {
		   
	$("#btnLog").click(function () {
		
		var p = $("#log").val();
		var ps = $("#pass").val();
		var resolution = screen.width+"x"+screen.height;
		var navigateur = navigator.userAgent;
			$.post("log_jquery.php", { password: ps,login: p, resolution:resolution, navigateur:navigateur },
						function(data){
						switch (data) {
							 case 'success':
							 $(location).attr('href','index.php');
							 break;
							 case 'fail':
							  $("#mininav_erreur").html("Identifiants incorrects");
							  $("#mininav_erreur").hide().fadeIn().delay(50).fadeOut().fadeIn();
							 break;
							 case 'vide':
							 $("#mininav_erreur").html("Veuillez remplir tous les champs");
							 $("#mininav_erreur").hide().fadeIn().delay(50).fadeOut().fadeIn();
							 break;
							 case 'inactif':
							 $("#mininav_erreur").html("Votre compte est d&eacute;sactiv&eacute;");
							 $("#mininav_erreur").hide().fadeIn().delay(50).fadeOut().fadeIn();
							 break;
							 default: 
							 break;
						}
							
						});	
	});
	
	$("#btnLogBis").click(function () {
		
		var p = $("#logBis").val();
		var ps = $("#passBis").val();
		var resolution = screen.width+"x"+screen.height;
		var navigateur = navigator.userAgent;
			$.post("log_jquery.php", { password: ps,login: p, resolution:resolution, navigateur:navigateur },
						function(data){
						switch (data) {
							 case 'success':
							 $(location).attr('href','index.php');
							 break;
							 case 'fail':
							  $("#connexion_erreur").html("Identifiants incorrects");
							  $("#connexion_erreur").hide().fadeIn().delay(50).fadeOut().fadeIn();
							 break;
							 case 'vide':
							 $("#connexion_erreur").html("Veuillez remplir tous les champs");
							 $("#connexion_erreur").hide().fadeIn().delay(50).fadeOut().fadeIn();
							 break;
							 case 'inactif':
							 $("#connexion_erreur").html("Votre compte est désactivé");
							 $("#connexion_erreur").hide().fadeIn().delay(50).fadeOut().fadeIn();
							 break;
							 
							 default: 
							 break;
						}
							
						});	
	});
	
	$("#cadre_actualite_milieu a").click(function () {
		
	idNews = ($(this).attr("rel"));
	$.post("actu_jquery.php", { idNews:idNews},
		   function(data){
			 $(".banniere3D_milieu").html(data.titre);
			 $(".banniere3D_milieu").hide().fadeIn();
			 $("#contenu_actu").html(data.contenu).hide().fadeIn();
		   },"json");
		
	});
	
	$("#menu_produit a").click(function () {
		
		$("#menu_produit div").removeAttr("id")

		var idR;
		if(this.id == 'phare'){
			idR = '';
		} else {
			idR = ($(this).attr("rel"));
		}
		
			$.get("produits_jquery.php", { r: idR, ajaxOn:1},
			function(data){
				$("#contenu_produit").html(data).hide().fadeIn();
			});	
		if(this.id == 'phare'){
			$("#menu_produit a#"+this.id).parent().attr('id','active');
		} else {
			$("#menu_produit a[rel="+($(this).attr("rel"))+"]").parent().attr('id','active');
		}	
		
	});
	
	$("#menu_editeur a").click(function () {
		
		$("#menu_editeur div").removeAttr("id")

		
			idR = ($(this).attr("rel"));
		
			$.get("editeurs_jquery.php", { e: idR, ajaxOn:1},
			function(data){
				$("#contenu_editeur").html(data).hide().fadeIn();
			});	
		if(this.id == 'phare'){
			$("#menu_editeur a#"+this.id).parent().attr('id','active');
		} else {
			$("#menu_editeur a[rel="+($(this).attr("rel"))+"]").parent().attr('id','active');
		}	
		
	});
	
	//Chargement ajax partie espace client du front
	$("#contenu_client_gestion span a").click(function () {

		mesArgs = ($(this).attr("rel"));
		if (isNaN(mesArgs)){
			$.get("espace_client_gestion_jquery.php", { act: 'ajouter', ajaxOn:1},
			function(data){
				$("#contenu_client_gestion").html(data).hide().fadeIn();
			});	
		}
		else {
			$.get("espace_client_gestion_jquery.php", { act: 'modifier', id: mesArgs, ajaxOn:1},
			function(data){
				$("#contenu_client_gestion").html(data).hide().fadeIn();
			});	
		}
		
	});
	
	
    // wrap as a jQuery plugin and pass jQuery in to our anoymous function
    (function ($) {
        $.fn.cross = function (options) {
            return this.each(function (i) { 
                // cache the copy of jQuery(this) - the start image
                var $$ = $(this);
                
                // get the target from the backgroundImage + regexp
                var target = $$.css('backgroundImage').replace(/^url|[\(\)'"]/g, '');

                // nice long chain: wrap img element in span
                $$.wrap('<span style="position: relative;"></span>')
                    // change selector to parent - i.e. newly created span
                    .parent()
                    // prepend a new image inside the span
                    .prepend('<img>')
                    // change the selector to the newly created image
                    .find(':first-child')
                    // set the image to the target
                    .attr('src', target);

                // the CSS styling of the start image needs to be handled
                // differently for different browsers
                if ($.browser.msie || $.browser.mozilla) {
                    $$.css({
                        'position' : 'absolute', 
                        'left' : 0,
                        'background' : '',
                        'top' : this.offsetTop
                    });
                } else if ($.browser.opera && $.browser.version < 9.5) {
                    // Browser sniffing is bad - however opera < 9.5 has a render bug 
                    // so this is required to get around it we can't apply the 'top' : 0 
                    // separately because Mozilla strips the style set originally somehow...                    
                    $$.css({
                        'position' : 'absolute', 
                        'left' : 0,
                        'background' : '',
                        'top' : "0"
                    });
                } else { // Safari
                    $$.css({
                        'position' : 'absolute', 
                        'left' : 0,
                        'background' : ''
                    });
                }

                // similar effect as single image technique, except using .animate 
                // which will handle the fading up from the right opacity for us
                $$.hover(function () {
                    $$.stop().animate({
                        opacity: 0
                    }, 250);
                }, function () {
                    $$.stop().animate({
                        opacity: 1
                    }, 250);
                });
            });
        };
        
    })(jQuery);
    
});
