(function(e){function p(){this.regional=[];this.regional[""]={labels:["Years","Months","Weeks","Days","Hours","Minutes","Seconds"],labels1:["Year","Month","Week","Day","Hour","Minute","Second"],compactLabels:["y","m","w","d"],timeSeparator:":",isRTL:false};this._defaults={until:null,since:null,timezone:null,format:"dHMS",layout:"",compact:false,description:"",expiryUrl:"",expiryText:"",alwaysExpire:false,onExpiry:null,onTick:null};e.extend(this._defaults,this.regional[""])}function q(a,b){e.extend(a,
b);for(var c in b)if(b[c]==null)a[c]=null;return a}e.extend(p.prototype,{markerClassName:"hasCountdown",_timer:setInterval(function(){e.countdown._updateTargets()},980),_timerTargets:[],setDefaults:function(a){this._resetExtraLabels(this._defaults,a);q(this._defaults,a||{})},UTCDate:function(a,b,c,d,f,h,k,j){if(typeof b=="object"&&b.constructor==Date){j=b.getMilliseconds();k=b.getSeconds();h=b.getMinutes();f=b.getHours();d=b.getDate();c=b.getMonth();b=b.getFullYear()}var g=new Date;g.setUTCFullYear(b);
g.setUTCDate(1);g.setUTCMonth(c||0);g.setUTCDate(d||1);g.setUTCHours(f||0);g.setUTCMinutes((h||0)-(Math.abs(a)<30?a*60:a));g.setUTCSeconds(k||0);g.setUTCMilliseconds(j||0);return g},_attachCountdown:function(a,b){var c=e(a);if(!c.hasClass(this.markerClassName)){c.addClass(this.markerClassName);b={options:e.extend({},b),_periods:[0,0,0,0,0,0,0]};e.data(a,"countdown",b);this._changeCountdown(a)}},_addTarget:function(a){this._hasTarget(a)||this._timerTargets.push(a)},_hasTarget:function(a){return e.inArray(a,
this._timerTargets)>-1},_removeTarget:function(a){this._timerTargets=e.map(this._timerTargets,function(b){return b==a?null:b})},_updateTargets:function(){for(var a=0;a<this._timerTargets.length;a++)this._updateCountdown(this._timerTargets[a])},_updateCountdown:function(a,b){var c=e(a);if(b=b||e.data(a,"countdown")){c.html(this._generateHTML(b));c[(this._get(b,"isRTL")?"add":"remove")+"Class"]("countdown_rtl");if(c=this._get(b,"onTick"))c.apply(a,[b._hold!="lap"?b._periods:this._calculatePeriods(b,
b._show,new Date)]);if(b._hold!="pause"&&(b._since?b._now.getTime()<=b._since.getTime():b._now.getTime()>=b._until.getTime())&&!b._expiring){b._expiring=true;if(this._hasTarget(a)||this._get(b,"alwaysExpire")){this._removeTarget(a);(c=this._get(b,"onExpiry"))&&c.apply(a,[]);if(c=this._get(b,"expiryText")){var d=this._get(b,"layout");b.options.layout=c;this._updateCountdown(a,b);b.options.layout=d}if(c=this._get(b,"expiryUrl"))window.location=c}b._expiring=false}else b._hold=="pause"&&this._removeTarget(a);
e.data(a,"countdown",b)}},_changeCountdown:function(a,b,c){b=b||{};if(typeof b=="string"){var d=b;b={};b[d]=c}if(c=e.data(a,"countdown")){this._resetExtraLabels(c.options,b);q(c.options,b);this._adjustSettings(c);e.data(a,"countdown",c);b=new Date;if(c._since&&c._since<b||c._until&&c._until>b)this._addTarget(a);this._updateCountdown(a,c)}},_resetExtraLabels:function(a,b){var c=false;for(var d in b)if(d.match(/[Ll]abels/)){c=true;break}if(c)for(d in a)if(d.match(/[Ll]abels[0-9]/))a[d]=null},_destroyCountdown:function(a){var b=
e(a);if(b.hasClass(this.markerClassName)){this._removeTarget(a);b.removeClass(this.markerClassName).empty();e.removeData(a,"countdown")}},_pauseCountdown:function(a){this._hold(a,"pause")},_lapCountdown:function(a){this._hold(a,"lap")},_resumeCountdown:function(a){this._hold(a,null)},_hold:function(a,b){var c=e.data(a,"countdown");if(c){if(c._hold=="pause"&&!b){c._periods=c._savePeriods;var d=c._since?"-":"+";c[c._since?"_since":"_until"]=this._determineTime(d+c._periods[0]+"y"+d+c._periods[1]+"o"+
d+c._periods[2]+"w"+d+c._periods[3]+"d"+d+c._periods[4]+"h"+d+c._periods[5]+"m"+d+c._periods[6]+"s");this._addTarget(a)}c._hold=b;c._savePeriods=b=="pause"?c._periods:null;e.data(a,"countdown",c);this._updateCountdown(a,c)}},_getTimesCountdown:function(a){a=e.data(a,"countdown");return!a?null:!a._hold?a._periods:this._calculatePeriods(a,a._show,new Date)},_get:function(a,b){return a.options[b]!=null?a.options[b]:e.countdown._defaults[b]},_adjustSettings:function(a){var b=new Date,c=this._get(a,"timezone");
c=c==null?-(new Date).getTimezoneOffset():c;a._since=this._get(a,"since");if(a._since)a._since=this.UTCDate(c,this._determineTime(a._since,null));a._until=this.UTCDate(c,this._determineTime(this._get(a,"until"),b));a._show=this._determineShow(a)},_determineTime:function(a,b){var c=function(f){var h=new Date;h.setTime(h.getTime()+f*1E3);return h},d=function(f){f=f.toLowerCase();var h=new Date,k=h.getFullYear(),j=h.getMonth(),g=h.getDate(),l=h.getHours(),i=h.getMinutes();h=h.getSeconds();for(var n=
/([+-]?[0-9]+)\s*(s|m|h|d|w|o|y)?/g,m=n.exec(f);m;){switch(m[2]||"s"){case "s":h+=parseInt(m[1],10);break;case "m":i+=parseInt(m[1],10);break;case "h":l+=parseInt(m[1],10);break;case "d":g+=parseInt(m[1],10);break;case "w":g+=parseInt(m[1],10)*7;break;case "o":j+=parseInt(m[1],10);g=Math.min(g,e.countdown._getDaysInMonth(k,j));break;case "y":k+=parseInt(m[1],10);g=Math.min(g,e.countdown._getDaysInMonth(k,j));break}m=n.exec(f)}return new Date(k,j,g,l,i,h,0)};(a=a==null?b:typeof a=="string"?d(a):typeof a==
"number"?c(a):a)&&a.setMilliseconds(0);return a},_getDaysInMonth:function(a,b){return 32-(new Date(a,b,32)).getDate()},_generateHTML:function(a){a._periods=periods=a._hold?a._periods:this._calculatePeriods(a,a._show,new Date);for(var b=false,c=0,d=0;d<a._show.length;d++){b|=a._show[d]=="?"&&periods[d]>0;a._show[d]=a._show[d]=="?"&&!b?null:a._show[d];c+=a._show[d]?1:0}b=this._get(a,"compact");d=this._get(a,"layout");var f=b?this._get(a,"compactLabels"):this._get(a,"labels"),h=this._get(a,"timeSeparator"),
k=this._get(a,"description")||"",j=function(l){var i=e.countdown._get(a,"compactLabels"+periods[l]);return a._show[l]?periods[l]+(i?i[l]:f[l])+" ":""},g=function(l){var i=e.countdown._get(a,"labels"+periods[l]);return a._show[l]?'<span class="countdown_section"><span class="countdown_amount">'+periods[l]+"</span><br/>"+(i?i[l]:f[l])+"</span>":""};return d?this._buildLayout(a,d,b):(b?'<span class="countdown_row countdown_amount'+(a._hold?" countdown_holding":"")+'">'+j(0)+j(1)+j(2)+j(3)+(a._show[4]?
this._twoDigits(periods[4]):"")+(a._show[5]?(a._show[4]?h:"")+this._twoDigits(periods[5]):"")+(a._show[6]?(a._show[4]||a._show[5]?h:"")+this._twoDigits(periods[6]):""):'<span class="countdown_row countdown_show'+c+(a._hold?" countdown_holding":"")+'">'+g(0)+g(1)+g(2)+g(3)+g(4)+g(5)+g(6))+"</span>"+(k?'<span class="countdown_row countdown_descr">'+k+"</span>":"")},_buildLayout:function(a,b,c){var d=c?this._get(a,"compactLabels"):this._get(a,"labels"),f=function(j){return(e.countdown._get(a,(c?"compactLabels":
"labels")+a._periods[j])||d)[j]};f={yl:f(0),yn:a._periods[0],ynn:this._twoDigits(a._periods[0]),ol:f(1),on:a._periods[1],onn:this._twoDigits(a._periods[1]),wl:f(2),wn:a._periods[2],wnn:this._twoDigits(a._periods[2]),dl:f(3),dn:a._periods[3],dnn:this._twoDigits(a._periods[3]),hl:f(4),hn:a._periods[4],hnn:this._twoDigits(a._periods[4]),ml:f(5),mn:a._periods[5],mnn:this._twoDigits(a._periods[5]),sl:f(6),sn:a._periods[6],snn:this._twoDigits(a._periods[6])};var h=b;for(b=0;b<7;b++){var k="yowdhms".charAt(b);
h=h.replace(new RegExp("\\{"+k+"<\\}(.*)\\{"+k+">\\}","g"),a._show[b]?"$1":"")}e.each(f,function(j,g){h=h.replace(new RegExp("\\{"+j+"\\}","g"),g)});return h},_twoDigits:function(a){return(a<10?"0":"")+a},_determineShow:function(a){a=this._get(a,"format");var b=[];b[0]=a.match("y")?"?":a.match("Y")?"!":null;b[1]=a.match("o")?"?":a.match("O")?"!":null;b[2]=a.match("w")?"?":a.match("W")?"!":null;b[3]=a.match("d")?"?":a.match("D")?"!":null;b[4]=a.match("h")?"?":a.match("H")?"!":null;b[5]=a.match("m")?
"?":a.match("M")?"!":null;b[6]=a.match("s")?"?":a.match("S")?"!":null;return b},_calculatePeriods:function(a,b,c){a._now=c;a._now.setMilliseconds(0);var d=new Date(a._now.getTime());if(a._since&&c.getTime()<a._since.getTime())a._now=c=d;else if(a._since)c=a._since;else{d.setTime(a._until.getTime());if(c.getTime()>a._until.getTime())a._now=c=d}var f=[0,0,0,0,0,0,0];if(b[0]||b[1]){var h=e.countdown._getDaysInMonth(c.getFullYear(),c.getMonth()),k=e.countdown._getDaysInMonth(d.getFullYear(),d.getMonth()),
j=d.getDate()==c.getDate()||d.getDate()>=Math.min(h,k)&&c.getDate()>=Math.min(h,k),g=function(i){return(i.getHours()*60+i.getMinutes())*60+i.getSeconds()};j=Math.max(0,(d.getFullYear()-c.getFullYear())*12+d.getMonth()-c.getMonth()+(d.getDate()<c.getDate()&&!j||j&&g(d)<g(c)?-1:0));f[0]=b[0]?Math.floor(j/12):0;f[1]=b[1]?j-f[0]*12:0;j=function(i,n,m){m=i.getDate()==m;var o=e.countdown._getDaysInMonth(i.getFullYear()+n*f[0],i.getMonth()+n*f[1]);i.getDate()>o&&i.setDate(o);i.setFullYear(i.getFullYear()+
n*f[0]);i.setMonth(i.getMonth()+n*f[1]);m&&i.setDate(o);return i};if(a._since)d=j(d,-1,k);else c=j(new Date(c.getTime()),+1,h)}var l=Math.floor((d.getTime()-c.getTime())/1E3);a=function(i,n){f[i]=b[i]?Math.floor(l/n):0;l-=f[i]*n};a(2,604800);a(3,86400);a(4,3600);a(5,60);a(6,1);return f}});e.fn.countdown=function(a){var b=Array.prototype.slice.call(arguments,1);if(a=="getTimes")return e.countdown["_"+a+"Countdown"].apply(e.countdown,[this[0]].concat(b));return this.each(function(){typeof a=="string"?
e.countdown["_"+a+"Countdown"].apply(e.countdown,[this].concat(b)):e.countdown._attachCountdown(this,a)})};e.countdown=new p})(jQuery);

