var scripts2 = {
    init: function () {
        // AJOUT du 17-06-2008  - YANN
        // Code pour centrer la home verticalement
        /*
        if($('#conteneurWelcome')) {
            var hauteur_doc = $(window).height();
            var hauteur_contenu = $('#conteneurWelcome').height();
            var marge_sup = ((hauteur_doc / 2) - (hauteur_contenu / 2));
            var marge_sup = marge_sup - 20;
            if(marge_sup < 0) { marge_sup = 0; }
            $('#conteneurWelcome').css('margin-top', marge_sup+'px');
        }
        */
        if($('#tagWelcome')){
            var axel = Math.random()+"";
            var a = axel * 10000000000000;
            $('#tagWelcome').html('<iframe SRC="http://fls.doubleclick.net/activityi;src=1708952;type=etamlp01;cat=lp01;ord='+ a + '?" width="1" height="1" frameborder="0"></iframe>');
        }
                
        if($(".faq h3 a")) {
            scripts2.initFaq();
        }
        
        if(jQuery("#contactFaq")) { 
            scripts2.initContactFaq();
        }
        
        // Vide le champ recherche qd on clique dessus
        if($("#champRecherche")){
            $("#champRecherche").click(function(){
                if($(this).val() == "Je recherche un produit") $(this).val("");
            });
            $("#champRecherche").blur(function(){
                if($(this).val() == "") $(this).val("Je recherche un produit");
            });
        }
        if(jQuery('.popGarantie')){
            jQuery(".popGarantie").each(function(){
                jQuery(this).click(function(evt){
                    scripts2.ouvrirGarantie(this.href);
                    evt.preventDefault();
                });
            });
        }
		if(jQuery('.sauvegardeHelp')){
            jQuery(".sauvegardeHelp").each(function(){
                jQuery(this).click(function(evt){
                    scripts2.ouvrirSauvegardeHelp(this.href);
                    evt.preventDefault();
                });
            });
        }
        if(jQuery('#fermerPopup a')){
            jQuery('#fermerPopup a').click(function(evt){
                window.close();
            });
        }
        
        if(jQuery('#closePopup').length > 0){
            jQuery('#closePopup').click(function(evt){
                window.close();
            });
        }
        
        // 7-11-2008 : Redesign noel : On retire le flot noel si la tailel du nav < 1024
    /*    jQuery(window).resize(
            function(){
                scripts2.gestionFlotDroit();
            }
        );
        scripts2.gestionFlotDroit();*/
    },
    /*gestionFlotDroit: function(){
        var largeur = null;
        if (document.body) largeur = (document.body.clientWidth);
        else largeur = (window.innerWidth);
        
        if(largeur < 1024) {
            jQuery("#noeud_droite").hide();
        }else jQuery("#noeud_droite").show();
    },*/
    initFaq: function(){
        // Pour toutes les rubriques, on écoute le clic
        $(".faq h3 a").each(function(){
            $(this).click(function(){
                scripts2.clicRubriqueFaq(this);
                return false;
            });
        });
        
        // Pour toutes les questions, on écoute le clic
        $(".faq .questions dt a").each(function(){
            $(this).click(function(){
                scripts2.clicQuestion(this);
                return false;
            });
        });
        
        // On ouvre la première
        scripts2.clicRubriqueFaq($(".faq h3 a").eq(0)[0]);
    },
    clicRubriqueFaq: function(rub){

        if(!rub) return;
        
        var aId = rub.id.split("_");
        id = aId[aId.length-1];

        if ($(rub).hasClass("open")) {
            scripts2.fermerRubriques();
            scripts2.fermerQuestions();
        } else if ($(rub).hasClass("close")) {
            scripts2.fermerRubriques();
            scripts2.fermerQuestions();
            $(rub).removeClass("close").addClass("open");
            $("#"+id).css("display", "block");
            $("#"+id+" dt.premier a").addClass("open");
        } else {
        	scripts2.fermerRubriques();
            scripts2.fermerQuestions();
            $(rub).addClass("open");
            $("#"+id).css("display", "block");	
            $("#"+id+" dt.premier a").addClass("open");
        }
        
        // On ouvre la rubrique
        //var src = $("img", rub).attr("src");
        //var pos = src.lastIndexOf(".");
        //var nvxSrc = src.substr(0, pos-4)+"open"+src.substr(pos);
        //$("img", rub).attr("src", nvxSrc);
        // On ouvre la première qst
        $("dd", $("#"+id)).eq(0).css("display", "block");
    },
    clicQuestion:function(qst){
        // On ferme toutes les questions
        var aId = qst.id.split("_");
        id = aId[aId.length-1];

        if ($(qst).hasClass("open")) {
            scripts2.fermerQuestions();
        } else {
            scripts2.fermerQuestions();
            $(qst).removeClass("close").addClass("open");
            $("#rep_"+id).css("display", "block");
        }
    },
    
    fermerRubriques: function(){    
        
        $(".faq h3 a").removeClass("open").addClass("close");
        
        // On remet les images d'origine en remplaçant les on.gif par off.gif dans toutes les images
        
        /*
        $(".faq h3 img").each(function(obj){
            var src = $(this).attr("src");
            var pos = src.lastIndexOf(".");
            if(src.substr(pos-4, 4) == "open"){
                var nvxSrc = src.substr(0, pos-4)+"close"+src.substr(pos);
                 $(this).attr("src", nvxSrc);
            }
        });
        */
        
        $(".questions").css("display", "none");
        
        $(".faq .questions").each(function(obj){
            $(obj).css("display", "none");
        });
    },
    fermerQuestions: function(){
        $(".faq .questions dt a").removeClass("open").addClass("close");
        $("#contenu2.faq dd").each(function(){
            $(this).css("display", "none");
        });
    },
    ouvrirGarantie: function(lien){
        var gauche = (window.screen.width - 630) / 2;
        var haut = (window.screen.height - 800) / 2;
        var popup = window.open(lien, "Garanties", "width=630, height=800, left="+gauche+", top="+haut+", scrollbars=yes");
        if(!popup) alert("Votre navigateur bloque les fenêtres popup");
        else popup.focus();
    },
	ouvrirSauvegardeHelp: function(lien){
        var gauche = (window.screen.width - 380) / 2;
        var haut = (window.screen.height - 404) / 2;
        var popup = window.open(lien, "_blank", "width=380, height=404, left="+gauche+", top="+haut+", scrollbars=no");
        if(!popup) alert("Votre navigateur bloque les fenêtres popup");
        else popup.focus();
    },
    /* FAQ CONTACT */
    initContactFaq: function(){
        // Pour toutes les questions, on écoute le clic
        jQuery("dl#contactFaq dt a").each(function(){
            jQuery(this).click(function(){
                scripts2.clicContactQuestion(this);
                return false;
            });
        });
    },
    clicContactQuestion:function(qst){
        // On ferme toutes les questions
        var aId = qst.id.split("_");
        id = aId[aId.length-1];
        if (jQuery(qst).hasClass("open")) {
            scripts2.fermerContactQuestions();
        } else {
            scripts2.fermerContactQuestions();
            jQuery(qst).removeClass("close").addClass("open");
            jQuery("#rep_"+id).css("display", "block");
        }
    },
    fermerContactQuestions: function(){
        jQuery("dl#contactFaq dt a").removeClass("open").addClass("close");
        jQuery("dl#contactFaq dd").each(function(){
            jQuery(this).css("display", "none");
        });
    }    
}
$(document).ready( function () {
    scripts2.init();
});


