(function(){function y(){var t=JSON.parse(u("cart")),i=JSON.parse(u("numberOfTickets")),n=0;return t.map(function(t){t.bands.map(function(t){n+=t.qty})}),n+i}function r(){var t=$(".js-ticket-qty"),n=0;t.each(function(t,i){n+=i.value});n>0?$(".js-add-cart-submit").removeAttr("disabled"):$(".js-add-cart-submit").attr("disabled",!0)}function p(){$(".js-cart-count").html(y())}function u(n){var i="; "+document.cookie,t=i.split("; "+n+"=");return t.length===2?t.pop().split(";").shift():null}function w(n,t,i){var r,u;i?(r=new Date,r.setTime(r.getTime()+i*864e5),u="; expires="+r.toGMTString()):u="";document.cookie=n+"="+t+u+"; path=/"}var b=document.getElementsByClassName("js-itinerary_list")[0],n={},f="",h=$(".js-cart-count"),t=$(".js-show-modal"),c=$(".js-modal-show-name"),l=$(".js-modal-show-date"),a=$(".js-modal-show-time"),v=$(".js-modal-show-venue"),e=$(".js-modal-price-bands"),o,s,i;$(".js-price-band .js-ticket-qty").val("0");o=$(".js-price-band").clone(!0);$(".js-price-band").remove();s=$(".js-ticket-qty");i=$(".js-add-cart-total");$(".js-modal-close").click(function(){$(".js-show-modal").removeClass("c-modal--open")});$(".js-performance .js-modal-toggle").click(function(){var t,u;$(".js-show-modal").addClass("c-modal--open");t=$(this).closest(".js-performance");f=t.data("performance-id");c.text(t.data("show-name"));l.text(t.data("date"));a.text(t.data("time"));v.text(t.data("venue"));e.empty();var p=t.data("price-bands").toString().split(","),b=t.data("prices").toString().split(","),d=t.data("quantity").toString().split(","),g=t.data("information").toString().split(","),nt=t.data("concessions").toString().split(",");for(console.log(p),u=0;u<p.length;u++){var h=p[u],y,k=d[u],w=g[u],tt=nt[u],r=o.clone(!0);y=h.trim()==="Private Booth"||h.trim()==="Private Booths"?parseFloat(Math.round(y*800)/100).toFixed(2):h.trim()==="Family Ticket"?parseFloat(Math.round(b[u]*400)/100).toFixed(2):b[u];k>0&&(r.data("band-name",h),r.data("band-price",y),r.data("band-concession",tt),r.find(".js-price-band-name").text(h),r.find(".js-price-band-price").text(y),w!=null&&w.trim()!=""?(r.find(".c-tooltip__tip").text(w),r.find(".c-tooltip").show()):r.find(".c-tooltip").hide(),r.find(".js-ticket-qty").attr({max:k,min:0}),e.append(r))}s.val("0");i.text("0");n={bands:{},total:0,init:function(){var n=this;$(".js-price-band").each(function(t,i){var r=$(i),u={price:parseFloat(r.data("band-price"))||0,qty:0,concessionId:parseFloat(r.data("band-concession"))||0};n.bands[r.data("band-name")]=u});console.log(n)},updateTotal:function(){var t=Object.getOwnPropertyNames(this.bands),n;this.total=0;t.forEach(function(n){this.total+=this.bands[n].price*this.bands[n].qty},this);n=parseFloat(Math.round(this.total*100)/100).toFixed(2);i.html(n)}};n.init();n.updateTotal()});t.on("keyup",".js-ticket-qty",function(){var f=$(this).closest(".js-price-band"),i=f.data("band-name"),t=f.find(".js-ticket-qty")[0],e=f.data("concessionId"),o=parseInt(t.value),u=parseInt($(t).attr("max"))>20?20:parseInt($(t).attr("max")),s;i.indexOf("Private Booth")>-1&&(u=2);i.indexOf("Family Ticket")>-1&&(u=5);(t.value==null||t.value==undefined||t.value=="")&&(t.value=0);o>u&&(t.value=u,s=new document.toast("Sorry, we only have "+u+" "+i+" tickets available.").show());n.bands[i].qty=parseInt(t.value);n.bands[i].concessionId=parseInt(e);n.updateTotal();r()});t.on("keydown",".js-ticket-qty",function(n){if(n.keyCode==13)return $(n.target).next().focus(),!1});t.on("click",".js-ticket-qty-inc",function(){var e=$(this).closest(".js-price-band"),u=e.data("band-name"),t=e.find(".js-ticket-qty")[0],i=parseInt($(t).attr("max"))>20?20:parseInt($(t).attr("max")),f,o,s;u.indexOf("Private Booth")>-1&&(i=2);u.indexOf("Family Ticket")>-1&&(i=5);f=parseInt(t.value);console.log(f,i);f<i?(o=f+=1,t.value=o,n.bands[u].qty=parseInt(t.value),n.updateTotal(),r()):(t.value=i,s=new document.toast("Sorry, we only have "+i+" "+u+" tickets available.").show())});t.on("click",".js-ticket-qty-dec",function(){var i=$(this).closest(".js-price-band"),u=i.data("band-name"),t=i.find(".js-ticket-qty")[0],f=parseInt(t.value),e;f>=1?(e=f-=1,t.value=parseInt(e),n.bands[u].qty=parseInt(t.value),n.updateTotal()):(t.value=parseInt(0),n.bands[u].qty=parseInt(0),n.updateTotal());r()});$(".js-add-cart").submit(function(i){var e,o,s,a;i.stopPropagation();i.preventDefault();var r=JSON.parse(u("cart")||"[]"),c=[],l=Object.getOwnPropertyNames(n.bands);if(l.forEach(function(t){var i=n.bands[t].qty,r=n.bands[t].concessionId;i&&r!=null&&c.push({name:t,qty:i,concessionId:r})}),e={id:f,bands:c},r.push(e),console.log("Added new cart item: ",e),console.log("All cart items: ",r),w("cart",JSON.stringify(r),300),h.text(r.length),t.removeClass("c-modal--open"),o=0,e.bands.map(function(n){o+=n.qty}),s="",o==1)s="Your product was";else if(o>1)s="Your products were";else return;a=new document.toast(s+' successfully added to your cart, we\'ll save them for 30 minutes.&emsp;<a href="/cart" class="c-toast__link">Checkout<\/a>').show();p()})})()