!function($,t,i,a){function s(t){this._name="scheduleSummary",this._defaults=$.fn.scheduleSummary.defaults,this.options=$.extend({},this._defaults,t),this.total=0,this.endsTotal=0,this.placesTotal=0,this.customisationsTotal=0,this.init()}function e(t){return $("<div/>").text(t).html()}function o(t,i,a){var s=parseInt(i.val());!0===isNaN(s)&&(s=1),t.$placesDisplay.hide();var o=t.$placesDisplay.find(".placestext"),n=t.$placesDisplay.find(".placesprice");if(1===s)return t.placesTotal=0,o.html(""),n.html(""),t.$placesDisplay.hide(),void(!0===a&&t.calculateTotal());var l=t.options.defaultPrice*s;t.placesTotal=l;var c=e("£"+l.toFixed(2)),d=s+" places";o.html(d),n.html(c),t.$placesDisplay.show(),!0===a&&t.calculateTotal()}function n(t,i,a){var s=i.attr("id"),o=i.val(),n=i.find("option:selected"),l=$("#"+s+"_text"),c=l.find(".customtext"),d=l.find(".customprice"),u=parseFloat(n.data("price"));if(isNaN(u)||u<=0||""===o)c.html(""),d.html(""),l.hide();else{var h=n.data("description");void 0===h&&(h=n.html());var r=e("£"+u.toFixed(2));c.html(h),d.html(r),l.show()}!0===a&&t.calculateCustomisationTotal()}function l(t,i,a){var s,o=i.data("description"),n=parseFloat(i.data("price"));isNaN(n)||n<=0?(n=0,s=""):s=e("£"+(n+t.options.defaultPrice).toFixed(2)),t.$durationDisplay.html(o),t.$durationPrice.html(s),t.endsTotal=n,!0===a&&t.calculateTotal()}$.extend(s.prototype,{init:function(){if(this.buildCache(),this.bindEvents(),o(this,this.$placesSelect,!1),this.$customisations.each((function(){n(this,$(this),!1)})),!0===this.options.variableLengthSchedule&&this.$endsRadioButtons.length>0){var t=this.$endsRadioButtons.find(":checked");1===t.length&&l(this,t,!1)}this.calculateCustomisationTotal(),this.calculateTotal()},destroy:function(){this.unbindEvents()},buildCache:function(){if(this.$totalPriceDisplay=$(this.options.totalPriceDisplayId),this.$vatTotalPriceDisplay=$(this.options.vatRatePriceId),this.$durationDisplay=$(this.options.durationDisplayId),this.$durationPrice=$(this.options.durationPriceId),this.$placesSelect=$(this.options.placesSelectId),this.$placesDisplay=$(this.options.placesSectionId),this.$customisations=$(this.options.customisationsSelector),!1!==this.options.variableLengthSchedule){var t="input[type=radio][name="+this.options.durationEndsRadioButtonName+"]";this.$endsRadioButtons=$(t)}},bindEvents:function(){var t=this;t.$placesSelect.on("change",(function(){var i=$(this);o(t,i,!0)})),t.$customisations.on("change",(function(){var i=$(this);n(t,i,!0)})),!1!==t.options.variableLengthSchedule&&t.$endsRadioButtons.on("change",(function(){var i=$(this);l(t,i,!0)}))},unbindEvents:function(){var t=this;t.$placesSelect.off("change"),t.$customisations.off("change"),!1!==t.options.variableLengthSchedule&&t.$endsRadioButtons.off("change")},calculateCustomisationTotal:function(){var t=this,i=0;t.$customisations.each((function(){var t=$(this);if(""!==t.val()){var a=t.find("option:selected"),s=parseFloat(a.data("price"));isNaN(s)||s<=0||(i+=s)}})),t.customisationsTotal=i,t.calculateTotal()},calculateTotal:function(){var t=this,i=t.endsTotal+t.customisationsTotal+t.placesTotal;if((isNaN(i)||i<=0)&&(i=0),0===t.placesTotal&&!1===isNaN(t.options.defaultPrice)&&(i+=t.options.defaultPrice),t.options.vatRate>0){var a=t.options.vatRate/100*i;t.$vatTotalPriceDisplay.html(e("£"+a.toFixed(2))),i+=a}t.$totalPriceDisplay.html(e("£"+i.toFixed(2)))}}),$.fn.scheduleSummary=function(t){new s(t);return this},$.fn.scheduleSummary.defaults={customisationsSelector:".customisationSelect",variableLengthSchedule:!1,totalPriceDisplayId:"#totalPriceHtml",durationDisplayId:"#durationHtml",durationPriceId:"#durationPriceHtml",placesSelectId:"#places",placesSectionId:"#placesSummarySection",defaultPrice:0,durationEndsRadioButtonName:"ends",vatRate:0,vatRatePriceId:"#vatRateHtml"}}(jQuery,window,document);