(function(n){"use strict";typeof define=="function"&&define.amd?define(["jquery"],n):n(jQuery)})(function(n){"use strict";var h=[],l=[],f={precision:100,elapse:!1,defer:!1};l.push(/^[0-9]*$/.source),l.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),l.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),l=new RegExp(l.join("|"));function p(t){if(t instanceof Date)return t;if(String(t).match(l))return String(t).match(/^[0-9]*$/)&&(t=Number(t)),String(t).match(/\-/)&&(t=String(t).replace(/\-/g,"/")),new Date(t);throw new Error("Couldn't cast `"+t+"` to a date object.")}var c={Y:"years",m:"months",n:"daysToMonth",d:"daysToWeek",w:"weeks",W:"weeksToMonth",H:"hours",M:"minutes",S:"seconds",D:"totalDays",I:"totalHours",N:"totalMinutes",T:"totalSeconds"};function d(t){var s=t.toString().replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1");return new RegExp(s)}function w(t){return function(s){var e=s.match(/%(-|!)?[A-Z]{1}(:[^;]+;)?/gi);if(e)for(var i=0,g=e.length;i1?e:i}var r=function(t,s,e){this.el=t,this.$el=n(t),this.interval=null,this.offset={},this.options=n.extend({},f),this.instanceNumber=h.length,h.push(this),this.$el.data("countdown-instance",this.instanceNumber),e&&(typeof e=="function"?(this.$el.on("update.countdown",e),this.$el.on("stoped.countdown",e),this.$el.on("finish.countdown",e)):this.options=n.extend({},f,e)),this.setFinalDate(s),this.options.defer===!1&&this.start()};n.extend(r.prototype,{start:function(){this.interval!==null&&clearInterval(this.interval);var t=this;this.update(),this.interval=setInterval(function(){t.update.call(t)},this.options.precision)},stop:function(){clearInterval(this.interval),this.interval=null,this.dispatchEvent("stoped")},toggle:function(){this.interval?this.stop():this.start()},pause:function(){this.stop()},resume:function(){this.start()},remove:function(){this.stop.call(this),h[this.instanceNumber]=null,delete this.$el.data().countdownInstance},setFinalDate:function(t){this.finalDate=p(t)},update:function(){if(this.$el.closest("html").length===0){this.remove();return}var t=n._data(this.el,"events")!==void 0,s=new Date,e;e=this.finalDate.getTime()-s.getTime(),e=Math.ceil(e/1e3),e=!this.options.elapse&&e<0?0:Math.abs(e),!(this.totalSecsLeft===e||!t)&&(this.totalSecsLeft=e,this.elapsed=s>=this.finalDate,this.offset={seconds:this.totalSecsLeft%60,minutes:Math.floor(this.totalSecsLeft/60)%60,hours:Math.floor(this.totalSecsLeft/60/60)%24,days:Math.floor(this.totalSecsLeft/60/60/24)%7,daysToWeek:Math.floor(this.totalSecsLeft/60/60/24)%7,daysToMonth:Math.floor(this.totalSecsLeft/60/60/24%30.4368),weeks:Math.floor(this.totalSecsLeft/60/60/24/7),weeksToMonth:Math.floor(this.totalSecsLeft/60/60/24/7)%4,months:Math.floor(this.totalSecsLeft/60/60/24/30.4368),years:Math.abs(this.finalDate.getFullYear()-s.getFullYear()),totalDays:Math.floor(this.totalSecsLeft/60/60/24),totalHours:Math.floor(this.totalSecsLeft/60/60),totalMinutes:Math.floor(this.totalSecsLeft/60),totalSeconds:this.totalSecsLeft},!this.options.elapse&&this.totalSecsLeft===0?(this.stop(),this.dispatchEvent("finish")):this.dispatchEvent("update"))},dispatchEvent:function(t){var s=n.Event(t+".countdown");s.finalDate=this.finalDate,s.elapsed=this.elapsed,s.offset=n.extend({},this.offset),s.strftime=w(this.offset),this.$el.trigger(s)}}),n.fn.countdown=function(){var t=Array.prototype.slice.call(arguments,0);return this.each(function(){var s=n(this).data("countdown-instance");if(s!==void 0){var e=h[s],i=t[0];r.prototype.hasOwnProperty(i)?e[i].apply(e,t.slice(1)):String(i).match(/^[$A-Z_][0-9A-Z_$]*$/i)===null?(e.setFinalDate.call(e,i),e.start()):n.error("Method %s does not exist on jQuery.countdown".replace(/\%s/gi,i))}else new r(this,t[0],t[1])})}});