/* http://keith-wood.name/countdown.html Countdown for jQuery v1.6.2. Written by Keith Wood (kbwood{at}iinet.com.au) January 2008. Available under the MIT (https://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt) license. Please attribute the author if you use it. */ /* Display a countdown timer. Attach it with options like: $('div selector').countdown( {until: new Date(2009, 1 - 1, 1, 0, 0, 0), onExpiry: happyNewYear}); */ !function(a){function b(){function b(a){var e=a<1e12?e=performance.now?performance.now()+performance.timing.navigationStart:Date.now():a||(new Date).getTime();e-d>=1e3&&(l._updateTargets(),d=e),c(b)}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"],whichLabels:null,digits:["0","1","2","3","4","5","6","7","8","9"],timeSeparator:":",isRTL:!1},this._defaults={until:null,since:null,timezone:null,serverSync:null,format:"dHMS",layout:"",compact:!1,significant:0,description:"",expiryUrl:"",expiryText:"",alwaysExpire:!1,onExpiry:null,onTick:null,tickInterval:1},a.extend(this._defaults,this.regional[""]),this._serverSyncs=[];var c=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||null,d=0;!c||a.noRequestAnimationFrame?(a.noRequestAnimationFrame=null,setInterval(function(){l._updateTargets()},980)):(d=window.animationStartTime||window.webkitAnimationStartTime||window.mozAnimationStartTime||window.oAnimationStartTime||window.msAnimationStartTime||(new Date).getTime(),c(b))}function k(b,c){return"option"==b&&(0==c.length||1==c.length&&"string"==typeof c[0])||a.inArray(b,j)>-1}var c=0,d=1,e=2,f=3,g=4,h=5,i=6;a.extend(b.prototype,{markerClassName:"hasCountdown",propertyName:"countdown",_rtlClass:"countdown_rtl",_sectionClass:"countdown_section",_amountClass:"countdown_amount",_rowClass:"countdown_row",_holdingClass:"countdown_holding",_showClass:"countdown_show",_descrClass:"countdown_descr",_timerTargets:[],setDefaults:function(b){this._resetExtraLabels(this._defaults,b),a.extend(this._defaults,b||{})},UTCDate:function(a,b,c,d,e,f,g,h){"object"==typeof b&&b.constructor==Date&&(h=b.getMilliseconds(),g=b.getSeconds(),f=b.getMinutes(),e=b.getHours(),d=b.getDate(),c=b.getMonth(),b=b.getFullYear());var i=new Date;return i.setUTCFullYear(b),i.setUTCDate(1),i.setUTCMonth(c||0),i.setUTCDate(d||1),i.setUTCHours(e||0),i.setUTCMinutes((f||0)-(Math.abs(a)<30?60*a:a)),i.setUTCSeconds(g||0),i.setUTCMilliseconds(h||0),i},periodsToSeconds:function(a){return 31557600*a[0]+2629800*a[1]+604800*a[2]+86400*a[3]+3600*a[4]+60*a[5]+a[6]},_attachPlugin:function(b,c){if(b=a(b),!b.hasClass(this.markerClassName)){var d={options:a.extend({},this._defaults),_periods:[0,0,0,0,0,0,0]};b.addClass(this.markerClassName).data(this.propertyName,d),this._optionPlugin(b,c)}},_addTarget:function(a){this._hasTarget(a)||this._timerTargets.push(a)},_hasTarget:function(b){return a.inArray(b,this._timerTargets)>-1},_removeTarget:function(b){this._timerTargets=a.map(this._timerTargets,function(a){return a==b?null:a})},_updateTargets:function(){for(var a=this._timerTargets.length-1;a>=0;a--)this._updateCountdown(this._timerTargets[a])},_optionPlugin:function(b,c,d){b=a(b);var e=b.data(this.propertyName);if(!c||"string"==typeof c&&null==d){var f=c;return c=(e||{}).options,c&&f?c[f]:c}if(b.hasClass(this.markerClassName)){if(c=c||{},"string"==typeof c){var f=c;c={},c[f]=d}this._resetExtraLabels(e.options,c);var g=e.options.timezone!=c.timezone;a.extend(e.options,c),this._adjustSettings(b,e,null!=c.until||null!=c.since||g);var h=new Date;(e._since&&e._sinceh)&&this._addTarget(b[0]),this._updateCountdown(b,e)}},_updateCountdown:function(b,c){var d=a(b);if(c=c||d.data(this.propertyName)){if(d.html(this._generateHTML(c)).toggleClass(this._rtlClass,c.options.isRTL),a.isFunction(c.options.onTick)){var e="lap"!=c._hold?c._periods:this._calculatePeriods(c,c._show,c.options.significant,new Date);1!=c.options.tickInterval&&this.periodsToSeconds(e)%c.options.tickInterval!=0||c.options.onTick.apply(b,[e])}var f="pause"!=c._hold&&(c._since?c._now.getTime()=c._until.getTime());if(f&&!c._expiring){if(c._expiring=!0,this._hasTarget(b)||c.options.alwaysExpire){if(this._removeTarget(b),a.isFunction(c.options.onExpiry)&&c.options.onExpiry.apply(b,[]),c.options.expiryText){var g=c.options.layout;c.options.layout=c.options.expiryText,this._updateCountdown(b,c),c.options.layout=g}c.options.expiryUrl&&(window.location=c.options.expiryUrl)}c._expiring=!1}else"pause"==c._hold&&this._removeTarget(b);d.data(this.propertyName,c)}},_resetExtraLabels:function(a,b){var c=!1;for(var d in b)if("whichLabels"!=d&&d.match(/[Ll]abels/)){c=!0;break}if(c)for(var d in a)d.match(/[Ll]abels[02-9]|compactLabels1/)&&(a[d]=null)},_adjustSettings:function(b,c,d){for(var e,f=0,g=null,h=0;h0,o[p]="?"!=b._show[p]||k?b._show[p]:null,m+=o[p]?1:0,n-=b._periods[p]>0?1:0;for(var q=[!1,!1,!1,!1,!1,!1,!1],p=i;p>=c;p--)b._show[p]&&(b._periods[p]?q[p]=!0:(q[p]=n>0,n--));var r=b.options.compact?b.options.compactLabels:b.options.labels,s=b.options.whichLabels||this._normalLabels,t=function(a){var c=b.options["compactLabels"+s(b._periods[a])];return o[a]?j._translateDigits(b,b._periods[a])+(c?c[a]:r[a])+" ":""},u=function(a){var c=b.options["labels"+s(b._periods[a])];return!b.options.significant&&o[a]||b.options.significant&&q[a]?''+j._translateDigits(b,b._periods[a])+"
"+(c?c[a]:r[a])+"
":""};return b.options.layout?this._buildLayout(b,o,b.options.layout,b.options.compact,b.options.significant,q):(b.options.compact?''+t(c)+t(d)+t(e)+t(f)+(o[g]?this._minDigits(b,b._periods[g],2):"")+(o[h]?(o[g]?b.options.timeSeparator:"")+this._minDigits(b,b._periods[h],2):"")+(o[i]?(o[g]||o[h]?b.options.timeSeparator:"")+this._minDigits(b,b._periods[i],2):""):''+u(c)+u(d)+u(e)+u(f)+u(g)+u(h)+u(i))+""+(b.options.description?''+b.options.description+"":"")},_buildLayout:function(b,j,k,l,m,n){for(var o=b.options[l?"compactLabels":"labels"],p=b.options.whichLabels||this._normalLabels,q=function(a){return(b.options[(l?"compactLabels":"labels")+p(b._periods[a])]||o)[a]},r=function(a,c){return b.options.digits[Math.floor(a/c)%10]},s={desc:b.options.description,sep:b.options.timeSeparator,yl:q(c),yn:this._minDigits(b,b._periods[c],1),ynn:this._minDigits(b,b._periods[c],2),ynnn:this._minDigits(b,b._periods[c],3),y1:r(b._periods[c],1),y10:r(b._periods[c],10),y100:r(b._periods[c],100),y1000:r(b._periods[c],1e3),ol:q(d),on:this._minDigits(b,b._periods[d],1),onn:this._minDigits(b,b._periods[d],2),onnn:this._minDigits(b,b._periods[d],3),o1:r(b._periods[d],1),o10:r(b._periods[d],10),o100:r(b._periods[d],100),o1000:r(b._periods[d],1e3),wl:q(e),wn:this._minDigits(b,b._periods[e],1),wnn:this._minDigits(b,b._periods[e],2),wnnn:this._minDigits(b,b._periods[e],3),w1:r(b._periods[e],1),w10:r(b._periods[e],10),w100:r(b._periods[e],100),w1000:r(b._periods[e],1e3),dl:q(f),dn:this._minDigits(b,b._periods[f],1),dnn:this._minDigits(b,b._periods[f],2),dnnn:this._minDigits(b,b._periods[f],3),d1:r(b._periods[f],1),d10:r(b._periods[f],10),d100:r(b._periods[f],100),d1000:r(b._periods[f],1e3),hl:q(g),hn:this._minDigits(b,b._periods[g],1),hnn:this._minDigits(b,b._periods[g],2),hnnn:this._minDigits(b,b._periods[g],3),h1:r(b._periods[g],1),h10:r(b._periods[g],10),h100:r(b._periods[g],100),h1000:r(b._periods[g],1e3),ml:q(h),mn:this._minDigits(b,b._periods[h],1),mnn:this._minDigits(b,b._periods[h],2),mnnn:this._minDigits(b,b._periods[h],3),m1:r(b._periods[h],1),m10:r(b._periods[h],10),m100:r(b._periods[h],100),m1000:r(b._periods[h],1e3),sl:q(i),sn:this._minDigits(b,b._periods[i],1),snn:this._minDigits(b,b._periods[i],2),snnn:this._minDigits(b,b._periods[i],3),s1:r(b._periods[i],1),s10:r(b._periods[i],10),s100:r(b._periods[i],100),s1000:r(b._periods[i],1e3)},t=k,u=c;u<=i;u++){var v="yowdhms".charAt(u),w=new RegExp("\\{"+v+"<\\}(.*)\\{"+v+">\\}","g");t=t.replace(w,!m&&j[u]||m&&n[u]?"$1":"")}return a.each(s,function(a,b){var c=new RegExp("\\{"+a+"\\}","g");t=t.replace(c,b)}),t},_minDigits:function(a,b,c){return b=""+b,b.length>=c?this._translateDigits(a,b):(b="0000000000"+b,this._translateDigits(a,b.substr(b.length-c)))},_translateDigits:function(a,b){return(""+b).replace(/[0-9]/g,function(b){return a.options.digits[b]})},_determineShow:function(a){var b=a.options.format,j=[];return j[c]=b.match("y")?"?":b.match("Y")?"!":null,j[d]=b.match("o")?"?":b.match("O")?"!":null,j[e]=b.match("w")?"?":b.match("W")?"!":null,j[f]=b.match("d")?"?":b.match("D")?"!":null,j[g]=b.match("h")?"?":b.match("H")?"!":null,j[h]=b.match("m")?"?":b.match("M")?"!":null,j[i]=b.match("s")?"?":b.match("S")?"!":null,j},_calculatePeriods:function(a,b,j,k){a._now=k,a._now.setMilliseconds(0);var m=new Date(a._now.getTime());a._since?k.getTime()a._until.getTime()&&(a._now=k=m));var n=[0,0,0,0,0,0,0];if(b[c]||b[d]){var o=l._getDaysInMonth(k.getFullYear(),k.getMonth()),p=l._getDaysInMonth(m.getFullYear(),m.getMonth()),q=m.getDate()==k.getDate()||m.getDate()>=Math.min(o,p)&&k.getDate()>=Math.min(o,p),r=function(a){return 60*(60*a.getHours()+a.getMinutes())+a.getSeconds()},s=Math.max(0,12*(m.getFullYear()-k.getFullYear())+m.getMonth()-k.getMonth()+(m.getDate()u&&k.setDate(u),k.setFullYear(k.getFullYear()+n[c]),k.setMonth(k.getMonth()+n[d]),t&&k.setDate(u)}var v=Math.floor((m.getTime()-k.getTime())/1e3),w=function(a,c){n[a]=b[a]?Math.floor(v/c):0,v-=n[a]*c};if(w(e,604800),w(f,86400),w(g,3600),w(h,60),w(i,1),v>0&&!a._since)for(var x=[1,12,4.3482,7,24,60,60],y=i,z=1,A=i;A>=c;A--)b[A]&&(n[y]>=z&&(n[y]=0,v=1),v>0&&(n[A]++,v=0,y=A,z=1)),z*=x[A];if(j)for(var A=c;A<=i;A++)j&&n[A]?j--:j||(n[A]=0);return n}});var j=["getTimes"];a.fn.countdown=function(a){var b=Array.prototype.slice.call(arguments,1);return k(a,b)?l["_"+a+"Plugin"].apply(l,[this[0]].concat(b)):this.each(function(){if("string"==typeof a){if(!l["_"+a+"Plugin"])throw"Unknown command: "+a;l["_"+a+"Plugin"].apply(l,[this].concat(b))}else l._attachPlugin(this,a||{})})};var l=a.countdown=new b}(jQuery);