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