

/******************************************************************************************************************************************/
//Fonction permettant d afficher des TG de facon aleatoire
function getAffichageTGHP(tab){
    if (tab.length > 0) {
         // On verifie dans quel tg il y a des produits + style different pour le premier
        var tg1=false, tg2 =false, premierTg1 = tab[0], premierTg2 = tab[0];
        
        for (var i =0;i < tab.length;i++) {
            if (typeof tabProductsTgHp[0][' ' + tab[i].substring(tab[i].indexOf('_') + 1)] != "undefined") tg1 = true;
            if (tabProductsTgHp.length > 1 && typeof tabProductsTgHp[1][' ' + tab[i].substring(tab[i].indexOf('_') + 1)] != "undefined") tg2 = true;
            
            if (typeof tabProductsTgHp[0][' ' + premierTg1.substring(premierTg1.indexOf('_') + 1)] == "undefined" || tabProductsTgHp[0][' ' + tab[i].substring(tab[i].indexOf('_') + 1)] < tabProductsTgHp[0][' ' + premierTg1.substring(premierTg1.indexOf('_') + 1)])
                premierTg1 = tab[i];
            if (tg2 && (typeof tabProductsTgHp[1][' ' + premierTg2.substring(premierTg2.indexOf('_') + 1)] == "undefined" || tabProductsTgHp[1][' ' + tab[i].substring(tab[i].indexOf('_') + 1)] < tabProductsTgHp[1][' ' + premierTg2.substring(premierTg2.indexOf('_') + 1)]))
                premierTg2 = tab[i];
        }
        if (tg1) document.getElementById(premierTg1).className += " premier";
        if (tg2) document.getElementById(premierTg2).className += " premier";
       
       var nbTg1 = 0, nbTg2 = 0, isTg1 = false, isTg2 = false;
        for (var i = 0;i < tab.length && (nbTg1 <= 2 || nbTg2 <= 2);i++) {
            if (typeof tabProductsTgHp[0][' ' + tab[i].substring(tab[i].indexOf('_') + 1)] != "undefined") {
                nbTg1++;
                isTg1 = true;
                isTg2 = false;
            }
            if (tg2 && typeof tabProductsTgHp[1][' ' + tab[i].substring(tab[i].indexOf('_') + 1)] != "undefined") {
                nbTg2++;
                isTg2 = true;
                isTg1 = false;
            }
        
            if (isTg1 && nbTg1 <= 2 || isTg2 && nbTg2 <= 2) {
                showBloc(tab[i]);
                if (!lib_stock) lib_stock = libStock2;
                setBlocByHtml('disponibiliteTg_' + tab[i].substr(tab[i].indexOf('_') + 1),lib_stock);
            }
        }
        
        if (tg1) showBloc('blocTGHP-0');
        if (tg2) showBloc('blocTGHP-1');
        
        showBloc('infoLegalesCentraleHomepage');
    }
}

/************************************************************************************************************************************/
//Fonction permettant d afficher des TG sur la page rayon
function getAffichageTGRayon(tab){
    if (tab.length>0){
        if (tab.length > 2) visibleBloc("fleche-droite");
        
        for (i=0;i<tab.length ;i++){
            showBloc(tab[i]);
            if(!lib_stock) lib_stock = libStock2;
            setBlocByHtml('disponibiliteTg_' + tab[i].substr(tab[i].indexOf('_') + 1),lib_stock);
        }    
        showBloc('ongletTG');
    }
}
 
 /******************************************************************************************************************************************/
//Fonction permettant d afficher des TG de facon aleatoire
function getAffichageTGBrandHP(tab){
    if (tab.length>0){
    vstyle=" 1px solid ";
    setBlocByHtml("titreTGHPBrand","<span>"+titreHPBrand+"</span><div/>");
      if (tab.length >maxNbPrdbrandHome)
        nbrRestants = maxNbPrdbrandHome;
    else
        nbrRestants=tab.length ;       
        for (i=0;i<nbrRestants ;i++){              
            Lemodele =  tab[i].substring(tab[i].indexOf("_")+1,tab[i].length);
            showBloc(tab[i]);
            changeBlocColor("promo_"+Lemodele,colorBrand);
            changeBlocColor("dates_"+Lemodele,colorBrand);
            changeBlocColor("apartirde_"+Lemodele,colorBrand);
            changeBlocColor("prix-promo_"+Lemodele,colorBrand);
            changeBlocColor("reductionPourcentage_"+Lemodele,colorBrand);
            changeBlocColor("reductionPrix_"+Lemodele,colorBrand);
            changeBlocColor("prix_"+Lemodele,colorBrand);
            changeBlocColor("marque_"+Lemodele,colorBrand);
            changeBlocColor("description_"+Lemodele,colorBrand);
            changeBlocColorBorder("prix_"+Lemodele,vstyle,colorBrand);
            changeBlocColorBorder("prix-promo_"+Lemodele,vstyle,colorBrand);     
     }
     }
     else{
        setBlocByHtml("titreTGHPBrand","<span> </span>");
     }
 }
 /*################################################################################################
############################## JS DES FONCTIONS POUR LE DEFILEMENT DES TG DE LA PAGERAYON  ###################
/*############################################################################################## */
/* Variables pour le defilement des TG sur la page rayon */
    // Deplacement en pixels entre chaque reaffichage
    var delta=10;
    // Position initiale du bandeau
    var posx=-258;
    // Position a atteindre au premier click (a drotie)
    var posp=2;
    // Coordonnees des 3 positions : 0 a gauche - 1 au milieu - 2 a droite
    var posxvaleur = new Array();
    posxvaleur[0]=0;
    posxvaleur[1]=-257;
    posxvaleur[2]=-514;

function defilg() {
    if (posp<2) posp=posp+1;
    defilgauche()
}

function defilgauche() {
    document.getElementById('bandeau-produits').style.left=posx+"px";
    posx=Math.round(posx-delta);
    if (delta>2) delta=delta*0.97;
    if (posx>posxvaleur[posp]) setTimeout("defilgauche()",20);
    else {
        delta=10;
        document.getElementById('bandeau-produits').style.left=posxvaleur[posp]+"px";
    }
    if (posp == 0) {
        invisibleBloc('fleche-gauche');
        visibleBloc('fleche-droite');
    }
    if (posp == 1) {
        visibleBloc('fleche-gauche');
        visibleBloc('fleche-droite');
    }
    if (posp == 2) {
        visibleBloc('fleche-gauche');
        invisibleBloc('fleche-droite');
    }
}

function defild() {
    if (posp>0) posp=posp-1;
    defildroite(posp)
}

function defildroite() {
    document.getElementById('bandeau-produits').style.left=posx+"px";
    posx=Math.round(posx+delta);
    if (delta>2) delta=delta*0.97;
    if (posx<posxvaleur[posp]) setTimeout("defildroite()",20);
    else {
        delta=10;
        document.getElementById('bandeau-produits').style.left=posxvaleur[posp]+"px";
    }
    if (posp == 0) invisibleBloc('fleche-gauche');
    if (posp == 1) {
        visibleBloc('fleche-gauche');
        visibleBloc('fleche-droite');
    }
    if (posp == 2) {
        visibleBloc('fleche-droite');
        invisibleBloc('fleche-gauche');
    }
}
