function SimpleCart(n){this.countTimer=null;this.oldText=null;this._fdmsg=null;this._fd=null;this.load(n);this.checkButtons(n)}function onSimpleCartMove(){var n=$("#small-cart"),i,t;if(n.length!=0){if(!window.kytary.utils.isInViewportSimple(n)){t=($(window).width()-$(".panel-right .container").width())/2;n.addClass("fixed-cart").css("right",t-55);return}i=$(window).scrollTop();i<31?n.removeClass("fixed-cart").css("right",""):n.is(".fixed-cart")&&(t=($(window).width()-$(".panel-right .container").width())/2,n.css("right",t-55))}}(function(n){n.fn.shake=function(t){typeof t=="function"&&(t={callback:t});var t=n.extend({direction:"left",distance:20,times:3,speed:140,easing:"swing"},t);return this.each(function(){var i=n(this),h={position:i.css("position"),top:i.css("top"),right:i.css("right")},r=t.direction=="up"||t.direction=="down"?"top":"left",u=t.direction=="up"||t.direction=="left"?"pos":"neg",f={},e={},s={},o;for(f[r]=(u=="pos"?"-=":"+=")+t.distance,e[r]=(u=="pos"?"+=":"-=")+t.distance,s[r]=(u=="pos"?"-=":"+=")+t.distance,i.animate(f,t.speed,t.easing),o=1;o<t.times;o++)i.animate(e,t.speed,t.easing).animate(s,t.speed,t.easing);i.animate(e,t.speed,t.easing).animate(f,t.speed/2,t.easing,function(){i.css(h);t.callback&&t.callback.apply(this,arguments)})})}})(jQuery);SimpleCart.prototype.onCountChange=function(n){window.clearTimeout(this.countTimer);var t=this;this.countTimer=window.setTimeout(function(){var i=$(n.currentTarget);t.setCount(i.data("id"),i.val())},300)};SimpleCart.prototype.checkButtons=function(n,t){var i,r,u;this._fdmsg=n.fdmsg;this._fd=n.fd;i=this;r=$("a[data-cart]");t&&(r.find(".glyphicon").removeClass("glyphicon-ok"),r.is(".replace-text")&&this.oldText&&r.find("span:last").text(this.oldText));u=!0;$.each(n.items,function(t,f){var e=r.filter("[data-cart='"+f.mhProduct.id+"']");e.is(".replace-text")?(i.oldText||(i.oldText=e.find("span").last().text()),e.find("span:last").text(i.getMsg(f.mhProduct.id,n)),e.find(".glyphicon").addClass("padding--r-10 glyphicon-ok")):e.find(".glyphicon").addClass("glyphicon-ok");u=u&&f.isElectronicContent});i.handleFreeDelivery(n.t,u)};SimpleCart.prototype.load=function(n,t,i){var r,f,u,e;if(n&&n.items){r=$("#small-cart, #small-cart-ph");f=r.find("div > ul");f.empty();$.each(n.items,function(n,t){var i=$('<li><span><img src="'+t.imageUrl+'" alt="." /><\/span><span class="two-lines"><a href="/'+t.mhProduct.id+'">'+t.mhProduct.name+"<\/a><br/>"+t.available+'<\/span><span><input value="'+t.count+'" type="number" step="1" min="1"'+(t.maxOrder?' max="'+t.maxOrder+'"':"")+'/><\/span><span class="text-right price" id="'+t.mhProduct.id+"_"+t.mhProduct.position+'">'+t.price+'<\/span><span><a href="#"><i class="glyphicon glyphicon-remove"><\/i><\/a><\/span><\/li>');i.find("input").data("id",t.mhProduct);i.find("a:last-child").click(function(){return window.kytary.simpleCart.remove(t.mhProduct),!1});f.append(i)});u=this;f.find("input").stepper("defaults",{initDelay:1e3}).stepper().on("change",function(n){u.onCountChange(n)});e=this.badge(r,n.items.length);i&&t&&e&&setTimeout(function(){e.shake({times:1,direction:"up",distance:10,speed:150})},0);r.find(".total:first").text(n.total);f.children("li").length==0?(r.unbind("mouseenter mouseleave"),u.hide()):(r.hover(function(){u.show()},function(){u.hide()}),t&&u.show())}};SimpleCart.prototype.handleFreeDelivery=function(n,t){var i=$("#fd-info");if(!this._fdmsg||this._fdmsg.length==0){i.hide();return}if(t||this._fd==null?i.hide():i.show(),this._fdmsg.length==1){i.addClass("days");i.children("span").html(this._fdmsg[0]);i.show();return}n<this._fd?i.removeClass("over"):i.addClass("over");i.children("span").html(this._fdmsg[n<this._fd?0:1])};SimpleCart.prototype.badge=function(n,t,i){var r=n.find(".badge");return r.length==0?(t>0&&(r=$('<span class="badge badge-notify'+(t>9?" badge-twodigits":"")+'">'+t+"<\/span>"),i||(i=".glyphicon-shopping-cart"),n.find(i).after(r)),r):t>0?(t>9?r.addClass("badge-twodigits"):r.removeClass("badge-twodigits"),r.text(t),r):(r.remove(),null)};SimpleCart.prototype.getMsg=function(n,t){for(var i=0;i<t.items.length;i++)if(t.items[i].mhProduct.id==n)return window.kytary_resources.Cart_PcsInCart.format(t.items[i].count);return""};SimpleCart.prototype.add=function(n,t,i,r){var f=this,u=null,e;if(n)u=$(n),u.find(".glyphicon").addClass(u.is(".replace-text")?"ajax-small padding--r-10":"ajax-small");else return;(e=u.data("cart"),e)&&window.kytary.ajax.post("/Cart/AddProductToCart",{code:e,hitID:window.kytary.utils.hid,searchID:window.kytary.utils.sid,count:t?t:1,det:r},function(t){if(t){f.load(t,!0,!0);f.checkButtons(t);var r=!0;$.each(t.items,function(n,t){r=r&&t.isElectronicContent});f.handleFreeDelivery(t.t,r);n&&(u.find(".glyphicon").removeClass("ajax-small").addClass("glyphicon-ok"),u.is(".replace-text")?(f.oldText||(f.oldText=u.find("span").last().text()),u.find("span").last().text(f.getMsg(e,t))):u.find(".glyphicon").removeClass("padding--r-10"));t.mhc&&window.kytary_googleAnalytics.addJson({cart:JSON.parse(t.mhc)});i&&i()}},null,null,!1)};SimpleCart.prototype.addSet=function(n,t,i){var r,f,u;t&&(r=$(t),f=r.parents("form").first(),f.length!=0)&&(r.find(".glyphicon").addClass("ajax-small padding--r-10"),u=this,window.kytary.ajax.post("/Cart/AddProductSetToCartSimple",f.serialize(),function(t){if(t){u.load(t,!0,!0);u.checkButtons(t);var f=!0;$.each(t.items,function(n,t){f=f&&t.isElectronicContent});u.handleFreeDelivery(t.t,f);r.find(".glyphicon").removeClass("ajax-small").addClass("glyphicon-ok");r.is(".replace-text")&&r.find("span").last().text(u.getMsg(n,t));t.mhc&&window.kytary_googleAnalytics.addJson({cart:JSON.parse(t.mhc)});i&&i()}},null,null,!1))};SimpleCart.prototype.remove=function(n){var t=this;window.kytary.ajax.post("/Cart/RemoveProductFromCart",{id:{Code:n.id,Order:n.position}},function(i){i&&(t.load(i,!0),t.checkButtons(i,!0),i.mhc&&window.kytary_googleAnalytics.addJson({cart:JSON.parse(i.mhc)}),window.kytary_googleAnalytics.addEventAction("action.remove.products","remove",{products:[n]}))})};SimpleCart.prototype.setCount=function(n,t){var i=parseInt(t),r;isNaN(i)||i<1||(r=this,window.kytary.ajax.post("/Cart/SetCountInSmallCart",{id:{Code:n.id,Order:n.position},count:i},function(i){if(i){$("#small-cart, #small-cart-ph").find(".total:first").text(i.total);for(var u=0;u<i.items.length;u++)$("#"+i.items[u].mhProduct.id+"_"+i.items[u].mhProduct.position).text(i.items[u].price);r.checkButtons(i);n.quantity!=t&&i.mhc&&window.kytary_googleAnalytics.addJson({cart:JSON.parse(i.mhc)});n.quantity>t?(n.quantity=n.quantity-t,window.kytary_googleAnalytics.addEventAction("action.remove.products","remove",{products:[n]}),n.quantity=t):n.quantity<t&&(n.quantity=t-n.quantity,window.kytary_googleAnalytics.addEventAction("action.add.products","add",{products:[n]}),n.quantity=t)}}))};SimpleCart.prototype.show=function(){$("#small-cart .list-container").addClass("displayed")};SimpleCart.prototype.hide=function(){$("#small-cart .list-container").removeClass("displayed")};$(function(){$(window).on("resize scroll",function(){window.kytary.utils.onSimpleCartMove();window.kytary.compare.onCompareMove()});window.kytary.utils.onSimpleCartMove();window.kytary.compare.onCompareMove()})