// PAGE CATALOGUE
//
var boo_flash = true,             
    param = {typeProd:"",marque:"",categorie:"",genre:"",option_1:0, option_2:0, msgAnchor:""}; // utiliser pr requete ajax
    msgErr = {
        qte:"La quantit\351 doit \352tre sp\351cifi\351e avec une valeur num\351rique", 
        option_a:"L\u2019option ", 
        option_b:" est requise ",
        rez_0: "Il n\u2019 y a pas d\u2019articles de cette marque affich\351s sur notre site actuellement. Veuillez nous contacter ou passer au magasin pour conna\356tre la disponibilit\351 d\u2019un produit."
    }
    
jQuery(function($){
        
    var boo_IE7 = ($.browser.msie == true) && ( 7 == parseFloat(jQuery.browser.version) );
    var boo_IE6 = ($.browser.msie == true) && ( 6 == parseFloat(jQuery.browser.version) );
     
    
    // temporaire
    $("#flash").height(305+"px");
    
    initSWF(boo_flash);
    
    
    // IE7   
    if ( boo_IE7 )
    {
       dropDownIE7();
    }
    
    
    
    
    if ( !boo_IE6 )
    {       
       setCatalogueBox();
        
        $(window).resize(function(){
            setCatalogueBox();
            if (boo_IE7)
            {
                setDropDownLstBoxPos()
            }
        });
        
        //
        // idx des marque a comme valeur init l'idx de la section
        //
        window.param.section = $("#lst_marques").attr("idx");
    
       
        // section catalogue
        // ****
        
        initNavDropDown( window.param.section );
        initCatEvent();
        initBoitePanier();
        initBoiteMsg();   
        panier_etat();
    }
    // IE6
    else if (
        ($.browser.msie)  
    )
    {
        $("#navFiltre").remove();
        //$(".action_carosse").remove();
        initCatEvent();
        initBoitePanier();
        initBoiteMsg();
    }
    
    
    $(window).resize(function(){
         recherche_init(0);
     });
    $(window).load(function( ){
        recherche_init(1);
    });
  
    // tempo debugger paul
    // switchFlash();
    
    if (baseName().indexOf("recherche") !== -1) 
    {
        expandCatalogueBox();
    }
    
    
    $("#boitePanier_btn_droite").live("click", function(){
           // alert(0);
           str_q = get_q();
           window.location.href = makeURL("catalogue.php", "achat/"+str_q["id"]+"/"+str_q["stripe"]  );
    });
});








function ouvrirBoiteMsg(str_mesage, id_anchor)
{
    
    window.param.msgAnchor = id_anchor;
    window.param.msgContenu = str_mesage;
    $("#boiteMsgErr").show();
    $('#boiteMsgErr').jqmShow();
    
}
function fermerBoiteMsg()
{
    $("#boiteMsgErr").hide();
    $("#boiteMsgErr").jqmHide();
}
function initBoiteMsg()
{
    $('#boiteMsgErr').jqm( {
        overlay:0,
        toTop:true,
        modal:true,
        onShow: function(hash){
            // position % anchor
            // console.debug( window.param.msgAnchor );     
            $("#boiteMsgErr p").html(window.param.msgContenu);
            var anchorOffset = $(window.param.msgAnchor).offset()
            if (window.param.msgAnchor != "") // pr IE 
            {
                $('#boiteMsgErr').css("top", anchorOffset.top  );
                $('#boiteMsgErr').css("left", anchorOffset.left - 310 );
            }
        }
    });
}











function initCatEvent()
{
    //
    // ICON PANIER
    jQuery.each( $(".action_carosse"), function(){
        
        $(this).click(function(){
            boitePanier_sendClick();        
        });
            
         $(this).hover(function(){
          set_img_prefix($(this).children("img"), "_0.png", "_1.png");
        },function(){
             set_img_prefix($(this).children("img"), "_1.png", "_0.png");
        }); 
         
        $(this).prev(".action_infos").hover(
            function(){
                set_img_prefix($(this).children("img"), "_0.png", "_1.png");
                ($.browser.msie) ? $(this).parent().parent().prev().show() : $(this).parent().parent().prev().fadeIn();
            },
            function(){
               set_img_prefix($(this).children("img"), "_1.png", "_0.png");
               $(this).parent().parent().prev().hide();
            }
        );
        
    });
    
    
    //
    // lien img prod
    //
    jQuery.each( $("#catalogueEntry div.sectionB img"), function(){
        $(this).click(function(){
            $(this).parents("div").eq(1).find("a.action_infos").click();
        });        
    });
    
    //
    // ICON INFO
    // si deja init
    if ( $("#boiteInfo").jqm_init() ){
        $('#boiteInfo').jqmAddTrigger('a.action_infos');
    }
    else{
        $('#boiteInfo').jqm({
            overlay:0,
            modal:true,
            toTop:true,
            trigger: 'a.action_infos',
            onShow: function(hash){
                
                // position centree
                $('#boiteInfo').css("left", $("#flash").offset().left);
                
                $("#boiteInfo").empty();
                $("#boiteInfo").show();
                

                // clone ajax loader
                $("#boiteInfo").prepend( $("#produitImg .produitImgAjax").clone() );
                $("#boiteInfo img").css("margin", "50px");
                
                var str_id = $(hash.t).parent().attr("id"), 
                url;
                str_id = str_id.substr(3, str_id.length);
                str_url =  dirName()+"/index.php/ajax/produit_info/"+str_id;
                hideAllDropDownList();
                $("#boiteInfo").load(str_url, {}, function(responseText, textStatus, XMLHttpRequest){                    
                    initBoiteInfoEvent();
                });
                
            } 
        }); 
    }
    
    $(".action_infos").hover(function(){
          set_img_prefix($(this).children("img"), "_0.png", "_1.png");
    },function(){
         set_img_prefix($(this).children("img"), "_1.png", "_0.png");
    }); 
    
     

    //
    // ICON LOUPE CATALOGUE
    // si deja init
    if ( $("#produitImg").jqm_init() ){
        $('#produitImg').jqmAddTrigger('a.action_loupe');
    }
    else{
        $('#produitImg').jqm({
            toTop:true,
            modal:true,
            overlay:0,
            trigger: 'a.action_loupe',
            
            onShow: function(hash){
                
                // centree
                $('#produitImg').css("top", ($(window).height() - 490)/2);
                $('#produitImg').css("left", ($(window).width() - 800)/2);
                            
                var str_img_url = $(hash.t).parent().attr("id");
                str_img_url = "#produit" + str_img_url.substr(2, str_img_url.length);
                str_img_url = $(str_img_url + " div.sectionB img").attr("src");
                str_img_url = str_img_url.replace("vignette_cat.", "pleine.");
      
                produitImg_ajaxLoad('#produitImg', str_img_url)
            } 
         }); 
    }
    
    $('.action_loupe').hover(function(){
          set_img_prefix($(this).children("img"), "_0.png", "_1.png");
    },function(){
         set_img_prefix($(this).children("img"), "_1.png", "_0.png");
    }); 
     
      
     
}


function initNavDropDown(int_section)
{
    //
    // Selon le type de produit on a les marque diponible
    //
    // drop down lst "type de produits"
    var url = dirName()+"/index.php/ajax/getDropDownListItems/"+ int_section +"/typeProd";
    $("#lst_type_prod ul").load(url, {}, function(responseText, textStatus, XMLHttpRequest){
        setSelectedIdxdDropDownList("#lst_type_prod", "null");
        setSelectedDropDownList("#lst_type_prod", "label");
        // event
        $("#lst_type_prod .uiLabel").click(function(e){
            toggleDropDownList("#lst_type_prod");
        });
    });
    
    
    // categorie
    initNavDropDown_categorie(int_section, false, false, true);
    
    
    // drop down lst marque
    initNavDropDown_marque(int_section, false, true);
    
    // genre
    initNavDropDown_genre(int_section, true);
}

function initNavDropDown_marque(int_section, int_type_prod, inti_ev)
{
    // drop down lst marque
    window.param.marque = ""; // reset
    
    // si on load// init
    if (inti_ev == true)
    {
        var url = dirName()+"/index.php/ajax/getDropDownListItems/"+ int_section + "/marque" ;
        $("#lst_marques ul").load(url, {}, function(responseText, textStatus, XMLHttpRequest){
            setSelectedIdxdDropDownList("#lst_marques", "null");
            setSelectedDropDownList("#lst_marques", "label");
            // event :: init une fois 
            $("#lst_marques .uiLabel").live("click", function(e){
                toggleDropDownList("#lst_marques");
            });
        });
    }
    // si change de type de prod
    else
    {
       // console.log(int_type_prod);
        var url = dirName()+"/index.php/ajax/getDropDownListItems/"+ int_section +"/marque" + "/" + int_type_prod;
        $("#lst_marques ul").load(url, {}, function(responseText, textStatus, XMLHttpRequest){
            setSelectedIdxdDropDownList("#lst_marques", "null");
            setSelectedDropDownList("#lst_marques", "label");        
        });
    
    }
}

function initNavDropDown_categorie(int_section, int_type_prod, int_marque, inti_ev)
{
    window.param.categorie = ""; 
    var str_id_dd = "lst_categorie";
    // si on load// init : affcihe toutes les options
    if (inti_ev == true)
    {
        var url = dirName()+"/index.php/ajax/getDropDownListItems/"+ int_section + "/categorie" ;
        $("#"+str_id_dd+" ul").load(url, {}, function(responseText, textStatus, XMLHttpRequest){
            setSelectedIdxdDropDownList("#"+str_id_dd, "null");
            setSelectedDropDownList("#"+str_id_dd, "label");
            // event :: init une fois 
            $("#"+str_id_dd+" .uiLabel").live("click", function(e){
                toggleDropDownList("#"+str_id_dd);
            });
        });
    }
    // si change de type de prod
    else
    {
       // console.log(int_type_prod);
        var url = dirName()+"/index.php/ajax/getDropDownListItems/"+ int_section +"/categorie" + "/" + int_type_prod + int_marque;
        $("#" + str_id_dd + " ul").load(url, {}, function(responseText, textStatus, XMLHttpRequest){
            setSelectedIdxdDropDownList("#"+str_id_dd, "null");
            setSelectedDropDownList("#"+str_id_dd, "label");        
        });
    }
}

function initNavDropDown_genre(int_section, init_ev)
{
    window.param.genre = ""; 
    var str_id_dd = "lst_genre";
    // si on load// init : affcihe toutes les options
    if (init_ev == true)
    {
        var url = dirName()+"/index.php/ajax/getDropDownListItems/"+ int_section + "/genre" ;
        $("#"+str_id_dd+" ul").load(url, {}, function(responseText, textStatus, XMLHttpRequest){
            setSelectedIdxdDropDownList("#"+str_id_dd, "null");
            setSelectedDropDownList("#"+str_id_dd, "label");
            
            // event :: init une fois 
            $("#"+str_id_dd+" .uiLabel").live("click", function(e){
                toggleDropDownList("#"+str_id_dd);
            });
        });
    }
    // si change de type de prod
    else
    {
        var url = dirName()+"/index.php/ajax/getDropDownListItems/"+ int_section +"/genre" ;
        $("#" + str_id_dd + " ul").load(url, {}, function(responseText, textStatus, XMLHttpRequest){
            setSelectedIdxdDropDownList("#"+str_id_dd, "null");
            setSelectedDropDownList("#"+str_id_dd, "label");
        });
    }
}

/*
** Function: jqm_init
** jquery helper, indique si jqm a ete init pour le id 
** 
** Parameters:
**    css id selecto - string
** 
** Returns:
**    boolean
*/
$.fn.jqm_init = function(){
    str_id = this.attr("id")
    var boo_init = false;
    jQuery.each($.jqm.hash, function() {
        // $.jqm.hash[1].w.attr("id")
        if ( this.w.attr("id") ==  str_id ){
            boo_init = true
            return;
        }
    });
    return boo_init;
}


/*
** Function: produitImg_ajaxLoad
** helepr pr ajax load img 
*/
function produitImg_ajaxLoad(str_id, str_img_url)
{
    $(str_id+" img.produitImgSrc").hide();
    $(str_id+" img.produitImgAjax").show();
    // on load
    $(str_id+" img.produitImgSrc").load(function(){
       $(str_id+" img.produitImgSrc").fadeIn();
       $(str_id+" img.produitImgAjax").hide();
    });
    $(str_id+" img.produitImgSrc").attr("src", str_img_url);
    $(str_id).show();
}


/*
** Function: initBoiteInfoEvent
** init eve des ele de #boiteInfo 
** 
** Parameters:
**    NOM - TypeDesc
** 
** Returns:
**    TYPE - Desc
*/

function initBoiteInfoEvent()
{
    // section produit
    // fermer
    $("#boiteInfo_btn_gauche, #fermerBoite").click(function(){
        $("#boiteInfo").hide();
        $("#boiteInfo").jqmHide();
        panier_etat();
    });
    
    // section produit
    // alle a panier
    $("#boiteInfo_btn_droite").click(function(){
        $("#boiteInfo").hide();
        $("#boiteInfo").jqmHide();
        boitePanier_sendClick();
    });
    
    // section produit
    // ajouter au panier
    $("#boiteInfo_btn_ajouter").click(function(){
        var boo_qte = true,
            boo_option_1 = true,
            boo_option_2 = true
            str_msg = "",
            id_anchor = "";
            
        // qte valide
        boo_qte = ( isNaN( $("#yCart_qte").val() ) == false );
        if (!boo_qte) {
            str_msg = msgErr.qte + "<br />";
            id_anchor = "#yCart_qte";
        }
        // option valide
        jQuery.each( $("#boiteInfo_pannier .boiteInfo_pannier_dbox"), function(){
            var str_idx =  $(this).attr("id").charAt(14);
            switch( str_idx )
            {
                case "1":
                boo_option_1 = (window.param.option_1.id_i != 0) && (window.param.option_1.nom_i != "")
                if (!boo_option_1){
                    str_msg += msgErr.option_a + window.param.option_1.nom_o + msgErr.option_b+"<br />";
                    id_anchor = "#select_option_1";
                }
                break;
                case "2":
                boo_option_2 = (window.param.option_2.id_i != 0) && (window.param.option_2.nom_i != "")
                if (!boo_option_2) {
                    str_msg += msgErr.option_a + window.param.option_2.nom_o + msgErr.option_b + "<br />";
                    id_anchor = "#select_option_2";
                }
                break;
            }

        });
        
        if ( boo_qte && boo_option_1 && boo_option_2 ){
            // console.log("valide");
            panier_ajouterItem();
        }
        else{
            // pas valide
            ouvrirBoiteMsg(str_msg, id_anchor);
        }
         
    });
    
    
    
    
    // option produit
    //
    // ACTION SUR OPTION #1
    window.param.option_1 = make_param_option(null, 1, true);
    $("#select_option_1 div.dbox_selected").click(function(){
        if ( $(this).next().css("display") == "block" ){
            $(this).next().hide();            
        }
        else
        {
            $("#select_option_2 div.dbox_selected").next().hide();
            $(this).next().show();
        }
    });
    $("#select_option_1 div.dbox_available").click( function(){    
        $("#select_option_1 .dbox_selected").click();        
        window.param.option_1 = make_param_option(this, 1, false);    
        $("#select_option_1 .dbox_selected p").html( "<strong>"+ window.param.option_1.nom_o +"</strong> " + $(this).text() );
    });
    //
    // ACTION SUR OPTION #2    
    window.param.option_2 = make_param_option(null, 2, true);
    $("#select_option_2 div.dbox_selected").click(function(){
        if ( $(this).next().css("display") == "block" ){
            $(this).next().hide();            
        }
        else
        {
            $("#select_option_1 div.dbox_selected").next().hide();
            $(this).next().show();
        }
    });
    
    $("#select_option_2 div.dbox_available").click( function(){
        $("#select_option_2 div.dbox_selected").click(); 
        window.param.option_2 = make_param_option(this, 2, false);    
        $("#select_option_2 .dbox_selected p").html( "<strong>"+ window.param.option_2.nom_o +"</strong> " + $(this).text() );
    });
    
    
    
    
    
    //
    // IE 8 "compatibility view" BUG
    $("#select_option_1").css({
        "z-index":200,
        "margin-left": "10px"
    });

    $("#select_option_2").css({
      "z-index":100,
      "margin-left": "10px"
    });
    
    
    
    //
    // IE 6 "BUG BUG BUG"
    if ( ($.browser.msie == true) && ( 6 == parseFloat(jQuery.browser.version) ) )
    {
        // ?? IE 6
        // carousesel
        $("#boiteInfo_pannier").hide();
        $("#boiteInfo_pannier").show();
        /*
        $("#boiteInfo_pannier").css({
                "top":"0px",
                "left":"0px",
                "z-index":1000,
                "position":"absolute",
                "border":"1px solid red"
        });
        */
    }
    
    
    
    
    //
    // icon loupe dans boite Info
    // si deja init
    if ( $("#produitImgInfo").jqm_init() ){
        $('#produitImgInfo').jqmAddTrigger('#boiteInfo div.loupe a');
    }
    else{
        $('#produitImgInfo').jqm({
            toTop:true,
            overlay:0,
            modal:true,
            trigger: '#boiteInfo div.loupe a',
            
            onShow: function(hash){
                
                // centree
                $('#produitImgInfo').css("top", ($(window).height() - 490)/2);
                $('#produitImgInfo').css("left", ($(window).width() - 800)/2);
    
                // var jq_obj = $(hash.t).parent().next().find("img");
                var jq_obj = $("#boiteInfoo_model_apercu img");
                produitImg_ajaxLoad("#produitImgInfo", jq_obj.attr("src").replace("apercu_mod.", "pleine.") );
            } 
         });
    } 
    
    // init nav modeles
    $("#boiteInfo_model").jCarouselLite({
        visible:2,
        circular:false,
        speed:500,
        btnNext: "#boiteInfo_model_nav_right",
        btnPrev: "#boiteInfo_model_nav_left"
    });
    
    // boiteInfo_model_nav_right disabled ?
    if ( $("#boiteInfo_model li").length < 3 ){
        $("#boiteInfo_model_nav_right").addClass("disabled");
    }
    
    $("#boiteInfo_model div.img-wrapper").click(function(){
            var arr_param = $(this).attr("id").split("_"),
    	 		url = dirName()+"/index.php/ajax/getImgTagModel/" + arr_param[0] + "/" + arr_param[1] + "/apercu_mod";
    	 	// console.log( url );  
            
            //($id_prod, $str_type="vignette_mod", $str_alt="")";
            $("#boiteInfo div.ajax").show();
            $("#boiteInfoo_model_apercu img").hide();
            $("#boiteInfoo_model_apercu").load(url, {}, function(responseText, textStatus, XMLHttpRequest){
                $("#boiteInfo div.ajax").hide();
               // $("#boiteInfoo_model_apercu img").fadeIn();
            });
    });
    
} // FIN init envent boiteInfo


// helper
function make_param_option (obj, idx, empty){
       
       return ( empty ? {
            id_o: 0,
            nom_o: "",
            id_i: 0,
            nom_i: ""
        } : {    
            id_o: $("#select_option_"+idx+" .dbox_selected").attr("id").substr(2),
            nom_o: $("#select_option_"+idx+" div.dbox_selected strong").text(),
            id_i: $(obj).parent().attr("href").substr(1),
            nom_i: $(obj).text()
        } );
    }


/*
** Function: expandCatalogueBox
** expand Catalogu Box on filter produit
** if not expand
** 
*/

function expandCatalogueBox()
{
    var int_h = "150";
    if (1)
    {
        if ( $("#flash").height() != int_h )
        {
            $("#flash").height(int_h+"px");
            setCatalogueBox();
        }
    }
    else
    {
        // bug ici
        // flash reload x fois pendans l'animation ?
        //
        $("#flash").animate({ 
            height: int_h+"px"
        }, 1500, null, function(){
            setCatalogueBox();
        } );
    }
}
function contractCatalogueBox()
{
    $("#flash").height("384px");
    setCatalogueBox()
}

/*
** Function: setCatalogueBox
** set Catalogue Box dim % window height
** 
*/

function setCatalogueBox()
{
    var BoxOffset = $("#catalogueEntry").offset(), documentHeight = $(window).height();
    if ( (documentHeight - BoxOffset.top) > 0 ){
        $("#catalogueEntry").height(documentHeight - BoxOffset.top);
    }
    else{
        // si negatif scroll bar de la fenetre
        $("#catalogueEntry").height("auto");
    }
}



















    
    
/*
** Function: setSelectedIdxdDropDownList
** affecte l'attribut idx du dom object  #lst_marques
** 
** Parameters:
**      str_id
**      int_idx - valeur de l'idx
** 
** Returns:
**    null
*/

function setSelectedIdxdDropDownList(str_id, int_idx){
    $(str_id).attr("idx", int_idx);
    //console.log("setSelectedIdxdDropDownList: " +int_idx);
}


/*
** Function: setSelectedDropDownList
** affecte le nom actif du drop down l'attribut idx du dom object  "#lst_marques"
** utilise un identifciateur id, a parametriser
** 
** Parameters:
**      str_id
**      str_action - label, list
** 
** Returns:
**    null
*/
function setSelectedDropDownList(str_id, str_action){
   // var int_idx = parseInt($(str_id).attr("idx"));
    var int_idx = $(str_id).attr("idx"), j_obj;
    switch (str_id)
    {
        case "#lst_marques" :
            j_obj = $("#m_"+int_idx);
        break;
        case "#lst_type_prod" :
            j_obj = $("#t_"+int_idx);
        break;
        case "#lst_categorie" :
            j_obj = $("#c_"+int_idx);
        break;
        case "#lst_genre" :
            j_obj = $("#g_"+int_idx);
        break;
    }
    
        //var  = (str_id == "#lst_marques") ? $("#m_"+int_idx) : $("#t_"+int_idx);
        // console.debug( $("#m_null")  );
        // int_idx + "  " + str_id + "  " + str_action + "   " +  j_obj  );
        
    switch(str_action){
        
        case "label" :            
            // label du dropDown
            $(str_id + " .txt span").text( $("a", j_obj).text() );
            // cacher dans la list
            $(str_id + " li").show();
            j_obj.hide();
            break
        
        case "list":
            $(str_id + " li").removeClass("selected");
            j_obj.addClass("selected");
            break
            
    }
}

/*
** Function: toggleDropDownList
** toggle Drop Down List 
** 
** Parameters:
**    str_id - dom obj id attr
** 
** Returns:
**    null - null
*/
function toggleDropDownList(str_id)
{
    if ( $(str_id).hasClass("dropDownLst_ouvert") )
        hideDropDownList(str_id);               
    else
        showDropDownList(str_id);
 
}




/*
** Function: showDropDownList
** show Drop Down List 
** 
** Parameters:
**      str_id - dom obj id attr
** 
** Returns:
**      null - null
*/
function showDropDownList(str_id)
{
    // si apercu image est ouvert le fermer
    //
    jQuery.each($(".dropDownLstBox"), function() {
        if( "#"+$(this).attr("id") != str_id){
            hideDropDownList("#"+$(this).attr("id"));
        }
    });
    
    $(str_id).removeClass("dropDownLst_fermer");
    $(str_id).addClass("dropDownLst_ouvert");  
    // item cata
    $( "div.descriptionB, div.descriptionA" ).css("overflow","hidden");
    
    
    
    setSelectedDropDownList(str_id, "list");
    
    // NOTE: juste lst_marques ?
    // 
    if (str_id == "#lst_marques"){
        iniScroll(str_id);
    }
    
    if ( $(str_id).attr("dd_vp_h") == undefined ){
        iniScroll(str_id);
    }
    
    
    if ( $(str_id).attr("dd_vp_h") != undefined ){
        $(str_id + ".uiSlider").slider("moveTo", 0);
    }
    
}

/*
** Function: hideDropDownList
** hide Drop Down List 
** 
** Parameters:
**    str_id - dom obj id attr
** 
** Returns:
**    null - null
*/
function hideDropDownList(str_id)
{
    $(str_id).removeClass("dropDownLst_ouvert");
    $(str_id).addClass("dropDownLst_fermer");  
    
    // a valider dans nouvelle version
    $( "div.descriptionB, div.descriptionA" ).css("overflow","auto");
}


/*
** Function: hideAllDropDownList
** hide All Drop Down List 
** 
*/

function hideAllDropDownList()
{
    jQuery.each($(".dropDownLstBox"), function() {
            hideDropDownList("#"+$(this).attr("id"));
    });
}


/*
** Function: iniScroll
** init slider scroll bar 
** 
** Parameters:
**    str_id - id val of slider
** 
** Returns:
**    null
*/
function iniScroll(str_id)
{
    
    //reset du scrollBox
    
    $(str_id +" .uiSrollBox").height("300px");
    
    var int_pane_h = $(str_id + " .pane").height(), 
        int_vp_h = $(str_id +" .uiSrollBox").height();
    
    $(str_id).attr( "dd_vp_h", int_vp_h);
    $(str_id).attr( "dd_pane_h", int_pane_h);
    
    if ( int_pane_h - int_vp_h > 0){
        $(str_id +" .ui-slider").slider(
        {
            orientation: "vertical",
            slide: function(e, ui){
                var pos = ( int_pane_h - int_vp_h ) * (ui.value-100) / 100;
                $(str_id+" .pane").css("margin-top", pos+"px");
            } 
        });
        //
        // init pos to y = 0 // top
        $(str_id +" .ui-slider").slider( "value", 100);
        
        //
        // move +1 ou -1
        $(str_id +" .scrollOne img").click( function(){  
            var int_pos, int_val;
            jq_slider = $(this).parents(".dropDownLstBox").find(".ui-slider");
            int_val = eval( jq_slider.slider("value") + $(this).attr("rel") + "30" );
            int_val = Math.max(0, Math.min(100, int_val));
            jq_slider.slider("value", int_val);
            
           
            int_pos = ( $(str_id).attr( "dd_pane_h" ) - $(str_id).attr( "dd_vp_h" ) ) * (int_val-100) / 100;
            $(str_id+" .pane").css("margin-top", int_pos+"px");
             
            return false;
        });
         
    }
    else{
        // scoll bar car inutil ...
        $(str_id + " .ui-slider_bg").hide();
        // ajuste hauteur ....
        $(str_id + " .uiSrollBox").css("height", int_pane_h);
    }
}



/*
** Function: filtreProduit
** insere le contenu du catalogue
** ceci suite a une requete ajax
** 
** Parameters:
**      filtre - type de filtre
**      val - idx du filtre
** 
** Returns:
**      nill - nill
*/
function filtreProduit(filtre, val){
   switch(filtre)
   {
       case "m" : // marque
           window.param.marque = (val=="null") ? "" : val;
           setSelectedIdxdDropDownList("#lst_marques", val);
           setSelectedDropDownList("#lst_marques", "label");
           toggleDropDownList("#lst_marques", false);
           
           /*
           // retirer
           if (window.param.marque != "")
               $("#navFiltreWWW").load( dirName()+"/index.php/ajax/marqueUrl/"+window.param.marque );
           else
               $("#navFiltreWWW").html("");
           */
       break;
       case "t" : // type
           window.param.typeProd = (val=="null") ? "" : val;
           setSelectedIdxdDropDownList("#lst_type_prod", val);
           setSelectedDropDownList("#lst_type_prod", "label");
           toggleDropDownList("#lst_type_prod", false);
           
           //
           // load lst de marque en fct du type de produit
           // nouveau 13 avril
           initNavDropDown_marque(window.param.section, window.param.typeProd, false);
       break;
       
       
       case "c" : // categorie
           window.param.categorie = (val=="null") ? "" : val;
           setSelectedIdxdDropDownList("#lst_categorie", val);
           setSelectedDropDownList("#lst_categorie", "label");
           toggleDropDownList("#lst_categorie", false);
           
           // load en fct de
           // initNavDropDown_categorie(window.param.section, window.param.typeProd, window.param.marque, false);
       break;
       
       
       case "g" : // genre
            window.param.genre = (val=="null") ? "" : val;
            setSelectedIdxdDropDownList("#lst_genre", val);
            setSelectedDropDownList("#lst_genre", "label");
            toggleDropDownList("#lst_genre", false);
       break;
   }
   
   var url =  dirName()+"/index.php/ajax/produits";
       
   $("#catalogueEntry").empty();
    
   expandCatalogueBox();
    
   // clone ajax loader
   $("#catalogueEntry").prepend( $("#produitImg .produitImgAjax").clone() );
   $("#catalogueEntry img").css({"margin":"50px 0 0 492px"});
   $("#catalogueEntry").load(url, window.param, function(responseText, textStatus, XMLHttpRequest){
        initCatEvent();
        
        if (responseText.length == 0) $("#catalogueEntry").html(msgErr.rez_0);
   });
}
 
 
function initBoitePanier()
{
    var id_contenu = "#boitePanierContenu";
    //
    // si deja init
    if ( $("#boitePanier").jqm_init() ){
        $('#boitePanier').jqmAddTrigger('div#navMsg div.goToPanier a');
    }
    else{
        $("#boitePanier").jqm({
            toTop:true,
            overlay:0,
            modal:true,
            trigger: 'div#navMsg div.goToPanier a',         
            onShow: function(hash){
                
                // position centree
                $('#boitePanier').css("left", $("#flash").offset().left);
                
                $(id_contenu).empty();
                $("#boitePanier").show();
                
                // clone ajax loader
                $(id_contenu).prepend( $("#produitImg .produitImgAjax").clone() );
                $(id_contenu + " img").css("margin", "50px");
                //
                
                hideAllDropDownList();
                panier_afficher();
            }
        }); 
    }
}
function boitePanier_fermer()
{
    panier_etat();
    $("#boitePanier").hide();
    $("#boitePanier").jqmHide(); 
}
function boitePanier_sendClick()
{
    $("div#navMsg div.goToPanier a").click();
}

function panier_ajouterMsg()
{
    var qty = $("#boiteInfo_panier input[name='field_qty']").val(), str;
    str = (qty > 1) ? qty + " articles" : "1 article" ;
    $("#boiteInfo_msg p span").text(str);
    $("#boiteInfo_msg p").fadeIn(500).delay(1500).fadeOut(500);
}


/*
** Function: panier_ajouterItem
** ajouter un ttem du panier  
** 
*/
function panier_ajouterItem()
{
    var str_ajax_url = dirName()+"/index.php/ajax/produit_panier",
        post_param = {
            
                 "id_item": $("#yCart input[name='id_item']").val(),
                 "prix":  $("#yCart input[name='prix']").val(),
                 "nom":  $("#yCart input[name='nom']").val(),
                 "qte":  $("#yCart_qte").val(),
                 
                 
                 "option_1_id_o": window.param.option_1.id_o,
                 "option_1_nom_o": window.param.option_1.nom_o,
                 "option_1_id_i": window.param.option_1.id_i,
                 "option_1_nom_i": window.param.option_1.nom_i,
                 
                 "option_2_id_o": window.param.option_2.id_o,
                 "option_2_nom_o": window.param.option_2.nom_o,
                 "option_2_id_i": window.param.option_2.id_i,
                 "option_2_nom_i": window.param.option_2.nom_i,
                 
                 "display":0,
                 "action": "add"
        };
		// console.log (post_param);
		$.post(
		    str_ajax_url, 
		    post_param,
		    function(data){
		        // retourne 1 sur succes
		        // console.log(data);
		        //if (data == "1") 
                panier_ajouterMsg();
		    }
        );
}
function panier_afficher()
{
    var str_ajax_url = dirName()+"/index.php/ajax/produit_panier";
    $("#boitePanierContenu").load(str_ajax_url, {"dispaly": 1}, function(){
        panier_init_hover();
    });
}


function panier_etat()
{
    $.get(dirName()+"/index.php/ajax/pannier_count", {}, function(data){
        // appele sur init, sur fermer panier, sur fermer info
        if ( data > 0 )
            $("div#navMsg div.goToPanier a").addClass("active");
        else
            $("div#navMsg div.goToPanier a").removeClass("active");
    });
}
function panier_tout_effacer()
{
    var str_ajax_url = dirName()+"/index.php/ajax/produit_panier"
    $("#boitePanierContenu").load(str_ajax_url, {"dispaly": 1, "action" : "empty"});
}
function panier_init_hover()
{
    $("#boitePanier td.col_5 a").hover(function(){
        set_img_prefix($(this).children("img"), "_0.png", "_1.png");
    },function(){
        set_img_prefix($(this).children("img"), "_1.png", "_0.png");
    });
}

function panier_del_i(id_panier)
{
    var str_ajax_url = dirName()+"/index.php/ajax/produit_panier_del/" +id_panier;
    $.post( 
        str_ajax_url,
        {}, 
        function(){
            panier_afficher();
        }
    );
}


function panier_i_qte(id_panier)
{
    var updateQty = $("#ycart_qte_"+id_panier).val(),
        isCheckout = ($('#jcart-is-checkout').length == 0) ? false : $('#jcart-is-checkout').val();
    
    str_ajax_url = dirName()+"/index.php/ajax/produit_panier";
    
    
    boo_qte = ( isNaN( updateQty ) == false );
    
    if (!boo_qte) {        
        ouvrirBoiteMsg(msgErr.qte, "#ycart_qte_"+id_panier);
    }
    else    
    {
        $("#boitePanierContenu").load(
            str_ajax_url, 
            {
                "id_panier": id_panier, 
                "qte": updateQty, 
                "action": "i_qte", 
                "jcart_is_checkout": isCheckout        // ? 
            },
            function(){
                panier_init_hover();
            }
        );
    }
}




function switchFlash()
{
    $("#flash").html("<img src=\""+dirName()+"/asset/img/tmp_pano.png\" alt=\"\">");
    $("#flash").css("background-color", "#99d");
    $("#flash img").css("margin-top", "50px");
    
}




// FUNCTION: dropDownIE7()
// la structure a changer
function dropDownIE7()
{
    //
    // deplace la barre au complet
    //
    var val = "navFiltre",
        div_offset = $("#"+val).offset();
        
    $("div#"+val).attr("id", val+"_old");
    $("div#"+val+"_old").clone(true).insertAfter( $("#catalogueEntry") ).css(
        {
            "backgroundColor":"#000",
            "position":"absolute",
            "top": div_offset.top,
            "left":  div_offset.left,
            "zIndex":100
        }
    ).attr("id", val);
    $("#"+val+"_old").html("<!-- a ete vie -->");
    
    if (0){
        
        var lst_id = ["lst_genre", "lst_marques", "lst_type_prod", "lst_categorie"];
        jQuery.each(lst_id, function(idx, val){
            jQuery.each($("div#"+val + " li"), function(){
               // $(this).text( $.trim(  $(this).text() ) );
               $(this).css({
                    width:$("div.uiSrollBox div.pane").css("width"),
                    overflow:hidden
               });
               
            });
        });
    }
    
    $("div.dropDownLstBox  div.txt").css({"padding-top":"4px"});
}

// pr IE7
function setDropDownLstBoxPos()
{
    var val = "navFiltre",
    div_offset = $("#"+val+"_old").offset();
    
    $("div#"+ val).css(
        {"top": div_offset.top}
    );
}




function get_q()
{
    var s = window.location.search.substring(1),
    a = s.split('&'),
    r = {},
    v;
    for (var i=0, l=a.length; i<l; i++)
    {
        v = a[i].split("=");
        r[v[0]]=v[1];
    }
    return r;
}



