if(typeof PSP==="undefined")var PSP={};
PSP.BookingTimer=new Class({options:{urls:{expire:"./ajax/expiredorders.php"},text:{and:" and ",expiredMessage:"Bookings have expired.",normalMessage:"Your seats reservation will expire in ",minutes:" minutes",minute:" minute",seconds:" seconds",second:" second"},settings:{timeout:250,expire:1800,display:1}},_iteratorID:null,_displayElement:null,_startTime:null,_expireTime:null,_lastTextRefresh:0,_expired:false,_productsExpiring:[],initialize:function(a,c){this._displayElement=$$(a)[0];var b=0,e=
[];$splat(c[0]).each(function(d){e.push(d.productId);if(b==0||b.toInt()>d.bookingTime.toInt())b=d.bookingTime.toInt()});if(b.toInt()>0){this._productsExpiring=e;this._startTime=b.toInt()}},initTimer:function(){this._expireTime=this._startTime+this.options.settings.expire;this._expired=false;this._iteratorID=this._updateTimerElement.periodical(this.options.settings.timeout,this)},setPeriod:function(a){if(a.toInt()>0)this.options.settings.expire=a.toInt();this.initTimer()},_checkExpired:function(){if(this._expireTime<
this._getCurrentTime()){this._expired=true;(new Request.JSON({url:this.options.urls.expire,data:{products_id:this._productsExpiring},onComplete:function(){this._iteratorID=$clear(this._iteratorID)}.bind(this)})).send()}},_getCurrentTime:function(){var a=new Date;return(a.getTime()/1E3).round().toInt()},_updateTimerElement:function(){if(this._getCurrentTime()>=this._lastTextRefresh+this.options.settings.display){if(this._startTime>0){this._checkExpired();var a="";if(this._expired)a=this.options.text.expiredMessage;
else{a=this.options.text.normalMessage;var c=false;if(Math.floor((this._expireTime-this._getCurrentTime())/60)>0){a+=Math.floor((this._expireTime-this._getCurrentTime())/60);a+=Math.floor((this._expireTime-this._getCurrentTime())/60)==1?this.options.text.minute:this.options.text.minutes;c=true}if((this._expireTime-this._getCurrentTime())%60){if(c)a+=this.options.text.and;a+=(this._expireTime-this._getCurrentTime())%60;a+=(this._expireTime-this._getCurrentTime())%60==1?this.options.text.second:this.options.text.seconds}a+=
"."}this._displayElement.set("text",a);this._displayElement[(a&&a.length?"remove":"add")+"Class"]("bookingTimerEmpty")}this._lastTextRefresh=this._getCurrentTime()}}});

