$(function(){var c=function(){var b=null,e=null,d=null;return{init:function(){$(document).on("click touchstart",".removeitem",function(){var a=$(this).data("key");$.getJSON("/cart?a=updatequantity",{q:0,pb_skiptemplate:1,key:a},function(a){c.sethtmlcontent(a)});return!1});$(document).on("click touchstart",".removefrombag",function(a){a.preventDefault();a=$(this).data("key");$.getJSON("/cart?a=updatequantity",{q:0,pb_skiptemplate:1,key:a},function(a){c.sethtmlcontent(a)});return!1});$(document).on("keypress",
".quantityinput",function(a){if(9==a.which||$(this).val()==d)return!1;window.clearTimeout(e);b=$(this);d=$(this).val();e=window.setTimeout($.proxy(c,"update"),500);d=null;return!0});$(document).on("change",".quantityinput",function(a){if(9==a.which||$(this).val()==d)return!1;window.clearTimeout(e);b=$(this);d=$(this).val();e=window.setTimeout($.proxy(c,"update"),500);d=null;return!0});$(document).on("click","#discountcodeapply",function(a){a.preventDefault();"discount code"!=$(this).val()&&$.getJSON("/cart?a=applydiscount&ajax=1",
{pb_skiptemplate:1,discountcode:$("#discountcodeinput").val()},function(a){c.sethtmlcontent(a);"undefined"!=typeof a.discounterrormessage&&($("#discountcodeinput").attr("placeholder",a.discounterrormessage),window.setTimeout(function(){$("#discountcodeinput").attr("placeholder","Enter promo code")},3E3));$("#discountcodeinput").attr("placeholder",a.discounterrormessage);window.setTimeout(function(){$("#discountcodeinput").attr("placeholder",a.discountcode)},3E3)});return!1});$(document).ajaxStart(function(){$("#cart-working").show()});
$(document).ajaxStop(function(){$("#cart-working").hide()});$(document).on("click",".checkout.button",function(a){a.preventDefault();var b=!1;$(".quantityinput").each(function(){$(this).hasClass("error")&&(b=!0)});b||(window.location="/checkout")})},sethtmlcontent:function(a){$(".shoppingbag").html(a.content);$(".mightlike").html(a.upsell);$(".itemnum").html(a.itemcount);0==a.itemcount?$(".mightlike").hide():$(".mightlike").show();$(".cartWrapper").load("/cart-dropdown")},update:function(){key=b.data("key");
b.val().match(/[^0-9]/)||""==b.val()?b.addClass("error"):(b.removeClass("error"),$.getJSON("/cart?a=updatequantity",{pb_skiptemplate:1,key:key,q:b.val()},function(a){c.sethtmlcontent(a)}))}}}();c.init()});