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