/*
 * jQuery hashchange event - v1.3 - 7/21/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 *
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);

_m_jQ = jQuery.noConflict();

_m_jQ(document).ready(function(){
    var q=true;
    var o=true;
    var h="";
    var f="";
    
    function p(i){
      window.reload_nav=i
    } 
    function d(){
      return window.reload_nav
    }    
    function t(i){
      window.reload_compare=i
    }
    function n(){
      return window.reload_compare
    }
    function b(i){
      window.cartDeleteText=i
    }
        
    p(true);
    t(true);
    
    var e=location.hash.slice(1);
    if(e!=""){
      s()
    }
        
     _m_jQ(window).hashchange(function(i){
       s()
     });
        
        
    function r(){
        min_price=0;
        max_price=parseInt(_m_jQ("input#price_maximum").val());
        step_val=_m_jQ("input#step_value").val();
        step_val=parseInt(step_val);
        _m_jQ("#slider-range-price").slider({
            range:true,
            min:0,
            max:max_price,
            step:step_val,
            values:[_m_jQ("#init_price_minimum").val(),_m_jQ("#init_price_maximum").val()],
            slide:function(j,i){
                _m_jQ("input#price_maximum").val(_m_jQ("#slider-range-price").slider("values",1));
                _m_jQ("input#price_minimum").val(_m_jQ("#slider-range-price").slider("values",0))
                },
            change:function(j,i){
                _m_jQ("input#price_maximum").val(_m_jQ("#slider-range-price").slider("values",1));
                _m_jQ("input#price_minimum").val(_m_jQ("#slider-range-price").slider("values",0));
                new_url=g(_m_jQ("#price_slider_url").val())+"&price="+_m_jQ("#slider-range-price").slider("values",0)+","+_m_jQ("#slider-range-price").slider("values",1);
                p(true);
                t(false);
                window.location.hash=c(new_url)
                }
            });
      _m_jQ("input#price_maximum").val(_m_jQ("#slider-range-price").slider("values",1));
      _m_jQ("input#price_minimum").val(_m_jQ("#slider-range-price").slider("values",0))
    }
    
    r();
   
   
    
_m_jQ(".pager select, .toolbar select").live("change",function(){
    /*p(true);
    t(true);*/
    p(true);
    t(false);
    
    window.location.hash=c(_m_jQ(this).val());
    return false
    });
    
   /* ici on trouve la fonction au clic de page */ 
_m_jQ(".pager a, .toolbar a").live("click",function(){
    /*p(false);
    t(false);*/
    
    p(true);
    t(false);

    window.location.hash=c(_m_jQ(this).attr("href"));
    return false
    });
    
    
_m_jQ(".block-layered-nav #narrow-by-list a, .block-layered-nav .currently a, .block-layered-nav .actions a").live("click",function(){
    p(true);
    t(true);
    if(_m_jQ(this).attr("id")=="price-filter-button"){
        step_val=parseInt(_m_jQ("input#step_value").val());
        request_price_min=Math.floor(_m_jQ("#price_minimum").val()/step_val)*step_val;
        request_price_max=Math.ceil(_m_jQ("#price_maximum").val()/step_val)*step_val;
        new_url=g(_m_jQ("#price_slider_url").val())+"&price="+request_price_min+","+request_price_max;
        window.location.hash=c(new_url)
        }else{
        window.location.hash=c(_m_jQ(this).attr("href"))
        }
        return false
    });
    
    
_m_jQ(".col-main .add-to-links a.link-compare").live("click",function(){
    p(false);
    t(true);
    a(_m_jQ(this).attr("href"),false,true);
    return false
    });
    
_m_jQ(".block.block-compare a.btn-remove, .block.block-compare .actions a").live("click",function(){
    p(false);
    t(true);
    a(_m_jQ(this).attr("href"),false,true);
    return false
    });
       
_m_jQ("#price_minimum, #price_maximum").live("keyup",function(i){
    if(i.keyCode==13){
        _m_jQ("#price-filter-button").click()
        }
    });
    
    
function s(){
    var i=location.hash.slice(1);
    path=window.location.href;
    path=path.split("#")[0];
    path=path.split("?")[0];
    path=g(path+"?"+i);
    nv=d();
    cm=n();
    a(path,nv,cm,false);
    p(true);
    t(true)
}

function a(l,k,j,i){
    l=g(l);
    _m_jQ(".col-main").append('<div class="products-list-loader"><div></div></div>');
    if(k){
        _m_jQ(".block-layered-nav").append('<div class="products-list-loader"><div></div></div>')
        }
        _m_jQ.get(l,{},function(u,m,w){
        if(m=="error"){
            _m_jQ(".col-main").html("<p>There was an error making the AJAX request</p>")
            }else{
            var v=_m_jQ("<div />").html(u);
            _m_jQ(".col-main").html(v.find(".col-main").html());
            if(k){
                _m_jQ(".block-layered-nav").html(v.find(".block-layered-nav").html());
                r()
                }
                if(j){
                _m_jQ(".block-compare").html(v.find(".block-compare").html())
                }
                if(i){
                _m_jQ(".block-cart").html(v.find(".block-cart").html())
                }
                if(typeof(window.ajaxproload)=="function"){
                ajaxproload()
                }
            }
    })
}

function g(i){
    if(i.indexOf("ajax=1")<0){
        if(i.indexOf("?")<0){
            i=i+"?ajax=1"
            }else{
            i=i+"&ajax=1"
            }
        }
    return i
}
function c(j){
    j.match(/\?(.+)$/);
    var i=RegExp.$1;
    if(i.indexOf("ajax=1")>=0){
        i=i.replace("ajax=1&","");
        i=i.replace("&ajax=1","");
        i=i.replace("ajax=1","")
        }
        return i
    }
    _m_jQ("#products-list button.btn-cart").live("click",function(){
    a(_m_jQ(this).attr("rel"),false,false,true);
    return false
    })
});

