/*! http://keith-wood.name/countdown.html
Countdown for jQuery v2.1.0.
Written by Keith Wood (wood.keith{at}optusnet.com.au) January 2008.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
!function(e){"use strict";e.JQPlugin.createPlugin({name:"countdown",defaultOptions:{until:null,since:null,timezone:null,serverSync:null,format:"dHMS",layout:"",compact:!1,padZeroes:!1,significant:0,description:"",expiryUrl:"",expiryText:"",alwaysExpire:!1,onExpiry:null,onTick:null,tickInterval:1},regionalOptions:{"":{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}},_rtlClass:"countdown-rtl",_sectionClass:"countdown-section",_amountClass:"countdown-amount",_periodClass:"countdown-period",_rowClass:"countdown-row",_holdingClass:"countdown-holding",_showClass:"countdown-show",_descrClass:"countdown-descr",_timerElems:[],_init:function(){var t=this;this._super(),this._serverSyncs=[];var i="function"==typeof Date.now?Date.now:function(){return(new Date).getTime()},s=window.performance&&"function"==typeof window.performance.now;var n=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||null,o=0;!n||e.noRequestAnimationFrame?(e.noRequestAnimationFrame=null,e.countdown._timer=setInterval(function(){t._updateElems()},1e3)):(o=window.animationStartTime||window.webkitAnimationStartTime||window.mozAnimationStartTime||window.oAnimationStartTime||window.msAnimationStartTime||i(),n(function e(r){var a=r<1e12?s?window.performance.now()+window.performance.timing.navigationStart:i():r||i();a-o>=1e3&&(t._updateElems(),o=a),n(e)}))},UTCDate:function(e,t,i,s,n,o,r,a){"object"==typeof t&&t instanceof Date&&(a=t.getMilliseconds(),r=t.getSeconds(),o=t.getMinutes(),n=t.getHours(),s=t.getDate(),i=t.getMonth(),t=t.getFullYear());var l=new Date;return l.setUTCFullYear(t),l.setUTCDate(1),l.setUTCMonth(i||0),l.setUTCDate(s||1),l.setUTCHours(n||0),l.setUTCMinutes((o||0)-(Math.abs(e)<30?60*e:e)),l.setUTCSeconds(r||0),l.setUTCMilliseconds(a||0),l},periodsToSeconds:function(e){return 31557600*e[0]+2629800*e[1]+604800*e[2]+86400*e[3]+3600*e[4]+60*e[5]+e[6]},resync:function(){var t=this;e("."+this._getMarker()).each(function(){var i=e.data(this,t.name);if(i.options.serverSync){for(var s=null,n=0;n-1},_removeElem:function(t){this._timerElems=e.map(this._timerElems,function(e){return e===t?null:e})},_updateElems:function(){for(var e=this._timerElems.length-1;e>=0;e--)this._updateCountdown(this._timerElems[e])},_optionsChanged:function(t,i,s){s.layout&&(s.layout=s.layout.replace(/</g,"<").replace(/>/g,">")),this._resetExtraLabels(i.options,s);var n=i.options.timezone!==s.timezone;e.extend(i.options,s),this._adjustSettings(t,i,!this._eqNull(s.until)||!this._eqNull(s.since)||n);var o=new Date;(i._since&&i._sinceo)&&this._addElem(t[0]),this._updateCountdown(t,i)},_updateCountdown:function(t,i){if(t=t.jquery?t:e(t),(i=i||this._getInst(t))&&i.options){if(t.html(this._generateHTML(i)).toggleClass(this._rtlClass,i.options.isRTL),"pause"!==i._hold&&e.isFunction(i.options.onTick)){var s="lap"!==i._hold?i._periods:this._calculatePeriods(i,i._show,i.options.significant,new Date);1!==i.options.tickInterval&&this.periodsToSeconds(s)%i.options.tickInterval!=0||i.options.onTick.apply(t[0],[s])}if("pause"!==i._hold&&(i._since?i._now.getTime()=i._until.getTime())&&!i._expiring){if(i._expiring=!0,this._hasElem(t[0])||i.options.alwaysExpire){if(this._removeElem(t[0]),e.isFunction(i.options.onExpiry)&&i.options.onExpiry.apply(t[0],[]),i.options.expiryText){var n=i.options.layout;i.options.layout=i.options.expiryText,this._updateCountdown(t[0],i),i.options.layout=n}i.options.expiryUrl&&(window.location=i.options.expiryUrl)}i._expiring=!1}else"pause"===i._hold&&this._removeElem(t[0])}},_resetExtraLabels:function(e,t){var i=null;for(i in t)i.match(/[Ll]abels[02-9]|compactLabels1/)&&(e[i]=t[i]);for(i in e)i.match(/[Ll]abels[02-9]|compactLabels1/)&&void 0===t[i]&&(e[i]=null)},_eqNull:function(e){return null==e},_adjustSettings:function(t,i,s){for(var n=null,o=0;o0,r[a]="?"!==t._show[a]||s?t._show[a]:null,n+=r[a]?1:0,o-=t._periods[a]>0?1:0;var l=[!1,!1,!1,!1,!1,!1,!1];for(a=6;a>=0;a--)t._show[a]&&(t._periods[a]?l[a]=!0:(l[a]=o>0,o--));var _=t.options.compact?t.options.compactLabels:t.options.labels,p=t.options.whichLabels||this._normalLabels,c=function(e){var s=t.options["compactLabels"+p(t._periods[e])];return r[e]?i._translateDigits(t,t._periods[e])+(s?s[e]:_[e])+" ":""},u=t.options.padZeroes?2:1,d=function(e){var s=t.options["labels"+p(t._periods[e])];return!t.options.significant&&r[e]||t.options.significant&&l[e]?''+i._minDigits(t,t._periods[e],u)+''+(s?s[e]:_[e])+"":""};return t.options.layout?this._buildLayout(t,r,t.options.layout,t.options.compact,t.options.significant,l):(t.options.compact?''+c(0)+c(1)+c(2)+c(3)+(r[4]?this._minDigits(t,t._periods[4],2):"")+(r[5]?(r[4]?t.options.timeSeparator:"")+this._minDigits(t,t._periods[5],2):"")+(r[6]?(r[4]||r[5]?t.options.timeSeparator:"")+this._minDigits(t,t._periods[6],2):""):''+d(0)+d(1)+d(2)+d(3)+d(4)+d(5)+d(6))+""+(t.options.description?''+t.options.description+"":"")},_buildLayout:function(t,i,s,n,o,r){for(var a=t.options[n?"compactLabels":"labels"],l=t.options.whichLabels||this._normalLabels,_=function(e){return(t.options[(n?"compactLabels":"labels")+l(t._periods[e])]||a)[e]},p=function(e,i){return t.options.digits[Math.floor(e/i)%10]},c={desc:t.options.description,sep:t.options.timeSeparator,yl:_(0),yn:this._minDigits(t,t._periods[0],1),ynn:this._minDigits(t,t._periods[0],2),ynnn:this._minDigits(t,t._periods[0],3),y1:p(t._periods[0],1),y10:p(t._periods[0],10),y100:p(t._periods[0],100),y1000:p(t._periods[0],1e3),ol:_(1),on:this._minDigits(t,t._periods[1],1),onn:this._minDigits(t,t._periods[1],2),onnn:this._minDigits(t,t._periods[1],3),o1:p(t._periods[1],1),o10:p(t._periods[1],10),o100:p(t._periods[1],100),o1000:p(t._periods[1],1e3),wl:_(2),wn:this._minDigits(t,t._periods[2],1),wnn:this._minDigits(t,t._periods[2],2),wnnn:this._minDigits(t,t._periods[2],3),w1:p(t._periods[2],1),w10:p(t._periods[2],10),w100:p(t._periods[2],100),w1000:p(t._periods[2],1e3),dl:_(3),dn:this._minDigits(t,t._periods[3],1),dnn:this._minDigits(t,t._periods[3],2),dnnn:this._minDigits(t,t._periods[3],3),d1:p(t._periods[3],1),d10:p(t._periods[3],10),d100:p(t._periods[3],100),d1000:p(t._periods[3],1e3),hl:_(4),hn:this._minDigits(t,t._periods[4],1),hnn:this._minDigits(t,t._periods[4],2),hnnn:this._minDigits(t,t._periods[4],3),h1:p(t._periods[4],1),h10:p(t._periods[4],10),h100:p(t._periods[4],100),h1000:p(t._periods[4],1e3),ml:_(5),mn:this._minDigits(t,t._periods[5],1),mnn:this._minDigits(t,t._periods[5],2),mnnn:this._minDigits(t,t._periods[5],3),m1:p(t._periods[5],1),m10:p(t._periods[5],10),m100:p(t._periods[5],100),m1000:p(t._periods[5],1e3),sl:_(6),sn:this._minDigits(t,t._periods[6],1),snn:this._minDigits(t,t._periods[6],2),snnn:this._minDigits(t,t._periods[6],3),s1:p(t._periods[6],1),s10:p(t._periods[6],10),s100:p(t._periods[6],100),s1000:p(t._periods[6],1e3)},u=s,d=0;d<=6;d++){var h="yowdhms".charAt(d),m=new RegExp("\\{"+h+"<\\}([\\s\\S]*)\\{"+h+">\\}","g");u=u.replace(m,!o&&i[d]||o&&r[d]?"$1":"")}return e.each(c,function(e,t){var i=new RegExp("\\{"+e+"\\}","g");u=u.replace(i,t)}),u},_minDigits:function(e,t,i){return(t=""+t).length>=i?this._translateDigits(e,t):(t="0000000000"+t,this._translateDigits(e,t.substr(t.length-i)))},_translateDigits:function(e,t){return(""+t).replace(/[0-9]/g,function(t){return e.options.digits[t]})},_determineShow:function(e){var t=e.options.format,i=[];return i[0]=t.match("y")?"?":t.match("Y")?"!":null,i[1]=t.match("o")?"?":t.match("O")?"!":null,i[2]=t.match("w")?"?":t.match("W")?"!":null,i[3]=t.match("d")?"?":t.match("D")?"!":null,i[4]=t.match("h")?"?":t.match("H")?"!":null,i[5]=t.match("m")?"?":t.match("M")?"!":null,i[6]=t.match("s")?"?":t.match("S")?"!":null,i},_calculatePeriods:function(e,t,i,s){e._now=s,e._now.setMilliseconds(0);var n=new Date(e._now.getTime());e._since?s.getTime()e._until.getTime()&&(e._now=s=n));var o=[0,0,0,0,0,0,0];if(t[0]||t[1]){var r=this._getDaysInMonth(s.getFullYear(),s.getMonth()),a=this._getDaysInMonth(n.getFullYear(),n.getMonth()),l=n.getDate()===s.getDate()||n.getDate()>=Math.min(r,a)&&s.getDate()>=Math.min(r,a),_=function(e){return 60*(60*e.getHours()+e.getMinutes())+e.getSeconds()},p=Math.max(0,12*(n.getFullYear()-s.getFullYear())+n.getMonth()-s.getMonth()+(n.getDate()u&&s.setDate(u),s.setFullYear(s.getFullYear()+o[0]),s.setMonth(s.getMonth()+o[1]),c&&s.setDate(u)}var d=Math.floor((n.getTime()-s.getTime())/1e3),h=null,m=function(e,i){o[e]=t[e]?Math.floor(d/i):0,d-=o[e]*i};if(m(2,604800),m(3,86400),m(4,3600),m(5,60),m(6,1),d>0&&!e._since){var g=[1,12,4.3482,7,24,60,60],w=6,f=1;for(h=6;h>=0;h--)t[h]&&(o[w]>=f&&(o[w]=0,d=1),d>0&&(o[h]++,d=0,w=h,f=1)),f*=g[h]}if(i)for(h=0;h<=6;h++)i&&o[h]?i--:i||(o[h]=0);return o}})}(jQuery);