!function(e,t,n,s){"use strict";function l(t,n){this.$element=t,this.settings=e.extend({},a,n),this._defaults=a,this._name=i,this._serverDate=null,this._javaScriptDate=null,this.currentDate=null,this.targetDate=null,this.days=null,this.hours=null,this.minutes=null,this.seconds=null,this.deciseconds=null,this.milliseconds=null,this.daysLabel=null,this.hoursLabel=null,this.minutesLabel=null,this.secondsLabel=null,this.decisecondsLabel=null,this.millisecondsLabel=null,this._intervalId=null,this._wrapsExists={},this._oldValues={},this._changed=!1,this.init()}var i="WpcdtClock",a={day:1,month:1,year:2050,hour:0,minute:0,second:0,millisecond:0,timeZone:null,countUp:!1,currentDateTime:null,daysWrapper:".ce-days",hoursWrapper:".ce-hours",minutesWrapper:".ce-minutes",secondsWrapper:".ce-seconds",decisecondsWrapper:".ce-dseconds",millisecondsWrapper:".ce-mseconds",daysLabelWrapper:".ce-days-label",hoursLabelWrapper:".ce-hours-label",minutesLabelWrapper:".ce-minutes-label",secondsLabelWrapper:".ce-seconds-label",decisecondsLabelWrapper:".ce-dseconds-label",millisecondsLabelWrapper:".ce-mseconds-label",singularLabels:!1,daysLabel:"Days",dayLabel:"Day",hoursLabel:"Hours",hourLabel:"Hour",minutesLabel:"Minutes",minuteLabel:"Minute",secondsLabel:"Seconds",secondLabel:"Second",decisecondsLabel:"Deciseconds",decisecondLabel:"Decisecond",millisecondsLabel:"Milliseconds",millisecondLabel:"Millisecond",timeout:1e3,highspeedTimeout:4,leftHandZeros:!0,wrapDigits:!0,wrapDigitsTag:"span",dayInMilliseconds:864e5,hourInMilliseconds:36e5,minuteInMilliseconds:6e4,secondInMilliseconds:1e3,decisecondInMilliseconds:100,onInit:null,beforeCalculation:null,afterCalculation:null,onChange:null,onComplete:null};l.prototype={init:function(){var t=this,n=t.$element,s=t.settings;(e(n).find(s.decisecondsWrapper).length>0||e(n).find(s.millisecondsWrapper).length>0)&&(s.timeout=s.highspeedTimeout),null!=s.currentDateTime&&t.setCurrentDate(s.currentDateTime),"function"==typeof s.onInit&&s.onInit.call(t),t._intervalId=setInterval(function(){t.calculate()},s.timeout),t.calculate()},calculate:function(){var t=this,n=t.settings,s=n.dayInMilliseconds,l=n.hourInMilliseconds,i=n.minuteInMilliseconds,a=n.secondInMilliseconds,o=n.decisecondInMilliseconds,r=!1;t._changed=!1,t.setTargetDate(new Date(n.year,n.month-1,n.day,n.hour,n.minute,n.second)),"function"==typeof n.beforeCalculation&&n.beforeCalculation.call(t);var u=t.getCurrentDate(),c=t.getTargetDate(),d=u.getTime(),h=null===n.timeZone?0:(c.getTimezoneOffset()/60+n.timeZone)*n.hourInMilliseconds,m=c.getTime()-h-d,p=m;t.currentDate=u;var g=t.round(p/s);p%=s;var b=t.round(p/l);p%=l;var f=t.round(p/i);p%=i;var L=t.round(p/a),D=p%a,_=t.round(D/o);0==n.countUp?(g=t.naturalNum(g),b=t.naturalNum(b),f=t.naturalNum(f),L=t.naturalNum(L),D=t.naturalNum(D),_=t.naturalNum(_)):(g*=-1,b*=-1,f*=-1,L*=-1,D*=-1,_*=-1),t.days=g,t.hours=b,t.minutes=f,t.seconds=L,t.milliseconds=D,t.deciseconds=_,t.format(),t.output(),Math.floor(m/n.timeout)<=0&&0==n.countUp&&(r=!0,null==n.millisecondsWrapper&&null==n.decisecondsWrapper||(r=m<=0)),1==r&&("function"==typeof n.onComplete&&n.onComplete.call(t),clearInterval(t._intervalId)),"function"==typeof n.afterCalculation&&n.afterCalculation.call(t)},format:function(){var e=this,t=e.settings,n=t.singularLabels,s=e.days,l=e.hours,i=e.minutes,a=e.seconds,o=e.deciseconds,r=e.milliseconds,u=t.dayLabel,c=t.hourLabel,d=t.minuteLabel,h=t.secondLabel,m=t.decisecondLabel,p=t.millisecondsLabel;1==t.leftHandZeros&&(e.days=e.strPad(s,2),e.hours=e.strPad(l,2),e.minutes=e.strPad(i,2),e.seconds=e.strPad(a,2),e.milliseconds=e.strPad(r,3)),e.daysLabel=1==s&&null!==u&&1==n?u:t.daysLabel,e.hoursLabel=1==l&&null!==c&&1==n?c:t.hoursLabel,e.minutesLabel=1==i&&null!==d&&1==n?d:t.minutesLabel,e.secondsLabel=1==a&&null!==h&&1==n?h:t.secondsLabel,e.decisecondsLabel=1==o&&null!==m&&1==n?m:t.decisecondsLabel,e.millisecondsLabel=1==r&&null!==p&&1==n?p:t.millisecondsLabel},output:function(){var t=this,n=t.settings;t.writeLabelToDom(n.daysLabelWrapper,t.daysLabel),t.writeLabelToDom(n.hoursLabelWrapper,t.hoursLabel),t.writeLabelToDom(n.minutesLabelWrapper,t.minutesLabel),t.writeLabelToDom(n.secondsLabelWrapper,t.secondsLabel),t.writeLabelToDom(n.decisecondsLabelWrapper,t.decisecondsLabel),t.writeLabelToDom(n.millisecondsLabelWrapper,t.millisecondsLabel),t.writeDigitsToDom(n.daysWrapper,t.days,"ce-days-digit"),t.writeDigitsToDom(n.hoursWrapper,t.hours,"ce-hours-digit"),t.writeDigitsToDom(n.minutesWrapper,t.minutes,"ce-minutes-digit"),t.writeDigitsToDom(n.secondsWrapper,t.seconds,"ce-seconds-digit"),t.writeDigitsToDom(n.decisecondsWrapper,t.deciseconds,"ce-dseconds-digit"),t.writeDigitsToDom(n.millisecondsWrapper,t.milliseconds,"ce-mseconds-digit"),"function"==typeof n.onChange&&1==t._changed&&n.onChange.call(t)},pause:function(){var e=this._intervalId;e&&clearInterval(e)},resume:function(){var e=this,t=e.settings;e._intervalId=setInterval(function(){e.calculate()},t.timeout)},destroy:function(){var e=this._intervalId;e&&clearInterval(e)},getOption:function(e){return this.settings[e]},setOption:function(e,t){this.settings[e]=t,"currentDateTime"==e&&this.setCurrentDate(t)},setTargetDate:function(e){this.targetDate=e},getTargetDate:function(){return this.targetDate},setCurrentDate:function(e){this._serverDate=new Date(e),this._javaScriptDate=new Date},getCurrentDate:function(){var e,t,n=this;return null!=n.settings.currentDateTime?(e=n._serverDate-n._javaScriptDate,t=(new Date).getTime(),new Date(t+e)):new Date},round:function(e){return 0==this.settings.countUp?Math.floor(e):Math.ceil(e)},naturalNum:function(e){return e<0?0:e},strPad:function(e,t,n){var s=e.toString();for(n||(n="0");s.length<t;)s=n+s;return s},writeLabelToDom:function(t,n){var s=this,l=e(s.$element);null==s._wrapsExists[t]&&(s._wrapsExists[t]=l.find(t).length>0),s._oldValues[t]!=n&&s._wrapsExists[t]&&(s._oldValues[t]=n,l.find(t).text(n),s._changed=!0)},writeDigitsToDom:function(t,n,s){var l,i,a=this,o=a.settings,r=o.wrapDigitsTag,u=e(a.$element).find(t),n=n.toString(),c=[];if(null==a._wrapsExists[t]&&(a._wrapsExists[t]=u.length>0),0==a._wrapsExists[t])return!1;if(1==o.wrapDigits)for(h=0;h<n.length;h++)c[h]=n[h];else c[0]=n;if(void 0===a._oldValues[t]&&(a._oldValues[t]=[]),a._oldValues[t].length>c.length){i=a._oldValues[t].length-c.length,(l=u.find(r)).slice(0,i).remove(),l=u.find(r);for(h=0;h<c.length;h++)l.eq(h).text(c[h]);a._changed=!0}if(a._oldValues[t].length<c.length){if(0==o.wrapDigits)u.text(c[0]);else{0==a._oldValues[t].length&&u.text("");for(var d="",h=0;h<c.length;h++)h<(i=c.length-a._oldValues[t].length)?d+="<"+r+' class="'+s+'">'+c[h]+"</"+r+">":(l=u.find(r)).eq(h-i).text(c[h]);u.prepend(d)}a._changed=!0}if(a._oldValues[t].length==c.length)if(0==o.wrapDigits)a._oldValues[t][0]!=c[0]&&(u.text(c[0]),a._changed=!0);else for(h=0;h<c.length;h++)a._oldValues[t][h]!=c[h]&&((l=u.find(r)).eq(h).text(c[h]),a._changed=!0);a._oldValues[t]=[];for(h=0;h<c.length;h++)a._oldValues[t][h]=c[h]}},e.fn[i]=function(t,n,s){var a=null,o=this.each(function(){var o=null;if(e.data(this,i)){if(o=e.data(this,i),"destroy"===t)return o.destroy(),void e.data(this,i,null);var r=o[t];return"function"==typeof r&&(a=r.call(o,n,s)),!1}o=new l(this,t),e.data(this,i,o)});return a||o}}(jQuery,window,document);