  MeerShopsCollapsed = 0;
  MandjeCollapsed    = 0;
  MaxProductsPerCart = 10;
  MeerShopsLast      = 7;
  MeerShopsActive    = 0;
  CurrentCarouselAt  = -1;
  CarouselTimeOut    = null;
  myVote             = -1;
  numVotes           = -1;
  fading             = 0;
  fW                 = 900;
  fH                 = 600;
  shopId             = 0;
  revertPGOA         = null;
  orgh               = 0;
  prod               = '';
  version            = '2.3.29';
  perrorbarstatus    = 0;
  max_use_voorraad   = -1;
  jquery_loaded      = 0;
  
  function InitMeerShops(){
    if($("div#container-shopbrowser a.shop").size() > 8){
      $("div#container-shopbrowser a.links").show().click(function(){SwapMeerShops('links');});
      $("div#container-shopbrowser a.rechts").show().click(function(){SwapMeerShops('rechts');});
    }
    $("div#container-shopbrowser a.shop").each(function(a){
      if(a < 8){
        $(this).show();
      }
    });
  }
  
  function SwapMeerShops(richting){
    $("#shopblocks").stop().animate({'opacity' : '0', 'top' : '100px'}, 300, function(){
      //$("#shopblocks").css({'top' : '-100px'});
      MeerShopsActive = 0;
      if(richting == 'links'){
        if(MeerShopsLast-7 > 0){
          $("div#container-shopbrowser a.shop").each(function(a){
            $(this).hide();
            if(a < MeerShopsLast-7 && a > (MeerShopsLast-16)){
              $(this).show();
              MeerShopsActive--;
              lastShop = a;
            }
          });
          MeerShopsLast = lastShop;
        }else{
          $("div#container-shopbrowser a.shop").each(function(a){
            if(! $(this).is(":hidden")){
              $(this).hide();
            }          
          });
        }
        if(MeerShopsActive+8 < 1){
          // Er is nog meer, dus OK!
        }else{
          // Geen 8, begin van de array
          shopRemainder = (MeerShopsActive+8);
          $("div#container-shopbrowser a.shop").each(function(a){
            if(a >= ($("div#container-shopbrowser a.shop").size()-shopRemainder)){
              $(this).show();
              lastShop = a;
            }
          });
          MeerShopsLast = lastShop+(8-shopRemainder);
        }
        $("#shopblocks").animate({'opacity' : '1', 'top' : '0px'}, 300);
      }else{
        $("div#container-shopbrowser a.shop").each(function(a){
          if(! $(this).is(":hidden")){
            $(this).hide();
          }          
          if(a > MeerShopsLast && a <= (MeerShopsLast+8)){
            $(this).show();
            MeerShopsActive++;
            lastShop = a;
          }
        });
        MeerShopsLast = lastShop;
        if(lastShop + 1 < $("div#container-shopbrowser a.shop").size()){
          // Er is nog meer, dus OK!
        }else{
          // Geen 8, einde van de array
          shopRemainder = 8-MeerShopsActive;
          $("div#container-shopbrowser a.shop").each(function(a){
            if(a < shopRemainder){
              $(this).show();
              lastShop = a;
            }
          });
          MeerShopsLast = lastShop;
        }
        $("#shopblocks").animate({'opacity' : '1', 'top' : '0px'}, 300);
      }
    });
  }

  function CartInit(){
    if($("div#productenlijst ul").size() > 0){
      UpdateCartLabel();
      $("#winkelmandje").css({'background-position' : '-468px 0px'});
      $("#winkelmandje a").attr('href', 'javascript:niets();');

      $("#winkelmandje").css({'cursor' : 'pointer'});
      $("div#productenlijst ul li.col3 a").unbind('click');
      $("div#productenlijst ul li.col3 a").click(function(){
        DeleteFromCart($(this).parent());
      });
      
      if($("div#productenlijst ul").size() > MaxProductsPerCart){
        $("#meerproducten").show();
        $("div#productenlijst ul").each(function(a,b){
          if(a >= MaxProductsPerCart){
            $(this).hide();
          }
        });
      }
    }
  }

  function CollapseMandje(rm){    
    if(MandjeCollapsed < 1){
      $("div#wkw-striptop").show();
      $("#overlay").css({'z-index' : '20', 'opacity' : '0', 'filter' : 'alpha(opacity=0)'}).show();
      MandjeCollapsed = 1;
      $("#winkelmandje-fix").show().animate({'top' : '0px'}, 400, function(){
        if(rm < 1){
          $("#winkelmandje").css({'background-position' : '-234px 0px'});
        }
      });
      $("#overlay, div#wkw-striptop").click(function(){
        MandjeCollapsed = 1;
        CollapseMandje(0);
        $("#overlay, div#wkw-striptop").unbind('click');
      });
    }else{
      $("#overlay").css({'z-index' : '980', 'opacity' : '.6', 'filter' : 'alpha(opacity=60)'}).hide();
      MandjeCollapsed = 0;
      if($("div#productenlijst ul").size() > 0){
        $("#winkelmandje-fix").animate({'top' : '-250px'}, 300, function(){
          if(rm < 1)
          {
            $("#winkelmandje").css({'background-position' : '-468px 0px'});
          }
          $("div#wkw-striptop").hide();
        });
      }else{
        $("#winkelmandje-fix").animate({'top' : '-250px'}, 300, function(){
          $("div#wkw-striptop").hide();
        });
      }
    }
  }

  function CollapseMeerShops(){
    if(MeerShopsCollapsed < 1){
      $("#shopbrowser-meer").css({'background-image' : 'url(/images/pijltje-down.png)', 'background-position' : 'center 4px'});
      $("#shopbrowser").animate({bottom: '0px', 'opacity' : '1', 'filter' : 'alpha(opacity=100)'}, 200);
      MeerShopsCollapsed = 1;
    }else{
      $("#shopbrowser-meer").css({'background-image' : 'url(/images/pijltje-up.png)', 'background-position' : 'center 5px'});
      $("#shopbrowser").animate({bottom: '-200px', 'opacity' : '.85', 'filter' : 'alpha(opacity=85)'}, 350);
      MeerShopsCollapsed = 0;
    }
  }
  
  function DeleteFromCart(a){
    var rmprod = 0;
    rmprod = a.parent().parent().find("ul").index(a.parent());
    $.post('/simple_ajax.php', {'rmprod' : rmprod }, function(d){
      // alert(d.r);
    }, "json");
    $(a).parent().remove();
    if($("div#productenlijst ul").size() >= MaxProductsPerCart){
      $("#meerproducten").show();
      $("div#productenlijst ul").each(function(a,b){
        if(a+1 == MaxProductsPerCart){
          $(this).show();
        }
      });
    }else{
      $("#meerproducten").hide();
    }
    if($("div#productenlijst ul").size() < 1){
      CollapseMandje(0);
      LeegMandje();
    }
    $("#winkelmandje-content").hide().show();
    UpdateCartLabel();
  }
  
  function MandjeClickable(){
    if($("div#productenlijst ul").size() > 0){
      $("#winkelmandje").unbind('click');
      $("#winkelmandje").click(function(){
        CollapseMandje(0);
      });
    }
  }
  
  function LeegMandje(){
    $("#winkelmandje").css({'background-position' : '0px 0px'});
    $("#winkelmandje").unbind('click');
    $("#winkelmandje").css({'cursor' : 'default'});
  }
  
  function UpdateCartLabel(){
    if($("div#productenlijst ul").size() > 0){
      if($("div#productenlijst ul").size() == 1){
        $("#winkelmandje a").html('<b>1 ' + (l('product')) + '</b>');
      }else{
        $("#winkelmandje a").html('<b>' + $("div#productenlijst ul").size() + ' ' + (l('producten')) + '</b>');
      }
      var totaalprijs = 0;
      
      $("div#productenlijst ul").each(function(a,b){
        var aantal = parseInt($(this).children().eq(0).html());
        var prijs  = parseFloat($(this).children().eq(3).html());
        totaalprijs += aantal * prijs;
      });
      
      totaalprijs = number_format(totaalprijs, 2, ',', '.');
      
      $("#winkelmandje a").append(' <small>(' + l('currencyhtml') + '' + totaalprijs + ')</small>');
    }else{
      $("#winkelmandje a").html('<b>' + ucfirst(l('winkelmandje')) + '</b>');
    }
  }
  
  function ucfirst(str) {
    str += '';
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1);
  }
  
  function l(label){
    if(shoplang[label]){
      return shoplang[label];
    }else{
      return '#lang_err#';
    }
  }
  
  function number_format( number, decimals, dec_point, thousands_sep ) {
    var n = number, prec = decimals;
    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
    var sep = (typeof thousands_sep == "undefined") ? ',' : thousands_sep;
    var dec = (typeof dec_point == "undefined") ? '.' : dec_point;
    var s = (prec > 0) ? n.toFixed(prec) : Math.round(n).toFixed(prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
    var abs = Math.abs(n).toFixed(prec);
    var _, i;
    if (abs >= 1000) {
      _ = abs.split(/\D/);
      i = _[0].length % 3 || 3;
      _[0] = s.slice(0,i + (n < 0)) +
        _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
      s = _.join(dec);
    }else{ s = s.replace('.', dec); }
    return s;
  }
  
  $(document).ready(function(){
    jquery_loaded = 1;
    
    fW = $(window).width()-100;
    fH = $(window).height()-100;

    CartInit();
    MandjeClickable();
    
    $("#shopbrowser").css({'bottom' : '-200px'});
    $("#shopbrowser-meer").click(function(){
      CollapseMeerShops();
    });
    
    $("div#leegmaken").hover(function(){$("div#leegmaken div.button-bg").addClass('button-bg-hover');},function(){$("div#leegmaken div.button-bg").removeClass('button-bg-hover');});
    $("div#checkout").hover(function(){$("div#checkout div.button-bg").addClass('button-bg-hover');},function(){$("div#checkout div.button-bg").removeClass('button-bg-hover');});
    
    
    $(".activator").each(function(a){      
    /*
      $(this).click(function(){
        $(this).effect('transfer', { to: "#winkelmandje", className: 'ui-effects-transfer' }, 650, function(){
          $("#meerproducten").before('<ul class="product"><li class="col1">100x</li><li class="col2">XXXX</li><li class="col3"><a class="delete" href="#"></a></li><li class="prijs">2</li></ul>');
          CartInit();
          MandjeClickable();
        });
      });
    */
      $(this).mouseover(function(){
        $(this).parent().addClass("product-bg-hover");
      }).mouseout(function(){
        $(this).parent().removeClass("product-bg-hover");
      });
    });
    
    setTimeout(function(){void(0);InitMeerShops();}, 100);
    
    if($("#carousell").size() > 0){
      $("#carousell").jqGalScroll();
      SwapTo();
    }
    
    $("#submenu li .hassub").each(function(){
      $(this).attr('href', 'javascript:menu();');
      addMenuClick($(this));
    });

    $("ul#submenu li ul.submenu-uitklap li.hasinner>a").each(function(){
      $(this).attr('href', 'javascript:menu();');
      addSubMenuClick($(this));
    });
    
    $("img.vlaggetje").each(function(a,b){
      $(this).parent().attr('alt', $(this).parent().attr('title'));
      $(this).parent().removeAttr('title');
      $(this).tooltip({
        track: true,
        delay: 0,
        showURL: false,
        top: -25,
        left: -2,
        positionLeft: true,
        bodyHandler: function() { 
          return '<div class="tt_left"><img src="/images/tooltip_left.png" /></div><div class="tt_main">' + $(b).parent().attr('alt') + '</div><div class="tt_right"><img src="/images/tooltip_right.png" /></div>'; 
        }
      });
    });
    
    $("img.tooltip").each(function(a,b){
      $(this).parent().attr('alt', $(this).parent().attr('title'));
      $(this).parent().removeAttr('title');
      $(this).tooltip({
        track: true,
        delay: 0,
        showURL: false,
        top: -31,
        left: 65,
        positionLeft: true,
        bodyHandler: function() { 
          return '<div class="tt_left"><img src="/images/tooltip_left.png" /></div><div class="tt_main">' + $(b).parent().attr('alt') + '</div><div class="tt_right"><img src="/images/tooltip_right.png" /></div>'; 
        }
      });
    });

    $("img.vlaggetjeAD").each(function(a,b){
      var c = $(this).attr('title');
      $(this).tooltip({
        track: true,
        delay: 0,
        showURL: false,
        top: -37,
        left: 5,
        bodyHandler: function() { 
          return '<div style="white-space: nowrap; padding: 2px; border: 1px solid #000; background-color: #fff; opacity: .88; filter:alpha(opacity=88); ">' + c + '</div>'; 
        }
      });
    });
    
    $("div.plaatsinwinkelwagen a").hover(function(){
      $("div.plaatsinwinkelwagen-bg").addClass('plaatsinwinkelwagen-bg-hover');
    }, function(){
      $("div.plaatsinwinkelwagen-bg").removeClass('plaatsinwinkelwagen-bg-hover');
    });
    
    $("div.product-bg a").hover(function(){
      $(this).parent().addClass('product-bg-hover');
    }, function(){
      $(this).parent().removeClass('product-bg-hover');
    });
    
    if($("#myVote").val() > 0) myVote = $("#myVote").val();
    
    $("#rating a").removeAttr('href').each(function(a,b){
      $(this).hover(function(){
        if(numVotes < 0) numVotes = $("#rating a img.geel").size();
        for(i=0;i<a+1;i++){
          $("#rating a img:eq(" + i + ")").attr('src', '/images/rating-oranje.png');
        }
        for(i=a+1;i<5;i++){
          $("#rating a img:eq(" + i + ")").attr('src', '/images/rating-wit.png');
        }
      }, function(){
        if(myVote < 0){
          for(i=0;i<5;i++){
            vColor = 'wit';
            if(i < numVotes) vColor = 'geel';
            $("#rating a img:eq(" + i + ")").attr('src', '/images/rating-' + vColor + '.png');
          }
        }else{
          for(i=0;i<5;i++){
            vColor = 'wit';
            if(i < myVote) vColor = 'oranje';
            $("#rating a img:eq(" + i + ")").attr('src', '/images/rating-' + vColor + '.png');
          }          
        }
      }).click(function(){
        myVote = a+1;
        // Ajaxcall Rate
        theProduct = $("#productNo").val();
        $.post('/simple_ajax.php', { rating : myVote, product : theProduct }, function(data){
          // alert(data.r);
        }, "json");
      });
    });
    
    big = null;
    
    $("#zoomer").mousemove(function(e){
//      if(fading < 1){
//        $("#pics img.big").show();
//        $("#pics img.normal").hide();
//      }
      pad  = 15;
      var pos = $(this).offset();
      posl = parseInt(pos.left);
      post = parseInt(pos.top);
      x    = e.pageX-posl;
      y    = e.pageY-post;
      w    = $(this).width();
      h    = $(this).height();
      if(x < pad) x = pad;
      if(y < pad) y = pad;
      if(x > w-pad) x = w-pad;
      if(y > h-pad) y = h-pad;
      x    = x-pad;
      y    = y-pad;
      fX = Math.ceil(x / (w-(pad*2)) * 100);
      fY = Math.ceil(y / (h-(pad*2)) * 100);
      $(big).css({'margin-left' : '-' + fX + '%', 'margin-top' : '-' + fY + '%'})
    }).hover(function(){
      big  = $("#pics img.big");
      if(fading < 1){
        $("#pics img.big").show();
        $("#pics img.normal").hide();
      }
    }, function(){
      $("#pics img.normal").show();
      $("#pics img.big").hide();
    });
    
    if($("img.normal").length > 0){
      if($("img.big").length == 1 && $("img.normal").length == 1){
        $("#zoomer").show();
      }else{
        if($("div.pbrowser.show .big").length > 0){
          $("#zoomer").show();
        }
        $("#nav a").removeAttr('href').css({'cursor' : 'pointer'});
        $("#nav a#nav-prev.none").css({'cursor' : 'default'});
        $("#nav a#nav-next.none").css({'cursor' : 'default'});
        
        $("#nav a#nav-next").click(function(){
          if($("div.pbrowser.show").next().length > 0){
            if(fading < 1){
              fading = 1;
              $("div.pbrowser.show").next().show().find(".normal").hide().fadeIn("slow", function(){
                $("div.pbrowser.show").hide();
                $("div.pbrowser.show").removeClass('show').next().addClass('show');
                fading = 0;
                if($("div.pbrowser.show .big").length > 0){
                  $("#zoomer").show();
                }else{
                  $("#zoomer").hide();
                }
              });
              if($("div.pbrowser.show").next().next().length < 1){
                $("#nav-next").addClass("none").css({'cursor' : 'default'});
              }
              if($("div.pbrowser.show").length > 0){
                $("#nav-prev").removeClass("none").css({'cursor' : 'pointer'});
              }
            }
          }
        });
        $("#nav a#nav-prev").click(function(){
          if($("div.pbrowser.show").prev().length > 0){
            if(fading < 1){
              fading = 1;
              $("div.pbrowser.show").prev().show().next().find(".normal").fadeOut("slow", function(){
                $(this).parent().hide().removeClass("show").prev().addClass("show");
                fading = 0;
                if($("div.pbrowser.show .big").length > 0){
                  $("#zoomer").show();
                }else{
                  $("#zoomer").hide();
                }
              });
              if($("div.pbrowser.show").length > 0){
                $("#nav-next").removeClass("none").css({'cursor' : 'pointer'});
              }
              if($("div.pbrowser.show").prev().prev().length < 1){
                $("#nav-prev").addClass("none").css({'cursor' : 'default'});
              }
            }
          }
        });       
      }
    }
    
    $(".zoeken-knop").click(function(){
      $(this).hide();
      $("#searchloader").css({'margin-left' : '193px'});
    });
    
    if($("#colorpicker").length > 0)
    {
      var colorpicker = $.farbtastic("#colorpicker");
      $("#colorpicker").css({'opacity' : '0', 'filter' : 'alpha(opacity=0)'}).css({'display' : 'none'});
      $('.colorwell').focus(function(){
        $(this).css({'border-color' : '#000000'});
        $('#colorpicker').stop().css({'display' : 'block'}).animate({'opacity' : '1', 'filter' : 'alpha(opacity=100)'});
        colorpicker.linkTo(this);
      }).blur(function(){
      
      });
  
      $('.colorwell').each(function(){
        colorpicker.linkTo(this);
      });
      
      $("#switchcolors").removeAttr('href').addClass('pointer').click(function(){
        styleswitch(0,($('.colorwell:eq(0)').val()).substr(1),($('.colorwell:eq(1)').val()).substr(1),($('.colorwell:eq(2)').val()).substr(1),($('.colorwell:eq(3)').val()).substr(1));
      });
    }
    
    $("#carslnonjs").hide();
    $("#carsljs").show();
    
    $("div#faq fieldset div.content").hide();
    
    $("div#faq fieldset legend a").removeAttr('href');
    $("div#faq fieldset legend a").click(function(){
      $(this).parent().parent().find("div.content").slideToggle();
    });
    
    $("#bestel-content #sluiten").click(function(){
      $("#overlay-content").fadeOut(function(){
        $("#overlay").fadeOut();
      });
    });
    
    $("a button").click(function(){
      if($(this).parent().attr('href'))
      {
        document.location.href = $(this).parent().attr('href');
      }
    });
    
    $("a.iframe").fancybox({'width' : 625,'height' : 400, 'type' : 'iframe'});
    $("a.cartiframe").fancybox({'width' : 645,'height' : 400, 'type' : 'iframe' });
    
    $(".iframeWindow").fancybox({'width' : fW,'height' : fH, 'type' : 'iframe'});
    
    $("div#leegmaken a").click(function(){
      confirmClearCart();
    });
    
    $(".winkelwagen-content img.collapseimg").click(function(){
      $(this).parent().parent().find(".winkelwagen-beschrijving-extrainfo").slideToggle("fast");
    });

    $(".functies #leegmaken, .incartclearcart").click(function(){
      confirmClearCartS100();
    });
    $(".functies #printen").click(function(){
      printS();
    });
    
    $("div.winkelwagen-footer div#winkelwagen-nav div#volgende a").hover(function(){
      $("div.winkelwagen-footer div#winkelwagen-nav div#volgende div.button-bg.notrans").addClass("button-bg-hover");
    }, function(){
      $("div.winkelwagen-footer div#winkelwagen-nav div#volgende div.button-bg.notrans").removeClass("button-bg-hover");
    });
    $("div.winkelwagen-footer div#winkelwagen-nav div#vorige a").hover(function(){
      $("div.winkelwagen-footer div#winkelwagen-nav div#vorige div.button-bg.notrans").addClass("button-bg-hover");
    }, function(){
      $("div.winkelwagen-footer div#winkelwagen-nav div#vorige div.button-bg.notrans").removeClass("button-bg-hover");
    });
    
    $("#addkcode").click(function(){
      var kc = trim($("#kcode").val());
      $("p.error").hide(100, function(){
        $(this).remove();  
      });
      $.post('/simple_ajax.php', { 'kcode': kc }, function(kdata){
        if(kdata.rcode == 1)
        {
          $(".button-bg-klein").hide();
          $("#kcodeform").slideUp('fast', function(){
            $(".winkelwagen-item-rij-korting").slideDown('fast');
            $("span#thecode").html(trim($("#kcode").val()));
          });
        }else{
          setTimeout(function(){
            $("#kortingscoupon").before('<p class="error hide">' + kdata.rtxt + '</p>').prev().slideDown('fast');
            $("#kcode").focus().select();
          }, 125);
        }
      }, 'json');
    });
    
    $("#kcodegooiweg").click(function(){
      $(".winkelwagen-item-rij-korting").slideUp('fast', function(){
        $("#kcodeform").slideDown('fast', function(){
          $(".button-bg-klein").show();
          $.post('/simple_ajax.php', { 'kcode': 'remove' }, function(kdata){}, 'json');
        });
      });
    });
    
    $(".winkelwagen-aantal span").css({'cursor' : 'pointer'}).click(function(){
      $(this).hide();
      $(this).prev().prev().prev().show().focus().select();
    });
    
    $(".winkelwagen-aantal input").keydown(function(event){
      if(event.keyCode == 13){
        $(this).blur();
        return false;
      }
    });
    
    $(".winkelwagen-aantal input").blur(function(){
      $(this).hide();
      $(this).next().next().next().html('<img src="/images/ajax-loader.gif" id="numloader" alt="" />');
      var hash = $(this).next().next().val();
      var aant = $(this).val();
      var prod = $(this).next().val();
      var stprijs = $(this).next().next().next().next().val();
      $.post('/simple_ajax.php', { 'hash' : hash, 'aantal' : aant, 'prod' : prod, 'stprijs' : stprijs }, function(r){
        $("#numloader").parent().html(r.r).parent().parent().find(".winkelwagen-totaal b").html(l('currencyhtml') + ' ' + r.c);
        $(".kassa span.bedrag-dik").html(l('currencyhtml') + ' ' + r.m);
        $(".kassa span.bedrag:eq(0)").html(l('currencyhtml') + ' ' + r.e);
        $(".kassa span.bedrag:eq(1)").html(l('currencyhtml') + ' ' + r.b);
        $("#winkelmandje a small").html(' (' + l('currencyhtml') + r.m + ')');
        var tPrm = r.m;
        tPrm = (tPrm.replace(/,/, ".") * 100);
        if(tPrm > $("#minordercent").val()-1)
        {
          $(".minorderbedrag").hide();
          $(".minorderbedrag2").show();
        }else{
          $(".minorderbedrag").show();
          $(".minorderbedrag2").hide();         
        }
        if(r.voorraadmod)
        {
          if(r.voorraadmod[0] > 0)
          {
            alert(l('artikelmaxvoorraad').replace(/%/, r.voorraadmod[1]));
          }
        }
      }, 'json');
      $(this).next().next().next().show();
    });
    
    $("#afhb").change(function(){
      $.post('/simple_ajax.php', { 'hybridvmethod' : $(this).val() }, function(r){
        $("#afhb").parent().parent().click();
      });
    });
    
    $("#bestelmethode li").click(function(){
      $("#bestelmethode li").removeClass("hover").addClass("semihidden");
      $(this).addClass("hover").removeClass("semihidden");
      var vmeth = $(this).find("input").val();
      $.post('/simple_ajax.php', { 'vmethod' : vmeth }, function(r){
        vmeth_enable = 1;
        
        if(vmeth == 1)
        {
          // alert('123');
          if($("#afhb").val() < 1)
          {
            vmeth_enable = 0;
          }else{
            //alert('submit');
          }
        }
        
        if(vmeth_enable > 0)
        {
          $(".winkelwagen-footer #volgende .button-bg").next().unbind('click');
          $(".winkelwagen-footer #volgende").removeClass("nocursor").addClass("pointer");
          $(".winkelwagen-footer #volgende .button-bg").removeClass("semitrans").addClass("notrans").next().attr('href','/s/102');
        }else{
          $(".winkelwagen-footer #volgende .button-bg").next().click(function(){
            //alert(l('hybridmnk'));
            if(perrorbarstatus < 1)
            {
              perrorbarstatus = 1;
              $.scrollTo($('h1'), 500, function(){
                $("#progresscontent").before('<p class="error">' + l('hybridmnk') + '</p>');
                $("p.error").hide().slideDown();
                setTimeout(function(){
                  $("p.error").slideUp(function(){
                    perrorbarstatus = 0;
                    $(this).remove();
                  });
                }, 5000);
              });
            }
          });
          $(".winkelwagen-footer #volgende .button-bg").next().removeAttr('href');
          $(".winkelwagen-footer #volgende .button-bg").removeClass("notrans").addClass("semitrans");
          $(".winkelwagen-footer #volgende").removeClass("pointer").addClass("nocursor");
        }
      }, 'json');
    });
    
    $("#bestelmethode li.firstclick").click();
    
    $("#NCOLPP").hide();
  
    animatingaddP = 0;
    
    $("#wwrijlmprodcontainer").hover(function(){
      if(animatingaddP < 1){
        animatingaddP = 1;
        $("#wwrijlsprod").slideUp('fast', function(){
          animatingaddM = 0;
        });
        $("#wwrijlmprod").slideDown('fast', function(){
          animatingaddP = 0;
        });
      }
    },function(){
      if(animatingaddP < 1){
        animatingaddP = 1;
        $("#wwrijlmprod").slideUp('fast', function(){
          animatingaddP = 0;
        });
      }
    });
    
    $("#wwrijlmprod").click(function(){
      document.location.href = '/s/100&addlma=true';
    });

    animatingaddM = 0;
    
    $("#wwrijlsprodcontainer").hover(function(){
      if(animatingaddM < 1){
        animatingaddM = 1;
        $("#wwrijlmprod").slideUp('fast', function(){
          animatingaddP = 0;
        });
        $("#wwrijlsprod").slideDown('fast', function(){
          animatingaddM = 0;
        });
      }
    },function(){
      if(animatingaddM < 1){
        animatingaddM = 1;
        $("#wwrijlsprod").slideUp('fast', function(){
          animatingaddM = 0;
        });
      }
    });
    
    $("#wwrijlsprod .winkelwagen-item-rij:last").addClass('noborder');
    
    $("#wwrijlsprod .winkelwagen-item-rij").click(function(){
      document.location.href = '/s/100&addxprod=' + $(this).find("input").val();
    });
    
    $("#productkleurmaatopties .kleuren img.hoverdeze").hover(function(){
      $(this).attr("src", "/images/prod-lijst-kleur_over.png");
    },function(){
      $(this).attr("src", "/images/prod-lijst-kleur.png");
    });
    
    // $("#productkleurmaatopties").fancybox({"width" : 645,"height" : 400, 'type' : 'iframe'});
    
    var chatDiv    = $("#chat-init");
    var chatTopPos = $(chatDiv).offset().top;

    var topChatSpc = $("#chat-init-above");
    var chatFixed  = $("#chat-fixed");
    
    $(window).scroll(function(){
      if($(window).scrollTop() >= chatTopPos-20)
      {
        $(chatDiv).css({'top' : '20px', 'position' : 'fixed' });
        chatFixed.show();
        topChatSpc.show();
      }else{
        if($(chatDiv).css('position') == 'fixed')
        {
          topChatSpc.hide();
          chatFixed.hide();
          $(chatDiv).css({'top' : '0px', 'position' : 'relative' });
        }
      }  
    });
    
    $("#alv").click(function(){
      window.open('/plugins/pdf-conditions', 'blank');
    });
    
    $(".plaatsinwinkelwagen.geenproductopties a").removeAttr('href').css({'cursor' : 'pointer'});
    
    $(".plaatsinwinkelwagen.geenproductopties").hover(function(){
      clearTimeout(revertPGOA);
      var curh = parseInt($(".no-opts-aantal").css('marginTop').replace(/px/, ''));
      if(orgh < 1) orgh = curh;
      $(".no-opts-aantal").stop().animate({'marginTop' : (orgh + 35) + 'px'}, 200);
    },function(){
      revert_ProductGeenOptiesAantal();
    });
    
    $(".no-opts-aantal").hover(function(){
      clearTimeout(revertPGOA);
    },function(){
      revert_ProductGeenOptiesAantal();
    });
    
	$(".no-opts-aantal .minder").click(function(){
      var newaant = $(".no-opts-aantal input#go-aantal").val();
      newaant = parseInt(newaant);
      if(newaant > 0 && newaant < 999) {}
      else {
          newaant = 1;
      }
      newaant = newaant-1;
      if(newaant < 1) newaant = 1;
      $(".no-opts-aantal input#go-aantal").val(newaant);
    });
	
	$(".no-opts-aantal .meer").click(function(){
      var newaant = $(".no-opts-aantal input#go-aantal").val();
      newaant = parseInt(newaant);
      if(newaant > 0 && newaant < 999) {}
      else {
          newaant = 1;
      }
      newaant = newaant+1;
      if(newaant > 999) newaant = 999;
      $(".no-opts-aantal input#go-aantal").val(newaant);
	});
    
    $(".no-opts-aantal a, .plaatsinwinkelwagen.geenproductopties a").click(function(){
      var newaant = $(".no-opts-aantal input#go-aantal").val();
      newaant = parseInt(newaant);
      if(newaant > 0 && newaant < 999) {}
      else {
        newaant = 1;
      }

      var params = {};
      params.aantal = newaant;
      
      if($(".s-optieveld").length > 0)
      {
        params.optie = $(".s-optieveld").val();
      }
      if($(".s-kleur").length > 0)
      {
        params.kleur = $(".s-kleur").val();
      }
      if(params.aantal && max_use_voorraad > -1 && max_use_voorraad < params.aantal)
      {
        alert(l('artikelmaxvoorraad').replace(/%/, max_use_voorraad));
        $(".no-opts-aantal input#go-aantal").val(max_use_voorraad);
      }else{
        $(".no-opts-aantal").stop().animate({'marginTop' : (orgh) + 'px'}, 150);
        iframeclose(1,newaant,parseFloat($("#prodprijs").val()),$("#productNo").val());
        $.post("/o/cart/" + $("#productNo").val(), params, function(d){}, 'json');
      }
    });

    if($(".bekeken.verwant").length > 0 && $(".bekeken.laatstbekeken").length < 1){
      $(".verwant").fadeIn();
    }

    if($(".bekeken.verwant").length > 0 && $(".bekeken.laatstbekeken").length > 0){
      $(".bekeken.verwant").prev().remove().prev().remove();
      $(".bekeken.laatstbekeken h2").html('<span class="vw">' + $(".bekeken.verwant h2").html() + '</span>' + '<span class="lb">' + $(".bekeken.laatstbekeken h2").html() + '</span>');
      $(".bekeken.verwant h2").remove();
      $(".bekeken.laatstbekeken div.prodcontainer").after($(".bekeken.verwant").html());
      $(".bekeken.verwant").remove();
      $(".bekeken.laatstbekeken h2 span:eq(1)").click(function(){
        $(this).css({ 'color' : '#000' });
        $(".bekeken.laatstbekeken h2 span:eq(0)").css({ 'color' : '#ccc' });
        $(".bekeken.laatstbekeken div.prodcontainer:eq(1)").fadeOut();
        $(".bekeken.laatstbekeken div.prodcontainer:eq(0)").fadeIn();
      });
      $(".bekeken.laatstbekeken h2 span:eq(0)").click(function(){
        $(this).css({ 'color' : '#000' });
        $(".bekeken.laatstbekeken h2 span:eq(1)").css({ 'color' : '#ccc' });
        $(".bekeken.laatstbekeken div.prodcontainer:eq(0)").fadeOut();
        $(".bekeken.laatstbekeken div.prodcontainer:eq(1)").fadeIn();
      });
    }
    
    $("span.inline-order-form input").click(function(){
      $(this).select();
    });
        
    $("span.inline-order-form img").click(function(){
      newaant = parseInt($(this).parent().find("input").val());
      if(newaant > 0 && newaant < 999) {}
      else {
        newaant = 1;
      }
      
      var params = {};
      params.aantal = newaant;

      if($(this).parent().find("input[name='kleur']").val().length > 0 && $(this).parent().find("input[name='kleur']").val() !== "")
      {
        params.kleur = $(this).parent().find("input[name='kleur']").val();
      }
      if($(this).parent().find("input[name='optie']").val().length > 0 && $(this).parent().find("input[name='optie']").val() !== "")
      {
        params.optie = $(this).parent().find("input[name='optie']").val();
      }

      $.post("/o/cart/" + $(this).parent().find("input").attr('name'), params, function(d){}, 'json');
      iframeclose(2,newaant,$(this).parent().parent().find(".prod-lijst-prijs").html().replace(/,/, "."),$(this).parent().find("input").attr('name'), this, $(this).parent().parent().find("a").html());
    });
    
    if($(".voorraadcheck-button").length > 0)
    {
      $.post('simple_ajax.php', { 'VoorraadAanwezig' : $("#artcode").val() }, function(d){
        //alert(d.voorraad);
        if(d.voorraad > 0)
        {
          $(".voorraadcheck-button").fadeOut('fast', function(){
            $(this).remove();
            $(".geenvoorraad-button").remove();
            $(".hidebutton").fadeIn('slow');
          });
        }else{
          $(".voorraadcheck-button").fadeOut('fast', function(){
            $(this).remove();
            $(".geenvoorraad-button").fadeIn('slow');
          });
        }
        max_use_voorraad = d.voorraad;
      }, 'json');
    }
    
    // EXIT
    
  });
  
  //$(window).bind('unload', function(){
  //  ___LeavePage();
  //});
  
  function revert_ProductGeenOptiesAantal()
  {
    clearTimeout(revertPGOA);
    revertPGOA = setTimeout(function(){
      $(".no-opts-aantal").stop().animate({'marginTop' : (orgh) + 'px'}, 200);
    }, 2000);
  }
  
  function confirmClearCartS100(){
    var answer = confirm(l('qsureclearcart'))
    if(answer){
      document.location.href = '/s/100&clearall=true';
      ___ClearCart();
    }
  }
  
  function confirmClearCart(){
    var answer = confirm(l('qsureclearcart'))
    if(answer){
      $.post('/simple_ajax.php', {'rmprod' : 'all' }, function(d){
        // alert(d.r);
      }, "json");
      CollapseMandje(1);
      //setTimeout(function(){
      $("div#productenlijst ul").remove();
      UpdateCartLabel();
      LeegMandje();
      ___ClearCart();
      //}, 500);
    }
  }

  function simpleclose()
  {
    //$("#fancy_close").click();
    //$.fancybox.close;
    //parent.$.fancybox.close;
    //setTimeout(function(){
      $("#fancybox-close").click();
    //}, 1000);
  }

  function iframeclose(fromcart,aantal,prijs,sprod,tobj,prodtitle)
  {
    if(aantal && max_use_voorraad > -1 && aantal > max_use_voorraad)
    {
      aantal = max_use_voorraad;
    }
    
    prod = sprod;
    //$("#fancy_close").click();
    //$("#fancybox-close").click();
    //$.fancybox.close;
    //parent.$.fancybox.close;
    simpleclose();
    
    if(fromcart > 0)
    {
      setTimeout(function(){
        toObj = '.plaatsinwinkelwagen';
        if(fromcart > 1)
        {
          toObj = $(tobj).parent().parent().find("a");
          var prodcont = prodtitle;
        }else{
          toObj = $(toObj);
          var prodcont = $('h1').html();
        }
        if(prodcont.length > 25)
        {
          prodcont = prodcont.substr(0, 25) + '...';
        }
        setTimeout(function(){
          toObj.effect('transfer', { to: "#winkelmandje", className: 'ui-effects-transfer' }, 750, function(){
            $("#meerproducten").before('<ul class="product"><li class="col1">' + aantal + 'x</li><li class="col2"><a href="/p/' + prod + '">' + prodcont + '</a></li><li class="col3"><a class="delete" href="javascript:niets();"></a></li><li class="prijs">' + (prijs) + '</li></ul>');
            ___ProductToCart(prod,aantal,prijs);
            CartInit();
            MandjeClickable();
          });
        },500);
      },100);
    }
  }

  function chatOffline()
  {
    $("#chat-init #linkchatmet").css({ 'background-image' : 'url(../images/status_busy.png)' } );
    $("#linkchatmet").html(l('chatoffline'));
    $("#chat-init").css({ 'cursor' : 'default !important' } );
    $("#chat-init img").css({ 'cursor' : 'default !important' } );
    $("#linkchatmet").unbind('click');
  }
  
  function chatOnline()
  {
    $("#chat-init #linkchatmet").css({ 'background-image' : 'url(../images/emoticon_smile.png)' } );
    $("#linkchatmet").html(l('chatmmdw'));
    $("#chat-init").css({ 'cursor' : 'pointer !important' } );
    $("#chat-init img").css({ 'cursor' : 'pointer !important' } );
    $("#linkchatmet").click(function(){
      enableOlarkChat();
      $(this).unbind('click');
    });
  }

  function enableOlarkChat()
  {
    if($("#chat-init").length > 0)
    {
      OlarkObj.set(1);
      
      $('html, body').animate({scrollTop:0}, 'slow');
      
      $("#chat-init").parent().slideUp(function(){
        $("#chat-init").parent().addClass('chat-active');
        $("#habla_window_div").addClass('showit');
        $("#chat-init").parent().slideDown(function(){
          $("textarea#habla_wcsend_input").focus();
        });
      });
    }
  }

  function quick_enableOlarkChat()
  {
    if($("#chat-init").length > 0)
    {
      //OlarkObj.set(1);
      //$('html, body').animate({scrollTop:0}, 1);
      $("div#imageabove").hide();
      $("#chat-init #linkchatmet").hide();
      $("#chat-init").parent().hide();
      $("#chat-init").parent().addClass('chat-active');
      $("#habla_window_div").addClass('showit');
      $("#chat-init").parent().show();
      $("textarea#habla_wcsend_input").focus();
    }
  }

  function styleswitch(restore,c1,c2,c3,c4){
    $("body").prepend('<div id="switchdiv" style="width: 100%; height: 100%; position: fixed; top: 0; left: 0; background-color: #000; z-index: 99999; display: none;"></div>');
    $("#switchdiv").fadeIn("slow", function(){
      if(restore < 1) $("#styleswap").attr('href', '/css/formatted.style.css.php?c1='+c1+'&c2='+c2+'&c3='+c3+'&c4='+c4);
      if(restore > 0) $("#styleswap").attr('href', '/css/formatted.style.css.php?restore=true');
      if($("#styleswapcustom").length > 0){
        if(restore < 1) $("#styleswapcustom").attr('href', '/graphics/' + shopId + '/custom_style.css.php?c1='+c1+'&c2='+c2+'&c3='+c3+'&c4='+c4);
        if(restore > 0) $("#styleswapcustom").attr('href', '/graphics/' + shopId + '/custom_style.css.php?restore=true');
      }
      rnd = new Date().getTime();
      if(restore < 1){
        clr = '&color=' + c2;
      }else{
        clr = '';
      }
      $("#searchloader img").load(function(){
        setTimeout(function(){
          $("#switchdiv").fadeOut("slow", function(){
            $(this).remove();
          });
        }, 500);
      }).attr('src', '/plugins/gif-loader/?clr_rld=' + rnd + clr + '&reload=' + restore);
    });
  }

  function menu(){}
  function niets(){}
  
  function addMenuClick(theObj){
    if(($(theObj).parent().attr('class')).match(/active/i) == null){
      $(theObj).click(function(){
        $(this).unbind('click');
        $(this).parent().addClass('active');
        $(this).addClass('active');
        addMenuClick($(this));
        $(this).next().css({'display' : 'block'});
      });
    }else{
      $(theObj).click(function(){
        $(this).unbind('click');
        $(this).parent().removeClass('active');
        $(this).removeClass('active');
        addMenuClick($(this));
        $(this).next().css({'display' : 'none'});
      });     
    }
  }

  function addSubMenuClick(theObj){
    if(($(theObj).parent().attr('class')).match(/innersel/i) == null){
      $(theObj).click(function(){
        $(this).unbind('click');
        $(this).parent().addClass('innersel');
        //$(this).addClass('active');
        addSubMenuClick($(this));
        $(this).next().css({'display' : 'block'});
      });
    }else{
      $(theObj).click(function(){
        $(this).unbind('click');
        $(this).parent().removeClass('innersel');
        //$(this).removeClass('active');
        addSubMenuClick($(this));
        $(this).next().css({'display' : 'none'});
      });     
    }
  }
  
  function SwapTo(){
    var total = $(".jqGSPagination li").size();
    CurrentCarouselAt = CurrentCarouselAt+1;
    if(CurrentCarouselAt >= total){
      CurrentCarouselAt = 0;
    }
    $(".jqGSPagination li a").eq(CurrentCarouselAt).click();
  }
  
  function printS(){
    print();
  }
  
  function collapse(what){
    $(what).slideToggle("fast");
  }
  
  function trim(value) {
    value = value.replace(/^\s+/,''); 
    value = value.replace(/\s+$/,'');
    return value;
  }
  
  function get_payment_methods(){
    $.post('/simple_ajax.php', { 'checkout' : 'true' }, function(d){
      $(".leftspace7px, p.dev.normal").remove();
      $(".winkelwagen-indeling-bg").hide();
      $(".winkelwagen-content-klein").hide();
      $(".winkelwagen-footer").hide();
      $("#orderload").hide();
      $("h1").html(l('kiesafrekenmethode'));
      $(".winkelwagen-indeling-bg").before('<br />' + l('kiesbettmeth') + '<br />' + d);
      ___DoOrder();
    }, 'html');
  }

  /* OK */ function ___ProductToCart(     a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z){ if(typeof(__ProductToCart)    == 'function'){ __ProductToCart(    a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z); }}
  /* OK */ function ___ViewProductCat(    a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z){ if(typeof(__ViewProductCat)   == 'function'){ __ViewProductCat(   a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z); }}
  /* OK */ function ___ViewProduct(       a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z){ if(typeof(__ViewProduct)      == 'function'){ __ViewProduct(      a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z); }}
  /* OK */ function ___RegisterAccount(   a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z){ if(typeof(__RegisterAccount)  == 'function'){ __RegisterAccount(  a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z); }}
  /* OK */ function ___DoOrder(           a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z){ if(typeof(__DoOrder)          == 'function'){ __DoOrder(          a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z); }}
  /* OK */ function ___ShowCart(          a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z){ if(typeof(__ShowCart)         == 'function'){ __ShowCart(         a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z); }}
  /* OK */ function ___ViewFactuurlijst(  a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z){ if(typeof(__ViewFactuurlijst) == 'function'){ __ViewFactuurlijst( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z); }}
  /* OK */ function ___ViewAccount(       a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z){ if(typeof(__ViewAccount)      == 'function'){ __ViewAccount(      a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z); }}
  /* OK */ function ___ClearCart(         a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z){ if(typeof(__ClearCart)        == 'function'){ __ClearCart(        a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z); }}
