Vista.QuickTickets.Stage={Movie:1,Cinema:2,Type:3,Time:4,Session:5},function(){"use strict";Vista.QuickTickets.BaseView=function(n){this.container=n;this.container.on("click",".item",{instance:this},this.onItemClick);this.selected=[]},Vista.QuickTickets.BaseView.prototype.columnTemplate='<span class="column"></span>',Vista.QuickTickets.BaseView.prototype.getAnyItem=function(){return $(this.formatItem({Id:"",Name:this.anyText})).addClass("any unique selected")},Vista.QuickTickets.BaseView.prototype.changeEvent="selectionchange.qtsub",Vista.QuickTickets.BaseView.prototype.display=function(n){this.data=n,this.container.append.apply(this.container,this.format(n)),this.container.scrollbox({step:432})},Vista.QuickTickets.BaseView.prototype.format=function(){var t=[],n;for(t.push(this.getAnyItem()),n=0;n<this.data.length;n++)t.push(this.formatItem(this.data[n]));return t},Vista.QuickTickets.BaseView.prototype.formatItem=function(n){return Vista.Utilities.format(this.template,n.Id,n.Name)},Vista.QuickTickets.BaseView.prototype.destroy=function(){this.container.scrollbox("destroy"),this.container.unbind(),this.container.empty()},Vista.QuickTickets.BaseView.prototype.filter=function(n){if(n==="")this.container.find(".filtered").removeClass("filtered");else{var t=new RegExp(n,"i");this.container.find(".item").each(function(n,i){i=$(i),i.is(".any")||!t.test(i.find(".name").text())?i.addClass("filtered"):i.removeClass("filtered")}),this.container.find(".column").each(function(n,t){t=$(t),t.children(":visible").length===0?t.addClass("filtered"):t.removeClass("filtered")})}this.container.scrollbox("refresh")},Vista.QuickTickets.BaseView.prototype.clearSelection=function(n){if(this.container.find(".any").addClass("selected"),this.selected.length){for(var t=0;t<this.selected.length;t++)this.selected[t].removeClass("selected");this.selected.length=0,n||this.container.trigger(this.changeEvent)}},Vista.QuickTickets.BaseView.prototype.getSelection=function(){if(this.selected.length===0){var n=this.container.find(".selected");if(n.length)return[{Name:n.find(".name").text()}]}return $.map(this.selected,function(n){return{Id:n.attr("data-id"),Name:n.find(".name").text()}})},Vista.QuickTickets.BaseView.prototype.onSelectionChange=function(n){this.container.bind(this.changeEvent,n)},Vista.QuickTickets.BaseView.prototype.formatColumns=function(n){for(var u=4,e=[],o=Math.ceil(n.length/u),r,i,f,t=0;t<o;t++){for(r=$(this.columnTemplate),i=0;i<u;i++)if(f=u*t+i,f<n.length)r.append(n[f]);else break;e.push(r)}return e},Vista.QuickTickets.BaseView.prototype.onItemClick=function(n){var i=$(this),t=n.data.instance,r,u;if(i.hasClass("selected")){if(i.hasClass("any"))return;for(i.removeClass("selected"),r=0;r<t.selected.length;r++)if(t.selected[r].is(i))break;t.selected.splice(r,1),(i.hasClass("unique")||!t.selected.length)&&t.container.find(".any").addClass("selected")}else{if(i.addClass("selected"),i.hasClass("unique")){for(u=0;u<t.selected.length;u++)t.selected[u].removeClass("selected");t.selected.length=0}else t.container.find(".any").removeClass("selected");i.hasClass("any")||t.selected.splice(0,0,i)}t.container.trigger(t.changeEvent)}}(),function(){"use strict";Vista.QuickTickets.MovieView=function(n){Vista.QuickTickets.BaseView.call(this,n)},Vista.QuickTickets.MovieView.prototype=Object.create(Vista.QuickTickets.BaseView.prototype),Vista.QuickTickets.MovieView.prototype.template='<span class="movie item" data-id="{1}"><img src="'+Vista.Urls.QuickTickets.MovieImages+'" alt="{2}" /><span class="name">{2}</span></span>',Vista.QuickTickets.MovieView.prototype.anyText=Vista.Lang.QuickTickets.MovieAny,Vista.QuickTickets.MovieView.prototype.formatItem=function(n){return Vista.Utilities.format(this.template,n.ImageId||"default",n.Id,n.Name)}}(),function(){"use strict";Vista.QuickTickets.CinemaView=function(n){Vista.QuickTickets.BaseView.call(this,n)},Vista.QuickTickets.CinemaView.prototype=Object.create(Vista.QuickTickets.BaseView.prototype),Vista.QuickTickets.CinemaView.prototype.template='<span class="item selectable cinema" data-id="{0}"><span class="name">{1}</span><span class="attributes">{2}</span></span>',Vista.QuickTickets.CinemaView.prototype.anyText=Vista.Lang.QuickTickets.CinemaAny,Vista.QuickTickets.CinemaView.prototype.formatItem=function(n){return Vista.Utilities.format(this.template,n.Id,n.Name,n.Attributes)},Vista.QuickTickets.CinemaView.prototype.format=function(){var n=Vista.QuickTickets.BaseView.prototype.format.call(this);return this.formatColumns(n)}}(),function(){"use strict";Vista.QuickTickets.TypeView=function(n){Vista.QuickTickets.BaseView.call(this,n)},Vista.QuickTickets.TypeView.prototype=Object.create(Vista.QuickTickets.BaseView.prototype),Vista.QuickTickets.TypeView.prototype.template='<span class="item selectable" data-id="{0}"><span class="name">{1}</span></span>',Vista.QuickTickets.TypeView.prototype.anyText=Vista.Lang.QuickTickets.ShowTypeAny,Vista.QuickTickets.TypeView.prototype.format=function(){var n=Vista.QuickTickets.BaseView.prototype.format.call(this);return this.formatColumns(n)}}(),function(){"use strict";Vista.QuickTickets.TimeView=function(n){Vista.QuickTickets.BaseView.call(this,n)},Vista.QuickTickets.TimeView.prototype=Object.create(Vista.QuickTickets.BaseView.prototype),Vista.QuickTickets.TimeView.prototype.template='<span class="item selectable" data-id="{0}"><span class="name">{1}</span></span>',Vista.QuickTickets.TimeView.prototype.anyText=Vista.Lang.QuickTickets.TimeAny,Vista.QuickTickets.TimeView.prototype.display=function(n){this.maxDate=n.MaxDate,this.minDate=n.MinDate,n=n.Filters,Vista.QuickTickets.BaseView.prototype.display.call(this,n)},Vista.QuickTickets.TimeView.prototype.format=function(){var t=this.buildCalendar(this.maxDate),n=$(this.columnTemplate);return n.append(this.getAnyItem()),n.append(this.formatItem({Id:"Day",Name:Vista.Lang.QuickTickets.TimeDay})),n.append(this.formatItem({Id:"Evening",Name:Vista.Lang.QuickTickets.TimeEvening})),[t,n]},Vista.QuickTickets.TimeView.prototype.clearSelection=function(){Vista.QuickTickets.BaseView.prototype.clearSelection.call(this,!0),this.calendar.reset(!1)},Vista.QuickTickets.TimeView.prototype.getSelection=function(){var n=Vista.QuickTickets.BaseView.prototype.getSelection.call(this),t=this.calendar.isToday()?Vista.Lang.QuickTickets.Today:Globalize.format(this.calendar.getDate(),"M");return n.splice(0,0,{Id:this.calendar.getDate(),Name:t}),n},Vista.QuickTickets.TimeView.prototype.buildCalendar=function(){var n=$(this.columnTemplate);return this.calendar=new Vista.QuickTickets.Calendar(n,{maxDate:this.maxDate,minDate:this.minDate,change:$.proxy(this.calendarChange,this)}),n},Vista.QuickTickets.TimeView.prototype.calendarChange=function(){this.container.trigger(this.changeEvent)}}(),function(){"use strict";Vista.QuickTickets.SessionView=function(n){Vista.QuickTickets.TimeView.call(this,n)},Vista.QuickTickets.SessionView.prototype=Object.create(Vista.QuickTickets.TimeView.prototype),Vista.QuickTickets.SessionView.prototype.template='<span class="item selectable unique" data-id="{0}"><span class="name">{1}</span></span>',Vista.QuickTickets.SessionView.prototype.anyText=Vista.Lang.QuickTickets.SessionAny,Vista.QuickTickets.SessionView.prototype.display=function(n){for(var r,u,i,t=0;t<n.length;t++)(i=new Date(n[t].TimeYear,n[t].TimeMonth,n[t].TimeDay),n[t].CinemaLocalDate=i,n[t].Name=n[t].TimeFormatted,n[t].SoldOut)||((typeof r=="undefined"||i>r)&&(r=i),(typeof u=="undefined"||i<u)&&(u=i));typeof r=="undefined"&&(r=new Date),this.minDate=u,this.maxDate=r,Vista.QuickTickets.BaseView.prototype.display.call(this,n)},Vista.QuickTickets.SessionView.prototype.format=function(){var i=this.buildCalendar(this.maxDate),n,t;for(this.items=[],n=0;n<this.data.length;n++)t=$(this.formatItem(this.data[n])).data("date",this.data[n].CinemaLocalDate),this.data[n].SoldOut&&t.removeClass("item").addClass("label invalid"),this.items.push(t);return this.static=i,this.container.append(i),this.refresh(),[]},Vista.QuickTickets.SessionView.prototype.refresh=function(){var n=this.calendar.getDate(),r=!1,i=[],u,t;$.each(this.items,function(t,u){u.detach();var f=u.data("date").getDate()===n.getDate()&&u.data("date").getMonth()===n.getMonth()&&u.data("date").getYear()===n.getYear();f&&(r|=!u.hasClass("invalid"),i.push(u))}),this.static.nextAll().remove(),r?this.static.after.apply(this.static,this.formatColumns(i)):(u=i.length?Vista.Lang.QuickTickets.SoldOutSessions:Vista.Lang.QuickTickets.NoSessions,t=$(this.formatItem({Name:Vista.Utilities.format(u,Globalize.format(n,"D"))})).removeClass("item").addClass("label"),t.css({width:"auto",display:"inline-block"}).find(".name").css("width","auto"),this.static.after(t))},Vista.QuickTickets.SessionView.prototype.calendarChange=function(){this.refresh(),this.container.scrollbox("refresh"),this.container.trigger(this.changeEvent)}}(),Vista.QuickTickets.Data=function(){"use strict";function n(n,r,u){if(i(r)&&n.cache){u(n.cache);return}t=$.ajax({type:"POST",url:n.url,data:r,traditional:!0,success:function(t){Vista.Utilities.fixDotNetJsonDateString(t),i(r)&&(n.cache=t),u(t)}})}function i(n){for(var t in n)if(n.hasOwnProperty(t)&&n[t]&&n[t].length)return!1;return!0}var t,r={url:Vista.Urls.QuickTickets.Movies,cache:undefined},f={url:Vista.Urls.QuickTickets.Cinemas,cache:undefined},u={url:Vista.Urls.QuickTickets.ShowTypes,cache:undefined},e={url:Vista.Urls.QuickTickets.Times,cache:undefined};return{abortCurrent:function(){t&&t.abort&&t.abort()},getMoviesAsync:function(t,i){n(r,t,i)},getCinemasAsync:function(t,i){n(f,t,i)},getTypesAsync:function(t,i){n(u,t,i)},getTimesAsync:function(t,i){n(e,t,i)}}},function(){"use strict";Vista.QuickTickets.Calendar=function(n,t){var r={change:function(){},maxDate:undefined,minDate:undefined},i;this.options=$.extend(r,t),this.options.minDate=this.options.minDate||new Date,this.options.minDate.setHours(0),this.options.minDate.setMinutes(0),this.options.minDate.setSeconds(0),this.options.minDate.setMilliseconds(0),this.options.maxDate&&(this.options.maxDate.setHours(0),this.options.maxDate.setMinutes(0),this.options.maxDate.setSeconds(0),this.options.maxDate.setMilliseconds(0)),i='<div class="calendar-container"><span class="calendar-left-arrow"></span><div class="calendar" tabindex="1"><span class="calendar-month"></span><span class="calendar-day"></span><span class="calendar-footer"></span></div><span class="calendar-right-arrow"></span></div>',this.container=n.find(".calendar-container"),this.calendar=$(i).appendTo(n).find(".calendar").click(function(){this.focus()}),this.month=n.find(".calendar-month"),this.day=n.find(".calendar-day"),this.footer=n.find(".calendar-footer"),this.leftArrow=n.find(".calendar-left-arrow"),this.rightArrow=n.find(".calendar-right-arrow"),this.calendar.keydown($.proxy(function(n){switch(n.which){case 37:return!this.decrement();case 39:return!this.increment();case 27:return this.reset(),!1}},this)),this.calendar.mousewheel($.proxy(function(n,t,i,r){return r===1?!this.decrement():r===-1?!this.increment():void 0},this)),this.leftArrow.click($.proxy(function(n){n.preventDefault(),n.stopPropagation(),this.decrement()},this)),this.rightArrow.click($.proxy(function(n){n.preventDefault(),n.stopPropagation(),this.increment()},this)),this.reset(!0)},Vista.QuickTickets.Calendar.prototype.isToday=function(){var n=new Date;return this.date.getDate()===n.getDate()&&this.date.getMonth()===n.getMonth()&&this.date.getYear()===n.getYear()},Vista.QuickTickets.Calendar.prototype.printDate=function(n){this.month.text(Globalize.format(this.date,"MMMM")),this.day.text(Globalize.format(this.date,"dd")),this.isToday()?this.footer.text(Vista.Lang.QuickTickets.Today):this.footer.empty(),this.date<=this.options.minDate?this.leftArrow.css("visibility","hidden"):this.leftArrow.css("visibility",""),this.date>=this.options.maxDate?this.rightArrow.css("visibility","hidden"):this.rightArrow.css("visibility",""),n||this.options.change()},Vista.QuickTickets.Calendar.prototype.increment=function(){return this.date>=this.options.maxDate?!1:(this.date.setDate(this.date.getDate()+1),this.printDate(),!0)},Vista.QuickTickets.Calendar.prototype.reset=function(n){this.date=new Date(this.options.minDate),this.date.setHours(0),this.date.setMinutes(0),this.date.setSeconds(0),this.date.setMilliseconds(0),this.printDate(n)},Vista.QuickTickets.Calendar.prototype.decrement=function(){return this.date<=this.options.minDate?!1:(this.date.setDate(this.date.getDate()-1),this.printDate(),!0)},Vista.QuickTickets.Calendar.prototype.getDate=function(){return new Date(this.date)}}(),Vista.QuickTickets.HomeView=function(n){"use strict";function r(){n.trigger(i.stageSelect,t[$(this).val()])}var i={stageSelect:"stageselect.qthome"},t;n.find("button").click(r),t={movie:Vista.QuickTickets.Stage.Movie,cinema:Vista.QuickTickets.Stage.Cinema,type:Vista.QuickTickets.Stage.Type,time:Vista.QuickTickets.Stage.Time},this.show=function(){n.show()},this.hide=function(){n.hide()},this.onStageSelect=function(t){n.bind(i.stageSelect,t)}},Vista.QuickTickets.DetailsView=function(n){"use strict";function a(i,u){var e=t[i].term,o=t[i].def,s=n.find("dl dt:visible:last"),f;for(s.length&&(e.insertAfter(s.next("dd")),o.insertAfter(e)),e.show(),o.show(),r&&r!==t[i].control&&r.collapse(),t[i].control.reset(),f=0;f<u.length;f++)t[i].control.append(u[f]);r=t[i].control}function f(){n.is(":visible")&&(n.hide(),i.hide(),$(window).unbind("resize",u),n.trigger(o.close))}function s(){n.is(":visible")||(u(),$(window).resize(u),i.show(),n.show())}function u(){i.width($(document).width()),i.height($(document).height())}var o={close:"close.qtdetails"},i=$('<div id="page-overlay"></div>').appendTo($("body")),c=n.find("h3 em"),l=n.find(".restart"),h=n.find(".close"),e=n.find(".compare"),t=function(){var u=n.find("dl .movies"),o=u.next(),e=n.find("dl .cinemas"),h=e.next(),s=n.find("dl .types"),r=s.next(),i=n.find("dl .times"),f=i.next(),t={};return t[Vista.QuickTickets.Stage.Movie]={term:u,def:o,control:new Vista.Collapsible(o)},t[Vista.QuickTickets.Stage.Cinema]={term:e,def:h,control:new Vista.Collapsible(h)},t[Vista.QuickTickets.Stage.Type]={term:s,def:r,control:new Vista.Collapsible(r)},t[Vista.QuickTickets.Stage.Time]={term:i,def:f,control:new Vista.Collapsible(f)},t}(),r;i.click(f),h.click(f),this.setTitle=function(n){c.text(n)},this.setSelection=function(n,t){a(n,t)},this.clear=function(){for(var n in t)t[n].control.reset(),t[n].term.hide(),t[n].def.hide()},this.onRestartClick=function(n){l.click(n)},this.onCompareClick=function(n){e.click(n)},this.onClose=function(t){n.bind(o.close,t)},this.disableCompare=function(){e.addClass("disabled").attr("disabled","disabled")},this.enableCompare=function(){e.removeClass("disabled").removeAttr("disabled")},this.show=s,this.hide=f},Vista.QuickTickets.SelectionView=function(n){"use strict";function c(){t.val(""),s()}function w(n){n.keyCode===27&&(t.val()!==""?c():t.blur())}function s(){var n=t.val();n!==""?o.show():o.hide(),i.filter(n)}function h(){i.clearSelection(),u.hide()}function y(){var r,t;t=$.grep(i.getSelection(),function(n){return n.Id}),r=e?t[0].Id.getTime()===e.getTime()&&t.length===1:t.length===0,r?u.hide():u.css("display",""),n.trigger(l.change)}function v(){r.removeClass("container-loading"),f.show(),u.hide(),t.removeAttr("disabled"),t.attr("placeholder",p)}function a(){r.removeClass("container-loading"),t.val(""),t.attr("disabled","disabled"),t.attr("placeholder",""),t.css("display",""),o.hide(),i&&i.destroy(),f.hide(),u.hide()}var l={change:"selectionchange.qtselect"},r=n.find(".selection"),f=n.find(".next"),u=n.find(".clear"),t=n.find(".search input"),o=n.find(".search button"),p=t.attr("placeholder"),i,e;u.click(h),o.click(c),t.keydown(w),t.keyup(s),this.displaySelection=function(n,t){var u;v();switch(n){case Vista.QuickTickets.Stage.Cinema:i=new Vista.QuickTickets.CinemaView(r);break;case Vista.QuickTickets.Stage.Type:i=new Vista.QuickTickets.TypeView(r);break;case Vista.QuickTickets.Stage.Time:u=!0,i=new Vista.QuickTickets.TimeView(r);break;case Vista.QuickTickets.Stage.Session:u=!0,i=new Vista.QuickTickets.SessionView(r);break;default:i=new Vista.QuickTickets.MovieView(r)}i.display(t);i.onSelectionChange(y);e=u?i.getSelection()[0].Id:null},this.onNextClick=function(n){f.click(n)},this.onSelectionChange=function(t){n.bind(l.change,t)},this.getSelection=function(){return i.getSelection()},this.showLoading=function(){r.addClass("container-loading")},this.clear=function(){h()},this.disable=function(){a()},this.setNextText=function(n){f.find("span").text(n),f.show()},this.disableNext=function(){f.hide()},this.showSearch=function(){t.show()},this.hideSearch=function(){t.hide()}},Vista.QuickTickets.Main=function(n,t,i,r){"use strict";function nt(i,r){n.hide(),u={},e=g.slice(),e.splice($.inArray(r,e),1),t.show(),y(r)}function b(){v(),l()}function d(){e.length=0,p()}function p(){var n=$.map(i.getSelection(),function(n){return n.Id});if(c()){window.location=Vista.Utilities.format(Vista.Urls.QuickTickets.Ticket,u[Vista.QuickTickets.Stage.Cinema][0],n[1]);return}u[s]=n,e.length?y(e.shift()):tt()}function tt(){var f=w(),u=$('<form method="post"></form>').attr("action",Vista.Urls.QuickTickets.Compare),r="?",t,n,i,e;for(t in f)if(f.hasOwnProperty(t))if(n=f[t],n instanceof Array)for(i=0;i<n.length;i++)r+="&"+t+"="+n[i],u.append($('<input type="hidden" />').attr({name:t,value:n[i]}));else r+="&"+t+"="+n,u.append($('<input type="hidden" />').attr({name:t,value:n}));e=1900,r.length>e?($("body").append(u),u.submit()):window.location=Vista.Urls.QuickTickets.Compare+r}function a(){r.abortCurrent(),i.disable(),t.clear(),n.show()}function v(){var n=i.getSelection();n=$.map(n,function(n){return n.Name}),t.setSelection(s,n)}function y(n){i.disable(),i.showLoading(),t.disableCompare(),s=n,t.setTitle(o[n].title),k(n)}function c(){return s===Vista.QuickTickets.Stage.Time&&(u[Vista.QuickTickets.Stage.Movie]||[]).length===1&&(u[Vista.QuickTickets.Stage.Cinema]||[]).length===1&&(u[Vista.QuickTickets.Stage.Type]||[]).length===1}function l(){if(c()){var n=i.getSelection();n.length===2?i.setNextText(f.BookNow):i.disableNext()}else e.length?i.setNextText(o[e[0]].nextText):i.setNextText(f.Compare)}function w(){var i,r,n,t;u[Vista.QuickTickets.Stage.Time]&&u[Vista.QuickTickets.Stage.Time].length&&(r=Vista.Utilities.formatDateForPost(u[Vista.QuickTickets.Stage.Time][0]),i=u[Vista.QuickTickets.Stage.Time].slice(1)),n={Movies:u[Vista.QuickTickets.Stage.Movie],Cinemas:u[Vista.QuickTickets.Stage.Cinema],ShowTypes:u[Vista.QuickTickets.Stage.Type],Time:i,Date:r};for(t in n)n.hasOwnProperty(t)&&typeof n[t]=="undefined"&&delete n[t];return n}function k(n){r.abortCurrent();var t=w();switch(n){case Vista.QuickTickets.Stage.Movie:r.getMoviesAsync(t,h(n));break;case Vista.QuickTickets.Stage.Cinema:r.getCinemasAsync(t,h(n));break;case Vista.QuickTickets.Stage.Type:r.getTypesAsync(t,h(n));break;case Vista.QuickTickets.Stage.Time:r.getTimesAsync(t,h(n))}}function h(n){return function(r){n===s&&(o[n].searchable?i.showSearch():i.hideSearch(),c()?i.displaySelection(Vista.QuickTickets.Stage.Session,r):i.displaySelection(n,r),v(),l(),t.enableCompare())}}var f=Vista.Lang.QuickTickets,s,g=[Vista.QuickTickets.Stage.Movie,Vista.QuickTickets.Stage.Cinema,Vista.QuickTickets.Stage.Type,Vista.QuickTickets.Stage.Time],e=[],u={},o={};o[Vista.QuickTickets.Stage.Movie]={title:f.Movies,nextText:f.MovieNext,searchable:!0},o[Vista.QuickTickets.Stage.Cinema]={title:f.Cinemas,nextText:f.CinemaNext,searchable:!0},o[Vista.QuickTickets.Stage.Type]={title:f.ShowTypes,nextText:f.ShowTypeNext,searchable:!1},o[Vista.QuickTickets.Stage.Time]={title:f.Times,nextText:f.TimeNext,searchable:!1};n.onStageSelect(nt);t.onClose(a);t.onRestartClick(a);t.onCompareClick(d);i.onSelectionChange(b);i.onNextClick(p)},$(function(){var n=$("#quick-tickets"),t;n.length&&(t=new Vista.QuickTickets.Main(new Vista.QuickTickets.HomeView(n),new Vista.QuickTickets.DetailsView($("#quick-tickets-overlay")),new Vista.QuickTickets.SelectionView($("#quick-tickets-selection")),new Vista.QuickTickets.Data))})