!function(b){"function"==typeof define&&define.amd?define(["jquery"],b):b(jQuery)}(function(t){function s(b){if(b instanceof Date){return b}if(String(b).match(n)){return String(b).match(/^[0-9]*$/)&&(b=Number(b)),String(b).match(/\-/)&&(b=String(b).replace(/\-/g,"/")),new Date(b)}throw new Error("Couldn't cast `"+b+"` to a date object.")}function r(d){var c=d.toString().replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1");return new RegExp(c)}function q(b){return function(y){var x=y.match(/%(-|!)?[A-Z]{1}(:[^;]+;)?/gi);if(x){for(var w=0,v=x.length;w1?h:g}var o=[],n=[],m={precision:100,elapse:!1,defer:!1};n.push(/^[0-9]*$/.source),n.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),n.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),n=new RegExp(n.join("|"));var l={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"},k=function(a,f,e){this.el=a,this.$el=t(a),this.interval=null,this.offset={},this.options=t.extend({},m),this.instanceNumber=o.length,o.push(this),this.$el.data("countdown-instance",this.instanceNumber),e&&("function"==typeof e?(this.$el.on("update.countdown",e),this.$el.on("stoped.countdown",e),this.$el.on("finish.countdown",e)):this.options=t.extend({},m,e)),this.setFinalDate(f),this.options.defer===!1&&this.start()};t.extend(k.prototype,{start:function(){null!==this.interval&&clearInterval(this.interval);var b=this;this.update(),this.interval=setInterval(function(){b.update.call(b)},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),o[this.instanceNumber]=null,delete this.$el.data().countdownInstance},setFinalDate:function(b){this.finalDate=s(b)},update:function(){if(0===this.$el.closest("html").length){return void this.remove()}var a,f=void 0!==t._data(this.el,"events"),e=new Date;a=this.finalDate.getTime()-e.getTime(),a=Math.ceil(a/1000),a=!this.options.elapse&&a<0?0:Math.abs(a),this.totalSecsLeft!==a&&f&&(this.totalSecsLeft=a,this.elapsed=e>=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()-e.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||0!==this.totalSecsLeft?this.dispatchEvent("update"):(this.stop(),this.dispatchEvent("finish")))},dispatchEvent:function(a){var d=t.Event(a+".countdown");d.finalDate=this.finalDate,d.elapsed=this.elapsed,d.offset=t.extend({},this.offset),d.strftime=q(this.offset),this.$el.trigger(d)}}),t.fn.countdown=function(){var a=Array.prototype.slice.call(arguments,0);return this.each(function(){var g=t(this).data("countdown-instance");if(void 0!==g){var f=o[g],b=a[0];k.prototype.hasOwnProperty(b)?f[b].apply(f,a.slice(1)):null===String(b).match(/^[$A-Z_][0-9A-Z_$]*$/i)?(f.setFinalDate.call(f,b),f.start()):t.error("Method %s does not exist on jQuery.countdown".replace(/\%s/gi,b))}else{new k(this,a[0],a[1])}})}});