/************** CHARGEMENT PAGE *****************************/
jQuery(document).ready(function(){
    initMenu();
    initRolloverCompte();
    initRolloverPanier();
    btnHover();
    initBlocProduit();

    // champ newsletter
    loadAddNewsletter('#newsletter');

    // formulaire de rappel telephone
    loadRappelTelephone(".form-rappel-menu");

    jQuery("input.altern-text").each(function(i){
        alterneText("#"+this.id, jQuery(this).attr('value'));
    });
    
    if(jQuery("#form-rappel").length > 0){
        loadRappelTelephone("#form-rappel");
    }

    jQuery("#malheur-josiane").click(function(){
        popupJosiane();
    });
});
/************** CHARGEMENT PAGE *****************************/
function popupJosiane(){
    jQuery("body").popup({
        popup:{
            css:{
                'width':'598px', 
                'height':'435px'
            },
            removeOnClick:{
                0:'#btn-close-popup'
            }
        },
        ajax:'/js/ajax/josiane.php'
    });
}
function popupLivre_blanc(){
    jQuery("body").popup({
        popup:{
            css:{
                'width':'598px', 
                'height':'350px'
            },
            removeOnClick:{
                0:'#btn-close-popup',
                1:'#btn-retour'
            }
        },
        ajax:'/js/ajax/livre_blanc.php'
    });
}

function popupLivre_blanc_submit(idForm){
    var data = jQuery("#contact_livre_blanc").serialize();
jQuery.ajax({
            type: "POST",
            url: '/js/ajax/livre_blanc.php',
            data : data,
            success: function(html){
                jQuery("#popup-livre-blanc").html(html);
            }
        });
return false;


}


function btnHover(){
    var listeClass = new Array('.btn-voir-produit', '.btn-mini-voir-produit', '.btn-process', '.btn-bloc-compte');

    jQuery.each(listeClass, function(index, value) {
        jQuery(value).hover(
            function(){
                jQuery(this).addClass('hover');
            },
            function(){
                jQuery(this).removeClass('hover');
            }
            );

        jQuery(value).click(function(){
            if(jQuery(this).attr('rel')){
                location.href = jQuery(this).attr('rel');
            }
        });
    });
}

function initBlocProduit(){
    jQuery(".visu-listing-produit").click(function(){
        if(jQuery(this).attr('rel')){
            location.href = jQuery(this).attr('rel');
        }
    });
}

function loadRappelTelephone(node){
    
    jQuery(node).submit(function(){
        jQuery("body").popup({
            popup:{
                removeOnClick:{
                    0:'#btn-close-popup',
                    1:'#btn-retour'
                }
            },
            ajax:'/js/ajax/rappel_telephone.php',
            data:jQuery(node).serialize()
        });
        return false;
    });
}

function initRolloverCompte(){
    var nodeCompte = 'infos-compte';
    jQuery("#btn-mon-compte").mouseenter(function(event){
        var pos = jQuery(this).position();
        jQuery(this).css({
            'cursor':'pointer',
            'z-index':5001
        });
        jQuery.ajax({
            type: "POST",
            url: '/js/ajax/infos_compte.php',
            success: function(html){
                // création de la div
                if (!jQuery("#"+nodeCompte).attr('id')) {
                    jQuery("<div></div>").attr("id", nodeCompte).css({
                        'left': (pos.left-100)+'px',
                        'position': 'absolute',
                        'top': '46px',
                        'z-index': '3000',
                        'display':'none'
                    }).html(html).appendTo("#wrapper");
                    jQuery("#"+nodeCompte).css('display', 'block');

                    jQuery("#"+nodeCompte).mouseenter(function(){
                        jQuery(this).css('display', 'block');
                        jQuery("#btn-mon-compte").css({
                            'cursor':'pointer',
                            'z-index':5001
                        });
                    });

                    jQuery("#btn-mon-compte").mouseleave(function(){
                        jQuery("#"+nodeCompte).css('display', 'none');
                        jQuery(this).css({
                            'cursor':'default',
                            'z-index':1000
                        });
                    });

                    jQuery("#"+nodeCompte).mouseleave(function(){
                        jQuery(this).css('display', 'none');
                        jQuery("#btn-mon-compte").css({
                            'cursor':'default',
                            'z-index':1000
                        });
                    });
                }else{
                    jQuery("#"+nodeCompte).html(html);
                    jQuery("#"+nodeCompte).css('display', 'block');
                }
            }
        });
    });
}
function initRolloverPanier(){
    var nodeCompte = 'contenu-panier-bulle';
    jQuery("#btn-mon-panier").mouseenter(function(event){
        var pos = jQuery(this).position();
        jQuery(this).css({
            'cursor':'pointer',
            'z-index':5001
        });
        jQuery.ajax({
            type: "POST",
            url: '/js/ajax/show_panier.php',
            success: function(html){
                // création de la div
                if (!jQuery("#"+nodeCompte).attr('id')) {
                    jQuery("<div></div>").attr("id", nodeCompte).css({
                        'left': (pos.left-180)+'px',
                        'position': 'absolute',
                        'top': '46px',
                        'z-index': '3000',
                        'display':'none'
                    }).html(html).appendTo("#wrapper");
                    jQuery("#"+nodeCompte).css('display', 'block');

                    jQuery("#"+nodeCompte).mouseenter(function(){
                        jQuery(this).css('display', 'block');
                        jQuery("#btn-mon-panier").css({
                            'cursor':'pointer',
                            'z-index':5001
                        });
                    });

                    jQuery("#btn-mon-panier").mouseleave(function(){
                        jQuery("#"+nodeCompte).css('display', 'none');
                        jQuery(this).css({
                            'cursor':'default',
                            'z-index':1000
                        });
                    });

                    jQuery("#"+nodeCompte).mouseleave(function(){
                        jQuery(this).css('display', 'none');
                        jQuery("#btn-mon-panier").css({
                            'cursor':'default',
                            'z-index':1000
                        });
                    });
                }else{
                    jQuery("#"+nodeCompte).html(html);
                    jQuery("#"+nodeCompte).css('display', 'block');
                }
            }
        });
    });
}

//Affichage du sous menu au rollover
function initMenu(){

    jQuery("#menu a.item-menu-center").each(function(i){
        
        jQuery(this).click(function(event){
            if(jQuery("#sous-" + this.id).css('visibility') == 'hidden'){
                jQuery(".wrapper-sous-menu").css('visibility', 'hidden');
                jQuery("#sous-" + this.id).css('visibility', 'visible');
                jQuery(this).parents(".item-menu").addClass('hover');
            }else{
                jQuery("#sous-" + this.id).css('visibility', 'hidden');
                jQuery(this).parents(".item-menu").removeClass('hover');
            }
        });
        
        jQuery(this).mouseenter(function(event){
            jQuery(this).parents(".item-menu").addClass('hover');
        });

        jQuery(this).mouseleave(function(event){
            jQuery("#sous-" + this.id).css('visibility', 'hidden');
            jQuery(this).parents(".item-menu").removeClass('hover');
        });
    });

    jQuery(".wrapper-sous-menu").each(function(i){
        jQuery(this).mouseenter(function(event){
            jQuery("#" + jQuery(this).attr("id").substr(5)).parents(".item-menu").addClass('hover');
            jQuery(this).css('visibility', 'visible');
        });

        jQuery(this).mouseleave(function(event){
            jQuery("#" + jQuery(this).attr("id").substr(5)).parents(".item-menu").removeClass('hover');
            jQuery(this).css('visibility', 'hidden');
        });
    });
    
    jQuery("#lien-menu-home").hover(function(){
        jQuery(this).find('img').attr('src', '/styles/images/menu/maison-blanche.png');
    }, function(){
        jQuery(this).find('img').attr('src', '/styles/images/menu/maison-rouge.png');
    });

// jQuery(".liste-categorie .colonne-ss-categ:last-child").addClass("last");
}

function loadChangeImage(){
    jQuery("#liste-mini-visuel .mini-visuel").each(function(i){
        jQuery(this).css('cursor', 'pointer').click(function(){
            var idVisu = jQuery(this).attr('id');
            jQuery("#grand-visuel img:first").attr('src', jQuery("#grand-"+idVisu+" img").attr('src'));
            // jQuery("#grand-visuel img:first").parents('a.jqzoom').attr('href', jQuery("#popup-"+idVisu+" img").attr('src'));     // pour le zoom produit
            jQuery("#loupe-visuel").unbind('click');
            jQuery("#loupe-visuel").click(function(){
                var html = '';
                html += '<div id="image-zoom-popup">'+jQuery("#popup-"+idVisu).html()+'</div>';
                html += buildNavPopup();
                jQuery("body").popup({
                    popup:{
                        css:{
                            'width':'700px',
                            'height':'580px'
                        },
                        removeOnClick:{
                            0:'#image-zoom-popup'
                        }
                    },
                    content: html,
                    callback:'changeImageZoom()'
                });
            });
        });
    });

    if(jQuery("#liste-mini-visuel .mini-visuel").length > 0){
        jQuery("#loupe-visuel").css('cursor', 'pointer').click(function(){
            var html = '';
            html += '<div id="image-zoom-popup">'+jQuery("#popup-"+jQuery("#liste-mini-visuel .mini-visuel:first").attr('id')).html()+'</div>';
            html += buildNavPopup();
            jQuery("body").popup({
                popup:{
                    removeOnClick:{
                        0:'#image-zoom-popup'
                    },
                    css:{
                        'width':'700px',
                        'height':'580px'
                    }
                },
                content: html,
                callback:'changeImageZoom()'
            });
        });
    }
}

function buildNavPopup(){
    var hBox
    if(jQuery(".mini-visuel").length > 7){
        hBox = '152px';
    }else{
        hBox = '76px';
    }
    var html = '<div class="nav-popup-zoom" style="height:'+hBox+'">';
    jQuery(".mini-visuel").each(function(){
        html += '<div class="zoom-mini-visuel" id="zoom-'+this.id+'">'+jQuery(this).html()+'</div>';
    });
    html += '<div class="clear"></div></div>';
    return html;
}

function changeImageZoom(){
    if(jQuery(".zoom-mini-visuel").length > 7){
        jQuery("#popup").css('height','656px');
    }
    jQuery(".zoom-mini-visuel").css('cursor','pointer').click(function(){
        var infos = this.id.split('-');
        jQuery("#image-zoom-popup").html(jQuery("#popup-visu-"+infos[2]).html());
        jQuery('.cloud-zoom').CloudZoom();
    });
    jQuery('.cloud-zoom').CloudZoom();
}

function loadPopupAttr(){
    jQuery(".liste-opts .img-attr").each(function(i){
        if(jQuery("#popup-"+this.id).attr('id')){
            jQuery(this).css('cursor', 'pointer').click(function(){
                jQuery("body").popup({
                    popup:{
                        css:{
                            'width':'700px',
                            'height':'500px',
                            'border':'1px solid #C6C6C6'
                        },
                        removeOnClick:{
                            0:'#popup'
                        }
                    },
                    content: jQuery("#popup-"+this.id).html()
                });
            });
        }
    });
}

function loadAddNewsletter(node){

    jQuery(node).submit(function(){
        jQuery("body").popup({
            popup:{
                removeOnClick:{
                    0:'#btn-close-popup',
                    1:'#close'
                }
            },
            ajax:'/js/ajax/addNewsletter.php',
            data:jQuery(node).serialize()
        });
        return false;
    });
}

function loadAjoutPanier(){
    jQuery("#btn-plus-panier").css('cursor', 'pointer').click(function(){
        jQuery("#qte").attr('value', parseInt(jQuery("#qte").attr('value'))+1);
    });

    jQuery("#btn-moins-panier").css('cursor', 'pointer').click(function(){
        if ((parseInt(jQuery("#qte").attr('value'))-1) > 0) {
            jQuery("#qte").attr('value', parseInt(jQuery("#qte").attr('value')) - 1);
        }
    });

    jQuery("#btn-ajout-fprod").css('cursor', 'pointer').click(function(){
        jQuery("body").popup({
            popup:{
                removeOnClick:{
                    0:'#btn-close-popup',
                    1:'#btn-continue-achat',
                    2:'#btn-retour-produit'
                }
            },
            ajax:'/js/ajax/update-panier.php',
            data:jQuery("#form-ajout-panier-fprod").serialize(),
            callback:'updateProdPanier()'
        });
    });

    jQuery("#btn-ajout-fprod").hover(
        function(){
            jQuery(this).attr('src', '/styles/images/produit/btn-ajout-panier-hover.png');
        },
        function(){
            jQuery(this).attr('src', '/styles/images/produit/btn-ajout-panier.png');
        }
        );
}

function addFastPanier(idForm){
    jQuery("body").popup({
        popup:{
            removeOnClick:{
                0:'#btn-close-popup',
                1:'#btn-continue-achat',
                2:'#close',
                3:'#continuer'
            }
        },
        ajax:'/js/ajax/update-panier.php',
        data:jQuery("#"+idForm).serialize(),
        callback:'updateProdPanier()'
    });
}

function AllTemoignage(){

    jQuery(".temoignage").css('cursor', 'pointer').click(function(){
        jQuery("body").popup({
            type: "POST",
            popup:{
                removeOnClick:{
                    0:'#close'
                }
            },
            ajax:'/js/ajax/temoignage.php',
            data: 'id='+jQuery(this).attr('id')
        });
    });

    jQuery("#ajouter_un_temoignage").css('cursor', 'pointer').click(function(){
        jQuery("body").popup({
            popup:{
                removeOnClick:{
                    0:'#close'
                }
            },
            ajax:'/js/ajax/ajout-temoignage.php'
        });
    });
}

function updateProdPanier(){
    jQuery.ajax({
        type: "POST",
        url: "/js/ajax/update_prod_panier.php",
        success: function(msg){
            var info = msg.split('|');
            jQuery("#nb-article-header").html(info[0]);
            jQuery("#total-ht-header").html(info[1]);
        }
    });
}

function loadPageInscription(){
    jQuery('#valid-creation-compte').hover(function(){
        jQuery(this).attr('src', '/styles/images/inscription/btn-valider-hover.png');
    }
    , function(){
        jQuery(this).attr('src', '/styles/images/inscription/btn-valider.png');
    });
}
function loadPageModifCompte(){
    jQuery('#valid-creation-compte').hover(function(){
        jQuery(this).attr('src', '/styles/images/inscription/btn-valider-hover.png');
    }
    , function(){
        jQuery(this).attr('src', '/styles/images/inscription/btn-valider.png');
    });
}
function loadPageLogin(){
    jQuery('#btn-connexion').hover(function(){
        jQuery(this).attr('src', '/styles/images/login/btn-connecter-hover.png');
    }
    , function(){
        jQuery(this).attr('src', '/styles/images/login/btn-connecter.png');
    });

    loadRappelTelephone("#rappel-login");
}
function loadPageHome(){
    // Slideshow
    jQuery(document).ready(function() {
        if(jQuery('#slideshow').length > 0){
            
            jQuery("#slideshow").showcase({
                animation:{
                    type:'fade'
                },
                navigator:{
                    position:"top-left",
                    showNumber:true,
                    css:{
                        padding:"0px",
                        zIndex:"2000"
                    },
                    item:{
                        cssClass:'nav-slideshow',
                        cssClassHover:'hover',
                        cssClassSelected:'hover'
                    }
                },
                titleBar:{
                    enabled:false
                }
            });
        }
    });
}

function loadPagePanier(){
    jQuery(".btn-qte-plus").css('cursor', 'pointer').click(function(){
        jQuery("#new-"+jQuery(this).attr('id')).attr('value', parseInt(jQuery("#value-"+jQuery(this).attr('id')).attr('value'))+1);
        jQuery("#form-"+jQuery(this).attr('id')).submit();
    });

    jQuery(".btn-qte-moins").css('cursor', 'pointer').click(function(){
        jQuery("#new-"+jQuery(this).attr('id')).attr('value', parseInt(jQuery("#value-"+jQuery(this).attr('id')).attr('value'))-1);
        jQuery("#form-"+jQuery(this).attr('id')).submit();
    });

    jQuery(".delete-produit").css('cursor', 'pointer').click(function(){
        jQuery("#form-"+jQuery(this).attr('id')).submit();
    });

    jQuery("#port select").each(function(){
        jQuery(this).change(function(){
            jQuery("#port").submit();
        });
    });

    jQuery("#vider-le-panier").click(function(){
        jQuery("#form-flush-panier").submit();
    });

    toolTipLivraison();
}

function loadPageCoord(){
	
    // jQuery("#new_adresse_livraison_id").change(function(){
    //    jQuery("#flag").attr('value', '4');
    //     jQuery('#coordonnees').submit();
    //  });
    
    jQuery("#pays_id").change(function(){
        jQuery("#flag").attr('value', '3');
        jQuery('#coordonnees').submit();
    });

    jQuery("#same-adress").click(function(){
        if(jQuery(this).attr('checked')){
            jQuery("#bloc-adresse-facturation").addClass('desactive');
            jQuery("#bloc-adresse-facturation p input").attr('disabled', 'disabled');
        }else{
            jQuery("#bloc-adresse-facturation").removeClass('desactive');
            jQuery("#bloc-adresse-facturation p input").removeAttr('disabled', 'disabled');
        }
    });

    jQuery("#new_adresse_facturation_id").change(function(){
        var url = '';
        if(jQuery(this).attr('value') == 'nouvelle_adresse'){
            url = '/account_address_book.html?origin=panier&cmd=add#dep_add';
        }else{
            url = '/checkout_shipping.html?new_adresse_livraison_id='+jQuery("#cur_adresse_livraison").attr('value')+'&new_adresse_facturation_id='+jQuery(this).attr('value');
        }
        if(url != '' && !jQuery("#bloc-adresse-facturation").hasClass('desactive')){
      			location.href = url;
        }
    });
	  
	  
    if(jQuery("#same-adress").hasClass('checkThis')){
    	jQuery("#same-adress").attr('checked', 'checked');
	    jQuery("#same-adress").trigger('click');
	    jQuery("#same-adress").attr('checked', 'checked');
		}
		
    toolTipLivraison();

    jQuery("#new_adresse_livraison_id").change(function(){
        var url = '';
        if(jQuery(this).attr('value') == 'nouvelle_adresse'){
            url = '/account_address_book.html?origin=panier&cmd=add#dep_add';
        }else{
        	if(jQuery("#bloc-adresse-facturation").hasClass('desactive')){
            url = '/checkout_shipping.html?new_adresse_livraison_id='+jQuery(this).attr('value')+'&new_adresse_facturation_id='+jQuery(this).attr('value');
          }
          else{
            url = '/checkout_shipping.html?new_adresse_livraison_id='+jQuery(this).attr('value')+'&new_adresse_facturation_id='+jQuery("#cur_adresse_facturation").attr('value');
          }
        }
        if(url != ''){
            location.href = url;
        }
    });
    
}



function loadPageRecap(){
    /*jQuery("#liste-paiement .paiement").css('cursor', 'pointer').click(function(){
        jQuery("#"+jQuery(this).attr('id')+" input:radio").attr('checked', 'checked');
    });*/

    toolTipLivraison();
}

function toolTipLivraison(){
    var decY = 80;
    var decX = 100;
    jQuery(".infos-livraison").each(function(){
        jQuery(this).css('cursor','help');
        jQuery(this).mouseenter(function(event){

            if(jQuery("#popup-"+jQuery(this).attr('id')).attr('id')){
                jQuery("#popup-"+jQuery(this).attr('id')).css({
                    'display':'block',
                    'top':event.pageY - decY,
                    'left':event.pageX - decX
                });
            }else{
                jQuery("<div></div>")
                .html(jQuery("#"+jQuery(this).attr('id')+"-contenu").html())
                .attr('id', "popup-"+jQuery(this).attr('id'))
                .addClass('tool-tip-livraison')
                .css({
                    'top':event.pageY - decY,
                    'left':event.pageX - decX,
                    'position':'absolute'
                })
                .appendTo("body");
            }
        });

        jQuery(this).mouseleave(function(){
            jQuery("#popup-"+jQuery(this).attr('id')).css('display', 'none');
        });

    });
}

function loadSendMail(){
    jQuery("#contact").submit(function(){
        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/contact.php",
            data: jQuery(this).serialize(),
            success: function(msg){
                jQuery("#contenu-contact").html(msg);
            }
        });
        return false;
    });
    jQuery("#btn-valid-contact").hover(
        function(){
            jQuery(this).attr('src', '/styles/images/contact/btn-envoyer-hover.png');
        },
        function(){
            jQuery(this).attr('src', '/styles/images/contact/btn-envoyer.png');
        }
        );
}
function loadInscNewsletter(){
    jQuery("#newsletter").submit(function(){
        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/addNewsletter.php",
            data: jQuery(this).serialize(),
            success: function(msg){
                jQuery("#contenu-contact").html(msg);
            }
        });
        
        return false;
    });
}

function loadFicheProduit(){
    loadChangeImage();
    jQuery( "#tabs" ).tabs();
    loadAjoutPanier();

    if(jQuery("#produit_attribut_id").length > 0){
        loadSelectAttr();
    }

    jQuery("#envoyer-a-ami").click(function(){
        envoyerAmi(jQuery("#produit_id").attr('value'));
    });

    jQuery("#imprimer-fprod").click(function(){
        window.print();
    });
}

function loadSelectAttr(){
    jQuery("#produit-couleur").change(function(){
        updateAttr();
    });
    jQuery("#produit-taille").change(function(){
        updateAttr();
    });
    
    jQuery('.cell-input:not(.surdemande)').click(function(){
        var node = jQuery(this).children('input');
        // gestion cas desactive, on ne peut pas selectionne cet option
        if(jQuery(this).hasClass('desactive')){
            node.removeAttr('checked');
            alert("Ce produit n'est pas disponible avec ces caracteristiques");
        }else{
            node.attr('checked', 'checked');

            var info = node.attr('id').split('-');

            var couleur = '';
            var taille = '';

            if(jQuery("#tableau-inverse").attr('value') == 1){
                couleur = info[2];
                taille = info[1];
            }else{
                couleur = info[1];
                taille = info[2];
            }

            jQuery("#produit-couleur").attr('value', couleur);
            jQuery("#produit-taille").attr('value', taille);
        }
        if(jQuery("#produit-couleur").attr('value') != '' || jQuery("#produit-taille").attr('value') != ''){
            updateAttr();
        }
    });

    jQuery("#liste-option input.disabled").css('cursor', 'default');
    jQuery("#liste-option input.disabled").parents('.cell-input').addClass('desactive');
    
    jQuery(".surdemande").css('cursor','help');
    jQuery(".surdemande").mouseenter(function(event){
        jQuery("#popup-surdemande").css({
            'display':'block',
            'top':event.pageY - 10,
            'left':event.pageX - 400
        });

        jQuery(".surdemande").mouseleave(function(){
            jQuery("#popup-surdemande").css('display', 'none');
        });
    });   

}

function updateAttr(){
    var c = jQuery("#produit-couleur").attr('value');
    var t = jQuery("#produit-taille").attr('value');
    var p = jQuery("#produit_id").attr('value');
    
    // gestion tableau inverse
    if(jQuery("#tableau-inverse").attr('value') == 1){
        opt1 = t;
        opt2 = c;
    }else{
        opt1 = c;
        opt2 = t;
    }

    if(opt1 == '' || opt2 == ''){
        jQuery("#liste-option input:checked").removeAttr('checked');
    }else if(c != '' && t != ''){
        jQuery("#option-"+opt1+"-"+opt2).attr('checked', 'checked');
    }

    jQuery.ajax({
        type: "POST",
        url: '/js/ajax/updateAttr.php',
        data:'couleur='+c+'&taille='+t+'&produit_id='+p,
        success: function(req) {
            var info = req.split('|');

            // cas 1 attribut selectionne
            if(info[0] == 'un-attr'){
                if(info[2] < info[1]){
                    jQuery("#prix-fprod").html(info[2]);
                    jQuery("#prix-promo-fprod").html(info[1]);
                }else{
                    jQuery("#prix-fprod").html(info[1]);
                }
                jQuery("#visu-"+info[4]).trigger('click');
                if(info[3] != ''){
                    jQuery("#produit_attribut_id").attr('value', info[3]);
                }
                if(info[5] != ''){      // ref produit attribut
                    jQuery("#ref-prod-att").html(info[5]);
                }
                
                jQuery("#infos-stock-produit").html(info[6]);
                
            }else if(info[0] == 'no-attr'){     // cas aucun attribut ne correspond
                alert("Ce produit n'est pas disponible avec ces caracteristiques");
                jQuery("#produit_attribut_id").attr('value', '-1');
            }else if(info[0] == 'multi-attr'){  // cas 1 option selectionne, donc plusieurs combinaison possible
                jQuery("#produit_attribut_id").attr('value', '-1');
                if(info[1] != ''){
                    jQuery("#visu-"+info[1]).trigger('click');
                }
            }
            // maj du tableau
            updateTableAttr(opt1, opt2);
        }
    });
}

function updateTableAttr(couleur, taille){
    // recupere tous ceux non desactive
    jQuery(".cell-input:not(.desactive)").addClass('no-select');
    jQuery(".cell-input").removeClass('attr-select');
    jQuery("#liste-option input:checked").parents('.cell-input').addClass('attr-select');
    jQuery("#liste-option input:checked").parents('.cell-input').removeClass('no-select');

    if(couleur == '' || taille == ''){
        var info = '';
        jQuery(".cell-input:not(.desactive) input").each(function(i){
            // option-3-9 => option-couleur-taille
            info = this.id.split('-');
            if((couleur != '' && info[1] == couleur) || (taille != '' && info[2] == taille)){
                jQuery(this).parents('.cell-input').removeClass('no-select');
            }
        });
    }
}

function alterneText(id, text){
    jQuery(id).focus(function(){
        if (jQuery(this).attr('value') == text) {
            jQuery(this).attr('value', '');
        }
    });
    jQuery(id).blur(function(){
        if (jQuery(this).attr('value') == '') {
            jQuery(this).attr('value', text);
        }
    });
}

function loadSlideShow(){

    jQuery("#promo").showcase({
        animation: {
            type: "horizontal-slider",
            stopOnHover: true,
            speed: 600
        },
        navigator:{
            position: "bottom-left",
            css: {
                top: "190px",
                height: "40px",
                "z-index": 1100
                
            },
            showNumber: true,
            item: {
                css: {
                    height:"30px",
                    "line-height":"28px",
                    width:"50px",
                    color: "#ffffff",
                    "font-weight":"bold",
                    "font-size":"18px",
                    backgroundColor: "transparent",
                    border: "none",
                    background:"url(/styles/images/conteneur/left/btn_slideshow.png) no-repeat",
                    margin: "0px 15px 0px 0px",
                    "text-align": "center",
                    "vertical-align": "middle"
                },
                cssHover: {
                    color: "#333333",
                    backgroundColor: "transparent",
                    border: "none",
                    background:"url(/styles/images/conteneur/left/btn_slideshow_select.png) no-repeat"
                },
                cssSelected: {
                    color: "#333333",
                    backgroundColor: "transparent",
                    border: "none",
                    background:"url(/styles/images/conteneur/left/btn_slideshow_select.png) no-repeat"
                }
            }
        },
        titleBar: {
            enabled: false
        }
    });
}

function popupVideo(produit_id){
    jQuery("body").popup({
        popup:{
            removeOnClick:{
                2:'#close'
            },

            css:{
                'width':'520px',
                'height':'330px'
            }
        },
        ajax:'/js/ajax/popupVideo.php',
        data:"produit_id=" + produit_id
    });
}

function popupCms(page_id){
    jQuery("body").popup({
        popup:{
            css:{
                'width':'400px',
                'height':'250px'
            },
            removeOnClick:{
                0:'#btn-close-popup'
            }
        },
        ajax:'/js/ajax/popupCms.php',
        data:'page_id=' + page_id
    });
}


/***********************/
function in_array(value, tableau){
    var a=false;
    for(var i=0;i<tableau.length;i++){
        if(value == tableau[i]){
            a=true;
            break;
        }
    }
    return a;
}
/***********************/


function envoyerAmi(produit_id){
    jQuery("body").popup({
        popup:{
  		
            removeOnClick:{
                0:'#ami_retour',
                1:'#popup_valider',
                2:'#close'
            },
  		
            css:{
                'width':'410px',
                'height':'370px'
            }
        },
        ajax:'/js/ajax/popupEnvoyerAmi.php',
        data:"produit_id=" + produit_id
    });

}

function removePopup(){
    jQuery("#popup").fadeOut(function(){
        jQuery("#popup").remove();
        jQuery("#bg-popup").remove();
        jQuery("select").css('visibility', 'visible');
    });
}

function checkamis(on) {
    jQuery.ajax({
        type: "POST",
        url: '/js/ajax/popupEnvoyerAmi.php',
        data:jQuery('#formamis').serialize(),
        success: function(req) {
            if(jQuery('#popup_ajout_newsletter')) jQuery('#popup_ajout_newsletter').html(req);
        }
    });
}
