!function($,t,e,s){var a="basket";function o(t,e){this.element=t,this._name=a,this._defaults=$.fn.basket.defaults,this.options=$.extend({},this._defaults,e),this.init()}$.extend(o.prototype,{init:function(){this.buildCache(),this.bindEvents()},destroy:function(){this.unbindEvents(),this.$element.removeData()},buildCache:function(){this.$element=$(this.element),this.$basketCounter=$(this.options.basketCounterId),this.$basketTotal=$(this.options.basketTotalId),this.$basketLoadingSection=$(this.options.basketLoadingId),this.$basketMessage=$(this.options.basketMessageId),this.$itemRemoveButtons=$(this.options.itemRemoveSelector),this.$basketCounter=$(this.options.basketCountId),this.$basket=$(this.options.basketPanelId),this.$grandTotalContainer=$(this.options.grandTotalContainerId),this.$checkoutButton=$(this.options.checkoutBtnId),this.basketCounter=parseInt(this.$basketCounter.html()),this.basketTotal=parseFloat(this.$basketTotal.html()),!0===isNaN(this.basketTotal)&&(this.basketTotal=0),!0===isNaN(this.basketCounter)&&(this.basketCounter=0)},bindEvents:function(){var t=this;t.$itemRemoveButtons.on("click",(function(e){e.preventDefault(),t.$basketMessage.hide(),t.$basketLoadingSection.hide();var s=$(this),a=parseInt(s.data("cartitem")),o=parseFloat(s.data("itemprice")),n=s.parent().parent();1===n.length&&(n.after(t.$basketLoadingSection),n.after(t.$basketMessage)),!0!==isNaN(a)&&!0!==isNaN(o)?t.removeFromBasket(n,a,o):t.setBasketMessage("An error has occurred whilst trying to remove the item.",!0)}))},unbindEvents:function(){this.$itemRemoveButtons.off("click")},setBasketMessage:function(t,e){var s=this;s.$basketMessage.html(t),s.$basketMessage.show(),!0!==e&&s.$basketMessage.delay(3200).fadeOut(300)},removeFromBasketTotal:function(t){var e=this;!0!==isNaN(e.basketTotal)&&!0!==isNaN(t)?(e.basketTotal=this.basketTotal-t,e.basketTotal<0&&(e.basketTotal=0),e.$basketTotal.html(e.basketTotal.toFixed(2))):e.$basketTotal.html("")},decreaseBasketCounter:function(){var t=this;t.basketCounter--,t.basketCounter<=0&&(t.basketCounter=0),t.$basketCounter.html(t.basketCounter),t.$basketCounter.attr("title","You have "+t.basketCounter+" item/s to checkout"),0===t.basketCounter&&(t.$checkoutButton.hide(),t.$grandTotalContainer.hide())},removeFromBasket:function(t,e,s){var a=this;if(t.hide(),a.$basketLoadingSection.show(),null!==a.options.removeFromBasketUrl){var o={cartItemId:e};$.ajax({type:"POST",url:a.options.removeFromBasketUrl,data:JSON.stringify(o),dataType:"json",contentType:"application/json; charset=utf-8",cache:!1,success:function(e){if(null===e)return t.show(),void a.setBasketMessage("An error has occurred removing the item",!0);t.remove(),a.setBasketMessage("Item has been removed",!1),a.options.reloadPageOnRemove?setTimeout((function(){location.reload()}),100):(a.removeFromBasketTotal(s),a.decreaseBasketCounter())},error:function(e,s,o){t.show(),a.setBasketMessage("An error has occurred whilst trying to remove the item: "+s,!0)},complete:function(){a.$basketLoadingSection.hide()}})}else a.setBasketMessage("No remove from basket url has been set",!0)}}),$.fn.basket=function(t){return this.each((function(){$.data(this,"plugin_basket")||$.data(this,"plugin_basket",new o(this,t))})),this},$.fn.basket.defaults={basketCounterId:"#basketCount",itemRemoveSelector:".removeCartItem",basketTotalId:"#basketTotal",basketLoadingId:"#basketLoading",basketMessageId:"#basketMessage",basketCountId:"#basketCount",basketPanelId:"#panel",grandTotalContainerId:"#grandTotalDiv",checkoutBtnId:"#checkoutBtn",removeFromBasketUrl:"/shoppingbasket/removeCartItem/",reloadPageOnRemove:!1}}(jQuery,window,document);