(new Image()).src =    site_root + "skin/frontend/default/lunedemiel/images/promos_bg.png";
(new Image()).src =    site_root + "skin/frontend/default/lunedemiel/images/idees_recettes_cuisine_hover.png";
(new Image()).src =    site_root + "skin/frontend/default/lunedemiel/images/idees_recettes_beaute_hover.png";
(new Image()).src =    site_root + "skin/frontend/default/lunedemiel/images/promo_promo_bg_hover.png";
(new Image()).src =    site_root + "skin/frontend/default/lunedemiel/images/btn_close_hover.png";
(new Image()).src =    site_root + "skin/frontend/default/lunedemiel/images/add_card_mini_hover.png";
(new Image()).src =    site_root + "skin/frontend/default/lunedemiel/images/product_add_card_hover.png";
(new Image()).src =    site_root + "skin/frontend/default/lunedemiel/images/products_mini_panier_moins_hover.png";
(new Image()).src =    site_root + "skin/frontend/default/lunedemiel/images/products_mini_panier_plus_hover.png";
(new Image()).src =    site_root + "skin/frontend/default/lunedemiel/images/carroussel_droite_hover.jpg";
//(new Image()).src =    site_root + "skin/frontend/default/lunedemiel/images/carroussel_gauche_plus_hover.jpg";
//(new Image()).src =    site_root + "skin/frontend/default/lunedemiel/images/newsletter_send_hover.jpg";
(new Image()).src =    site_root + "skin/frontend/default/lunedemiel/images/body_bg.png";

function _init_lunedemiel(){

    // Variables
    var default_search_text = "Vous cherchez un produit ? ";
    var default_newsletter_text = "Saisissez votre adresse email";
    var default_compte_mail = "Votre email ";
    var default_password = "password";
    
    //  -----  Traitements pour les produits  -----
    if (arguments[0]) {
        list_produits(arguments[0]);
    }
    if (arguments[1]) {
        jQuery("div[id=" + arguments[1] + "]/img").attr("src", "" + site_root + "skin/frontend/default/lunedemiel/images/" + jQuery(arguments[1]).attr("id") + "_hover.png");
        var image = jQuery("#icon_img_big").attr("src",  "" + site_root + "skin/frontend/default/lunedemiel/images/" + arguments[1] + "_big.jpg");
    }
    
    //  -----  Prechargement des images du site et des images de survol    -----
    // Ajout du survol des icones
    var icon_rollovers = jQuery("#content_top_middle").find("img");
    icon_rollovers.each(function(){
      (new Image()).src =    site_root + "skin/frontend/default/lunedemiel/images/" + jQuery(this).attr("id") + "_hover.png";
    });
    // Prechargemnent des images definies dans les CSS
    jQuery.preloadCssImages();

    // ------  Preparation initiale de la page
    jQuery('#icon_desc, #section_title, #masque').hide();
     jQuery("div.bloc_left, div.bloc_right, #compte, #home_panier").css("height", 0);
     jQuery("#main").append("<div id='product_hover_infos'></div>");
     jQuery("#masque").detach();
     
     //  -----  Comportements de survol  -----
     jQuery("#idees_recettes1").bind("mouseover", function(){
        jQuery(this).css("background", "url(" + site_root + "skin/frontend/default/lunedemiel/images/idees_recettes_cuisine_hover.png) no-repeat top left");
        jQuery(this).find("span").css({"backgroundColor": "#FF4100", "borderLeft": "12px #FF4100 solid", "borderRight": "12px #FF4100 solid"});
    });
    jQuery("#idees_recettes1").bind("mouseout", function(){
        jQuery(this).css("background", "url(" + site_root + "skin/frontend/default/lunedemiel/images/idees_recettes_cuisine.png) no-repeat top left");
        jQuery(this).find("span").css({"backgroundColor": "#CC001F", "borderLeft": "12px #CC001F solid", "borderRight": "12px #CC001F solid"});
    });
    jQuery("#idees_recettes2").bind("mouseover", function(){
        jQuery(this).css("background", "url(" + site_root + "skin/frontend/default/lunedemiel/images/idees_recettes_beaute_hover.png) no-repeat top left");
        jQuery(this).find("span").css({"backgroundColor": "#FF4100", "borderLeft": "12px #FF4100 solid", "borderRight": "12px #FF4100 solid"});
    });
    jQuery("#idees_recettes2").bind("mouseout", function(){
        jQuery(this).css("background", "url(" + site_root + "skin/frontend/default/lunedemiel/images/idees_recettes_beaute.png) no-repeat top left");
        jQuery(this).find("span").css({"backgroundColor": "#CC001F", "borderLeft": "12px #CC001F solid", "borderRight": "12px #CC001F solid"});
    });
    jQuery("#content_promos_promos").bind("mouseover", function(){
        jQuery(this).css("background", "url(" + site_root + "skin/frontend/default/lunedemiel/images/promo_promo_bg_hover.png) no-repeat 0 4px");
    });
    jQuery("#content_promos_promos").bind("mouseout", function(){
        jQuery(this).css("background", "url(" + site_root + "skin/frontend/default/lunedemiel/images/promo_promo_bg.png) no-repeat 0 4px");
    });
    jQuery("#bloc_close").live("mouseover", function(){
        jQuery(this).css("background", "url(" + site_root + "skin/frontend/default/lunedemiel/images/btn_close_hover.png) no-repeat top left");
    });
    jQuery("#bloc_close").live("mouseout", function(){
        jQuery(this).css("background", "url(" + site_root + "skin/frontend/default/lunedemiel/images/btn_close.png) no-repeat top left");
    });
    jQuery("#accueil_produits_left").live("mouseover", function(){
        jQuery(this).css("background", "url(" + site_root + "skin/frontend/default/lunedemiel/images/carroussel_droite_hover.jpg) no-repeat top left");
    });
    jQuery("#accueil_produits_left").live("mouseout", function(){
        jQuery(this).css("background", "url(" + site_root + "skin/frontend/default/lunedemiel/images/carroussel_droite.jpg) no-repeat top left");
    });
    jQuery("#accueil_produits_right").live("mouseover", function(){
        jQuery(this).css("background", "url(" + site_root + "skin/frontend/default/lunedemiel/images/carroussel_gauche_hover.jpg) no-repeat top left");
    });
    jQuery("#accueil_produits_right").live("mouseout", function(){
        jQuery(this).css("background", "url(" + site_root + "skin/frontend/default/lunedemiel/images/carroussel_gauche.jpg) no-repeat top left");
    });
         
    //Comportements : vider les input pre-remplis
    jQuery("#header_search_input").bind("focus", function() {
        if (jQuery(this).attr("value") === default_search_text){
            jQuery(this).attr("value", "");
        }
    });
    jQuery("#newsletter_input").bind("focus", function() {
        if (jQuery(this).attr("value") === default_newsletter_text){
            jQuery(this).attr("value", "");
        }
    });
    jQuery("#compte_mail").live("focus", function() {
        if (jQuery(this).attr("value") === default_compte_mail){
            jQuery(this).attr("value", "");
        }
    });
    jQuery("#compte_password").bind("focus", function() {
        if (jQuery(this).attr("value") === default_password){
            jQuery(this).attr("value", "");
        }
    });

    // **********  ICONES ET IMAGE PRINCIPALE  **********
    //  -----  Comportement : rollover sur les icones  -----
    var icons = jQuery("div[class=content_top_middle_line]/img").find("*");
    icons.bind("mouseover", affiche_icon_hover);
    icons.bind("mouseout", cache_icon_hover);
    //Par mesure de s�curit�, le comportement est aussi pass� aux div englobantes... 
    jQuery("#content_top_left, #content_top_right").bind("mouseover", cache_icon_hover);
    function affiche_icon_hover(e){
        jQuery('body > #icon_desc').stop();
        jQuery('body > #icon_desc').detach();
        jQuery("body").append("<div id='icon_desc'></div>");
        icone = jQuery('body > #icon_desc');
        icone.append(jQuery(this).attr("alt"));
        icone.css('top', e.pageY - 11);
        icone.css('left', e.pageX + 10);
        jQuery(this).attr("src", "" + site_root + "skin/frontend/default/lunedemiel/images/" + jQuery(this).attr("id") + "_hover.png");
        icone.animate({
            opacity: 1
        }, 200);
    }
    function cache_icon_hover(e){
        jQuery('#icon_desc').stop();
        jQuery('#icon_desc').animate({
            opacity: 0
        }, 100, function(){
            jQuery('body > #icon_desc').detach();
        });
        jQuery(this).attr("src", "" + site_root + "skin/frontend/default/lunedemiel/images/" + jQuery(this).attr("id") + ".png");
    }
    
    //  -----  Fonction : changer l'image principale
    //  -----  Comportement : click sur une icone  -----
    icons.bind("click", change_main_image);
    function change_main_image(){
        var title = jQuery(this).attr("alt");
        var image = jQuery("#icon_img_big");
        var img_src = "" + site_root + "skin/frontend/default/lunedemiel/images/" + jQuery(this).attr("id") + "_big.jpg";
        image.attr("usemap", "");
        //D�placement si n�cessaire du bloc promos
        promo_rayon();
        //Liste des produits
        // list_produits();
        list_produits(1, jQuery(this).attr("id"));
        // Titre sous l'image
        jQuery("#section_title").animate({
            opacity: 0
        },300); 
        image.animate({
            opacity: 0
        },300,function(){
            jQuery(this).attr({
                "src": img_src,
                "title": jQuery(this).attr("alt"),
                "alt": jQuery(this).attr("alt")
            });
            jQuery("#picture_loading").detach();
            image = jQuery(this);
            jQuery(this).attr({
                "src": img_src,
                "title": jQuery(this).attr("alt"),
                "alt": jQuery(this).attr("alt")
            });
            if (jQuery.browser.msie){
                image.animate({
                    opacity: 1,
                    zindex: '10'
                },1000, function(){
                    jQuery(this).css("opacity", "none");
                    jQuery("#picture_loading").detach();
                });
                var section_title_title = jQuery("#section_title_title");
                section_title_title.text(title);
                jQuery("#section_title").css({"width": (title.length * 8) + 35, "display": "block"});
                jQuery("#section_title").animate({
                    opacity: 1
                },1000, function(){jQuery(this).css("opacity", "none");});
            }
            else {    
                jQuery("#main").append("<div id='picture_loading'>Chargement en cours ... </div>");
                jQuery("#picture_loading").fadeIn(200);
                jQuery(this).load(function(){
                    jQuery("#picture_loading").stop();
                    jQuery("#picture_loading").animate({
                        opacity: 0
                    },200, function(){
                        image.animate({
                        opacity: 1,
                        zindex: '10'
                    },1000, function(){
                        jQuery("#picture_loading").detach();
                    });
                    var section_title_title = jQuery("#section_title_title");
                    section_title_title.text(title);
                    jQuery("#section_title").css({"width": (title.length * 8) + 35, "display": "block"});
                    jQuery("#section_title").animate({
                        opacity: 1
                    },1000);

                
                    });
                });
            }
        });
    }
    //  **********  ICONES ET IMAGE PRINCIPALE End  **********
    
    //  ********** CARROUSSEL PRODUITS Start  ********
    //  -----  Fonction: Placement inital du bloc sous le carroussel  -----
    function promos_init(){
        jQuery("#content_promos").stop();
        jQuery("#content_promos").delay(0).animate({
            marginTop: "59px"
        },600);
    }
    
    //  -----  Fonction: Placement du bloc sous le carroussel, rayon selectionn�  -----
    this.promo_rayon = function(){
        jQuery("#content_promos").delay(0).animate({
            marginTop: "170px"
        },600);
        jQuery("#miel").css("height", 150);
        jQuery("#page_container").animate({
            marginTop: "170px"
        },600);
    }
    //  -----  Fonction: Placement du bloc sousle carroussel avec infos produit  -----
    function promo_produit(){
        if (jQuery("#content_promos").css("marginTop") == "228px" || jQuery("#page_container").css("marginTop") == "228px"){
            return false;
        }
        else {
            jQuery("#content_promos").delay(0).animate({
                marginTop: "228px"
            },600);
            jQuery("#page_container").delay(0).animate({
                marginTop: "228px"
            },600);
            jQuery("#miel").css ("height", 170);
            return true;
        }
    }
    
    //  -----  Plugin: liste des produits  -----  

    this.list_produits = function()
    { supprimer_select_produit();
      jQuery("#accueil_produits_masque").animate({marginLeft:620});
      jQuery("#accueil_produits_left").animate({opacity: 0}, 200, function(){jQuery(this).detach();});
      jQuery("#accueil_produits_right").animate({opacity: 0}, 200, function(){jQuery(this).detach();});
      var margin= 0;
      var first = arguments[0];
      var id = arguments[1];
      var largeur = 0;
      if(typeof(categories[id]) != "undefined")
      { new Ajax.Request
        ( site_root + "index.php/jcatalog/list/products",
//        ( "http://localhost/www.lunedemiel.fr/echange/public.24.02.2010/liste_produits.html",
        { method: "post",
            parameters: {id_caterory: categories[id]},
            onComplete: function(transport)
            { var response = eval('(' + transport.responseText + ')');
              var html = response["html"];
              //var html = transport.responseText;
              if(html.indexOf("product_item") !== -1)
              { var i = 0;
                jQuery("#miel").empty();
                jQuery("#accueil_produits_left").detach();
                jQuery("#accueil_produits_right").detach();
                jQuery("#miel").append(html);
                var produits = jQuery(html).find("div.product_item");
                var produits_img = jQuery("div.product_image > a > img").each(function() { jQuery(this).css({"height": 105, "paddingTop": 20}); });
                jQuery("div.product_image > a ").die();
                survol_produits();
                if(false && first)
                { var max = 6;
                  var restant = jQuery(".product_item").length - first;
                  var decallage;
                  if(restant < max) decallage = restant - max + first - 2;
                  else
                  { decallage = first + 2;
                    jQuery("#accueil_produits_left").delay(0).animate({opacity: 0}, 400);
                  }
                  margin = 0 - (decallage * 100);
                }
                if(jQuery(".product_item").length < 6)
                { margin = (6 - jQuery(".product_item").length) * 62;
                }
                jQuery("#miel").before("<div id='accueil_produits_right'></div>");
                jQuery("#accueil_produits_right").css({opacity: 0});
                if(jQuery(".product_item").length > 6 && margin < 0) jQuery("#accueil_produits_right").delay(0).animate({opacity: 1}, 400);
                jQuery("#accueil_produits_masque").delay(0).animate
                ( {marginLeft: margin},
                  1500,
                  function()
                  { jQuery("#miel").after("<div id='accueil_produits_left'></div>");
                    if(jQuery(".product_item").length > 6) jQuery("#accueil_produits_left").animate({opacity: 1}, 400);
                  }
                );
                if(false && first) survol_produits(first);
                if(jQuery(".product_item").length > 6) jQuery("#accueil_produits_left").live("click", carroussel_left);
                if(jQuery(".product_item").length > 6) jQuery("#accueil_produits_right").live("click", carroussel_right);
              }
            }
          }
        );
      }
    }

    function supprimer_select_produit(){            
           jQuery("div.product_image > a > img").stop();
           jQuery("div.product_image > a > img").each(function(){
               if(parseInt(jQuery(this).css("height")) > 105){
                   jQuery(this).animate({
                       height: 105    ,
                       paddingTop : 20,
                       paddingLeft: 8
                   },150);
               }
           });
           jQuery("#product_hover_infos").stop();
           jQuery("#product_hover_infos").fadeOut(150);
    }
    function carroussel_left() {
        supprimer_select_produit();
        produits = jQuery("#accueil_produits_masque").find("div.product_item");
        //determination de la position finale
        var margin = parseInt(jQuery("#accueil_produits_masque").css("marginLeft"));
        var first = margin / -100;
        var max = 6;
        var restant = jQuery(".product_item").length - first - max;
        var decallage;
        if (restant > max) { decallage = max; }
        else {
            decallage = restant;
             jQuery(this).delay(0).animate({opacity: 0}, 400);
        }
         margin -= decallage * 100;
        vitesse = 350 * decallage;
        var masque_width = decallage * 100 + parseInt(jQuery("#accueil_produits_masque").css("width"));

        jQuery("#accueil_produits_right").delay(0).animate({opacity: 1}, 400);
        
        jQuery("#accueil_produits_masque").css({"width": masque_width});
        jQuery("#accueil_produits_masque").animate({marginLeft: margin}, vitesse);
    }
    function carroussel_right(){
        supprimer_select_produit();
        //determination de la position finale
        var margin = parseInt(jQuery("#accueil_produits_masque").css("marginLeft"));
        var first = margin / -100;
        var max = 6;
        var decallage;
        if (first < max) {
            decallage = first;
             jQuery(this).delay(0).animate({opacity: 0}, 400);
        }
        else {decallage = max;}
         jQuery("#accueil_produits_left").delay(0).animate({opacity: 1}, 400);
        margin = margin + (decallage* 100);
        vitesse = 350 * decallage;
        var masque_width = parseInt(jQuery("#accueil_produits_masque").css("width")) - (decallage * 100);
        jQuery("#accueil_produits_masque").animate({marginLeft: margin}, vitesse, function(){jQuery("#accueil_produits_masque").css({"width": masque_width});});
    
    }
    function survol_produits(){
           jQuery("div.product_image > a > img").css({"height":105});
           jQuery("div.product_image > a ").live("mouseover", infos_produit);
           if (arguments[0]){
               var produits = jQuery("#accueil_produits_masque").delay(0).find(".product_item");
               var produit = produits[arguments[0]];
               var attente = promo_produit();
               //Animation des images
               jQuery(produit).first("img").animate({
                    height: 125    ,
                    paddingTop : 0,
                    paddingLeft:0
                },300);
            //Affichage des infos produit
               var infos = jQuery(produit).find(".product_hover > *").clone();
               var item_position = jQuery(produit).position();
               if (item_position == null) {
                   item_position = 0;
               }
               var position = item_position.left - 7;
               jQuery("#product_hover_infos").stop();
               jQuery("#product_hover_infos").fadeOut(150).delay(0).empty().append(infos).css({display: "block", left: position});
               jQuery("#page_container").animate({
                    marginTop: 218
                },600, function(){
                    jQuery("#product_hover_infos").delay(0).fadeIn(300);
                    jQuery("#miel").css ("height", 150);
                   }
            );
           }
    }
    
    function infos_produit(){
        var attente = promo_produit();
           //Animation des images
           if (jQuery(this).find("img").css("height") < "106px") {
               jQuery("div.product_image > a > img").stop();
               jQuery("div.product_image > a > img").each(function(){
                   if(jQuery(this).css("height") > "105px"){
                       jQuery(this).animate({
                           height: 105    ,
                           paddingTop : 20,
                           paddingLeft: 8
                       },150);
                   }
               });
               jQuery(this).find("img").animate({
                    height: 125    ,
                    paddingTop : 0,
                    paddingLeft:0
                },300);
            //Affichage des infos produit
               var infos = jQuery(this).parent().find(".product_hover > *").clone();
               
               var item_position = jQuery(this).parent().parent().position();
               var position = item_position.left - 7 + parseInt(jQuery("#accueil_produits_masque").css("marginLeft"));
               jQuery("#product_hover_infos").stop();
               jQuery("#product_hover_infos").css("opacity", 1).fadeOut(150, function(){
                   jQuery(this).empty().append(infos).css({left: position, opacity: "none"});
               }
               );
               if(attente == true) {
                   jQuery("#product_hover_infos").delay(0).fadeIn(300, function(){jQuery(this).css("opacity", "none");});
               }
               else{
                   jQuery("#product_hover_infos").fadeIn(300, function(){jQuery(this).css("opacity", "none");});
               }
               jQuery("#product_hover_infos").delay(0).css("opacity", "none");
           }
    }
    
    //  **********  CARROUSSEL Produits End  **********
        
        
    //  **********  BLOCS  Start**********
    //  -----  Comportements : Affichage du masque  -----
    this.afficher_masque = function()
    { if(!jQuery.browser.msie || parseInt(jQuery.browser.version) != 7)
      { jQuery("body").append("<div id='masque'></div>");
        jQuery("#masque").css({"opacity": 0.6}).fadeIn(500);
      }
    }

    function cacher_masque()
    { if(!jQuery.browser.msie || parseInt(jQuery.browser.version) != 7)
      { jQuery("#masque").fadeOut(500);
        jQuery("#masque").detach();
      }
    }
    
    //  -----  Comportements : Fermeture du bloc
    jQuery("#bloc_close, #masque, #cart_block_back").live("click",function() {
         jQuery("#masque").fadeOut(500);
        jQuery(".bloc").animate({
            opacity: 0
        }, 400, function(){
            jQuery(this).detach();
        });
    });
    
    //  -----  Comportements : Affichage du panier  -----
    jQuery("#header_panier_right div").click( function(){
        //Ouverture
        if (jQuery("#main").find("#home_panier").length === 0){
            afficher_panier();
        }
        //Fermeture
        else {
            cacher_panier();
        }
    });

    function afficher_panier()
    { jQuery("#header_compte").css("z-index", 4);
      jQuery("#header_panier").css("z-index", 11);
      afficher_masque();
      jQuery("#masque").fadeIn(500);
      jQuery("#main_loading").css("display", "block");
      new Ajax.Request
      ( site_root + "index.php/jcatalog/cart/cart",
        { method: "post",
          parameters: {},
          onComplete: function(transport)
          { jQuery("#main_loading").css("display", "none");
            var response = eval('(' + transport.responseText + ')');
            if(typeof(response["redirect"]) == "undefined")
            { var html = response["html"];
              jQuery("#main").append(html);
              jQuery("#home_panier").fadeIn(500);
              var container = jQuery("div.bloc_content > div.bloc_content_white");
//              container.animate({height: "750px"}, 400);
              container.get(0).style.height = "auto";
            }
            else document.location.href = response["redirect"];
          }
        }
      );
    }

    this.cacher_panier = function()
    { var container = jQuery("div.bloc_content > div.bloc_content_white");
      cacher_masque();
      jQuery("#home_panier").fadeOut(500);
      container.animate({height: "0"}, 400, function(){jQuery("#home_panier").detach();});
    }
    
    //  -----  Comportements: Affichage du compte  -----
    jQuery(".hc_connexion_link").click( function(){
        //Ouverture
        if (jQuery("#main").find("#compte").length === 0){
            afficher_compte();
        }
        
        //Fermeture
        else {
            cacher_compte();
        }
    });

    function afficher_compte()
    { jQuery("#header_panier").css("z-index", 4);
      jQuery("#header_compte").css("z-index", 11);
      afficher_masque();
      new Ajax.Request
      ( site_root + "index.php/jcatalog/login/login",
        { method: "post",
          parameters: {},
          onComplete: function(transport)
          { var response = eval('(' + transport.responseText + ')');
            var html = response["html"];
            jQuery("#main").append(html);
            jQuery("#compte").fadeIn(500);
            var container = jQuery("div.bloc_content > div.bloc_content_orange");
            container.animate({height: "123px"}, 400);
          }
        }
      );
    }

    function cacher_compte(){
        var container = jQuery("div.bloc_content > div.bloc_content_orange");
        
        cacher_masque();
         jQuery("#compte").fadeOut(500);
        container.animate({
             height: "0"
         }, 400, function(){
             jQuery("#compte").detach();
        });
    }
    
    // -----  Comportement: nouveau compte  -----
    jQuery("#compte_nouveau_url").live("click", function(){
        //Ouverture
        if (jQuery("#main").find("#compte_nouveau_div").length === 0){
            afficher_nouveau_compte();
        }
        
        //Fermeture
        else {
            cacher_nouveau_compte();
        }
    });

    function afficher_nouveau_compte()
    { new Ajax.Request
      ( site_root + "index.php/jcatalog/login/register",
        { method: "post",
          parameters: {},
          onComplete: function(transport)
          { var response = eval('(' + transport.responseText + ')');
            var html = response["html"];
            jQuery(".bloc_content").append("<div class='bloc_content_white' id='compte_nouveau_div'> </div>");
            afficher_masque();
            var container = jQuery(".bloc_content > #compte_nouveau_div");
            container.append(html);
            container.fadeIn(500);    
            container.animate({height: "313"}, 400);
          }
        }
      );
    }

    function cacher_nouveau_compte(){
         var container = jQuery(".bloc_content > #compte_nouveau_div");
         container.animate({
             height: "0"
         }, 400,function(){
            jQuery("#compte_nouveau_div").detach();
        });
    }    
    //  **********  BLOCS End  **********
    
    //  -----  PAGE PRODUIT : affichage de type Lightbax  -----
    jQuery("#page_product_image a").fancybox();    
    
    //  -----  Comportements sp�cifiques : Mini panier  -----
    jQuery(".moins").live("mouseover", function() {
        jQuery(this).attr("src", "" + site_root + "skin/frontend/default/lunedemiel/images/products_mini_panier_moins_hover.png");
    });
    jQuery(".moins").live("mouseout", function() {
        jQuery(this).attr("src", "" + site_root + "skin/frontend/default/lunedemiel/images/products_mini_panier_moins.png");
    });
    jQuery(".plus").live("mouseover", function() {
        jQuery(this).attr("src", "" + site_root + "skin/frontend/default/lunedemiel/images/products_mini_panier_plus_hover.png");
    });
    jQuery(".plus").live("mouseout", function() {
        jQuery(this).attr("src", "" + site_root + "skin/frontend/default/lunedemiel/images/products_mini_panier_plus.png");
    });

    return this;
}

// -----  BIBLIOTHEQUES  -----
jQuery.preloadCssImages = function() {

    var sheets = document.styleSheets,
        styles = [],    //array of CSS rules
        imgs   = [],    //array of images path as they appear in CSS
        hrefs  = [],    //array of styleSheets href
        url    = '/';   //full path to imgs

    if (!sheets) return;

    jQuery(sheets).each(function(){
        var mediaText = typeof this.media.mediaText !== 'undefined' ? this.media.mediaText : this.media;
        if ( mediaText.indexOf('screen') == -1 ) return 0;
        feedStylesArray( this );
    });

    if (hrefs.length) {
        hrefs = removeDuplicates(hrefs);
        url = hrefs[0].split('/');
        url.pop();
        url = url.join('/') || window.location.href;
        if ( url.charAt(url.length - 1) !== '/' ) url += '/';//FireFox need this
    }

    if (styles.length) {
        imgs = jQuery.grep( styles, function (rule) { return rule.match(/(gif|jpg|jpeg|png)/g); });
        imgs = imgs.join(',');
        imgs = imgs.match(/[^\(("|')?]+\.(gif|jpg|jpeg|png)/g);
        imgs = jQuery.makeArray(imgs);
        // can't use "unique" on non DOM elements http://dev.jquery.com/ticket/1747
        imgs = removeDuplicates(imgs);
    }

    if (imgs.length) {
        createImgObjects(imgs);
    }

    return;
    
    function feedStylesArray( styleSheet ) {
        
        if ( styleSheet.href ) hrefs.push( styleSheet.href );
        
        if ( typeof styleSheet.cssRules !== 'undefined' ) {
            // do it the W3 way
            jQuery.each( styleSheet.cssRules,
                function() {
                    if (this.type === 1) {
                        styles.push( this.cssText );
                    }
                    else if (this.type === 3) {
                        // recurse through @import rules
                        feedStylesArray( this.styleSheet );
                    }
                }
            );
        }
        else {
            // do it the IE way
            jQuery(styleSheet.rules).each(function(){
                if (this.style)
                    styles.push( this.style.cssText.toLowerCase() );
            });
            // recurse through @import rules
            if(styleSheet.imports) {
                jQuery(styleSheet.imports).each(function(){
                    feedStylesArray(this);
                });
            }
        }
    }

    function removeDuplicates( array ) {
        var ret = [],
        done = {};
        try {
            for (var i = 0, length = array.length; i < length; i++) {
                var id = array[i];
                if (!done[id]) {
                    done[id] = true;
                    ret.push(array[i]);
                }
            }
        } catch(e) {
            ret = array;
        }
        return ret;
    }

    function createImgObjects( array ) {
        jQuery(array).each(function(){
            var img = new Image();
            $(img).attr('src', (this=='/' || !!this.match('http://')) ? this : url+this );
        });
    }

};

jQuery.fn.extend({
       findPos : function() {
           obj = jQuery(this).get(0);
           var curleft = obj.offsetLeft || 0;
           var curtop = obj.offsetTop || 0;
           while (obj = obj.offsetParent) {
                    curleft += obj.offsetLeft;
                    curtop += obj.offsetTop;
           }
           return {x:curleft,y:curtop};
           }
    });


// ---------------------------------------- SIMTIC : ajout fonctions

  function maj_cart()
  { lunedemiel.cacher_panier();
    jQuery("#header_compte").css("z-index", 4);
    jQuery("#header_panier").css("z-index", 11);
    lunedemiel.afficher_masque();
    jQuery("#masque").fadeIn(500);
    var form_inputs = {};
    jQuery("#cart_form").find("input").each
    ( function()
      { if(this.type == "text") form_inputs[this.name] = this.value;
        else
        { if(this.type == "checkbox")
          { if(this.checked) form_inputs[this.name] = this.value;
          }
        }
      }
    );
    jQuery("#main_loading").css("display", "block");
    new Ajax.Request
    ( site_root + "index.php/jcatalog/cart/update",
      { method: "post",
        parameters: form_inputs,
        onComplete: function(transport)
        { jQuery("#main_loading").css("display", "none");
          var response = eval('(' + transport.responseText + ')');
          var html = response["html"];
          jQuery("#main").append(html);
          jQuery("#home_panier").fadeIn(500);
          var container = jQuery("div.bloc_content > div.bloc_content_white");
          container.get(0).style.height = "auto";
          if(typeof(response["cart_count"]) != "undefined") maj_cart_count(response["cart_count"]);
        }
      }
    );
  }

  function add_product(i)
  { var form_inputs = {};
    jQuery("#product_atc_form_" + i).find("input").each
    ( function()
      { if(this.name.length > 0)
        { form_inputs[this.name] = this.value;
        }
      }
    );
    jQuery("#product_atc_form_" + i).find("select").each
    ( function()
      { if(this.name.length > 0)
        { form_inputs[this.name] = this.value;
        }
        form_inputs[this.name] = this.value;
      }
    );
    if(document.getElementById("home_panier")) lunedemiel.cacher_panier();
    jQuery("#header_compte").css("z-index", 4);
    jQuery("#header_panier").css("z-index", 11);
    lunedemiel.afficher_masque();
    jQuery("#masque").fadeIn(500);
    document.location.href = "#main";
    jQuery("#main_loading").css("display", "block");
    new Ajax.Request
    ( site_root + "index.php/jcatalog/cart/add",
      { method: "post",
        parameters: form_inputs,
        onComplete: function(transport)
        { var response = eval('(' + transport.responseText + ')');
          jQuery("#main_loading").css("display", "none");
          if(typeof(response["redirect"]) == "undefined")
          { var html = response["html"];
		    jQuery("#main").append(html);
            jQuery("#home_panier").fadeIn(500);
            var container = jQuery("div.bloc_content > div.bloc_content_white");
            container.get(0).style.height = "auto";
            if(typeof(response["cart_count"]) != "undefined") maj_cart_count(response["cart_count"]);
          }
          else document.location.href = response["redirect"];
        }
      }
    );
  }


  function ajouterPan(produit, quantite)
  { var form_inputs = {product: produit, qty: quantite};
    if(document.getElementById("home_panier")) lunedemiel.cacher_panier();
    jQuery("#header_compte").css("z-index", 4);
    jQuery("#header_panier").css("z-index", 11);
    lunedemiel.afficher_masque();
    jQuery("#masque").fadeIn(500);
    document.location.href = "#main";
    jQuery("#main_loading").css("display", "block");
    new Ajax.Request
    ( site_root + "index.php/jcatalog/cart/add",
      { method: "post",
        parameters: form_inputs,
        onComplete: function(transport)
        { var response = eval('(' + transport.responseText + ')');
          jQuery("#main_loading").css("display", "none");
          if(typeof(response["redirect"]) == "undefined")
          { var html = response["html"];
		    jQuery("#main").append(html);
            jQuery("#home_panier").fadeIn(500);
            var container = jQuery("div.bloc_content > div.bloc_content_white");
            container.get(0).style.height = "auto";
            if(typeof(response["cart_count"]) != "undefined") maj_cart_count(response["cart_count"]);
          }
          else document.location.href = response["redirect"];
        }
      }
    );
  }

