/* http://keith-wood.name/countdown.html
   Countdown for jQuery v1.2.0.
   Written by Keith Wood (kbwood@virginbroadband.com.au) January 2008.
   Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and 
   MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses. 
   Please attribute the author if you use it. */
(function($){function Countdown(){this._nextId=0;this._inst=[];this.regional=[];this.regional['']={labels:['Years','Months','Weeks','Days','Hours','Minutes','Seconds'],compactLabels:['y','m','w','d'],timeSeparator:':'};this._defaults={format:'dHMS',compact:false,description:'',expiryUrl:null,onExpiry:null,onTick:null};$.extend(this._defaults,this.regional['']);}$.extend(Countdown.prototype,{markerClassName:'hasCountdown',_register:function(inst){var id=this._nextId++;this._inst[id]=inst;return id;},_getInst:function(id){return this._inst[id]||id;},setDefaults:function(settings){extendRemove(this._defaults,settings||{});},_attachCountdown:function(target,inst){target=$(target);if (target.is('.'+this.markerClassName)){return;}target.addClass(this.markerClassName);target[0]._cdnId=inst._id;inst._target=target;this._updateCountdown(inst._id);},_updateCountdown:function(id){var inst=this._getInst(id);inst._target.html(inst._generateHTML());var onTick=inst._get('onTick');if (onTick){onTick.apply(inst._target[0],[inst._periods]);}var since=inst._get('since');var expired=(since?inst._now.getTime()<=since.getTime():inst._now.getTime()>=inst._getUntil(inst._now).getTime());if (expired){if (inst._timer){var onExpiry=inst._get('onExpiry');if (onExpiry){onExpiry.apply(inst._target[0],[]);}var expiryUrl=inst._get('expiryUrl');if (expiryUrl){window.location=expiryUrl;}}inst._timer=null;}else {inst._timer=setTimeout('$.countdown._updateCountdown('+inst._id+')',(inst._get('format').match('s|S')?1:30) * 980);}},_changeCountdown:function(target,settings){var inst=this._getInst(target._cdnId);if (inst){extendRemove(inst._settings,settings||{});this._updateCountdown(inst._id);}},_destroyCountdown:function(target){target=$(target);if (!target.is('.'+this.markerClassName)){return;}target.removeClass(this.markerClassName);target.empty();clearTimeout(this._inst[target[0]._cdnId]._timer);this._inst[target[0]._cdnId]=null;target[0]._cdnId=undefined;}});var Y=0;var O=1;var W=2;var D=3;var H=4;var M=5;var S=6;function CountdownInstance(settings){this._id=$.countdown._register(this);this._target=null;this._timer=null;this._now=null;this._periods=[0,0,0,0,0,0,0];this._settings=extendRemove({},settings||{});}$.extend(CountdownInstance.prototype,{_get:function(name){return (this._settings[name] !=null?this._settings[name]:$.countdown._defaults[name]);},_generateHTML:function(){var format=this._get('format');var show=[];show[Y]=(format.match('y')?'?':(format.match('Y')?'!':null));show[O]=(format.match('o')?'?':(format.match('O')?'!':null));show[W]=(format.match('w')?'?':(format.match('W')?'!':null));show[D]=(format.match('d')?'?':(format.match('D')?'!':null));show[H]=(format.match('h')?'?':(format.match('H')?'!':null));show[M]=(format.match('m')?'?':(format.match('M')?'!':null));show[S]=(format.match('s')?'?':(format.match('S')?'!':null));this._periods=periods=this._calculatePeriods(show,new Date());var shownNonZero=false;var showCount=0;for (var period=0;period<show.length;period++){shownNonZero|=(show[period]=='?'&&periods[period]>0);show[period]=(show[period]=='?'&&!shownNonZero?null:show[period]);showCount+=(show[period]?1:0);}var compact=this._get('compact');var labels=(compact?this._get('compactLabels'):this._get('labels'));var labels1=this._get('labels1');var labels2=this._get('labels2');var timeSeparator=this._get('timeSeparator');var description=this._get('description')||'';var twoDigits=function(value){return (value<10?'0':'')+value;};var showCompact=function(period){return (show[period]?periods[period]+labels[period]+' ':'');};var showFull=function(period){if (periods[period]==1){var labelss=labels1;}else if (periods[period]>1&&periods[period]<5){var labelss=labels2;}else {var labelss=labels;}return (show[period]?'<em class="countdown_section"><span class="countdown_amount">'+periods[period]+'</span><br/>'+labelss[period]+'</em>':'');};return (compact?'<em class="countdown_row countdown_amount">'+showCompact(Y)+showCompact(O)+showCompact(W)+showCompact(D)+twoDigits(this._periods[H])+timeSeparator+twoDigits(this._periods[M])+(show[S]?timeSeparator+twoDigits(this._periods[S]):''):'<em class="countdown_row countdown_show'+showCount+'">'+showFull(Y)+showFull(O)+showFull(W)+showFull(D)+showFull(H)+showFull(M)+showFull(S))+'</em>'+(description?'<em class="countdown_row countdown_descr">'+description+'</em>':'');},_calculatePeriods:function(show,now){this._now=now;this._now.setMilliseconds(0);var until=this._getUntil(now);if (now.getTime()>until.getTime()){this._now=now=until;}var since=this._get('since');if (since){since.setMilliseconds(0);}if (since&&now.getTime()<since.getTime()){this._now=now=since;}if (since){until=now;now=since;}var periods=[0,0,0,0,0,0,0];if (show[Y]||show[O]){var months=Math.max(0,(until.getFullYear()-now.getFullYear()) * 12+until.getMonth()-now.getMonth()+(until.getDate()<now.getDate()?-1:0));periods[Y]=(show[Y]?Math.floor(months / 12):0);periods[O]=(show[O]?months-periods[Y] * 12:0);now=new Date(now.getTime());now.setFullYear(now.getFullYear()+periods[Y]);now.setMonth(now.getMonth()+periods[O]);}var diff=Math.floor((until.getTime()-now.getTime()) / 1000);var extractPeriod=function(period,numSecs){periods[period]=(show[period]?Math.floor(diff / numSecs):0);diff-=periods[period] * numSecs;};extractPeriod(W,604800);extractPeriod(D,86400);extractPeriod(H,3600);extractPeriod(M,60);extractPeriod(S,1);return periods;},_getUntil:function(now){var until=this._get('until')||now;until.setMilliseconds(0);return until;}});function extendRemove(target,props){$.extend(target,props);for (var name in props){if (props[name]==null){target[name]=null;}}return target;}$.fn.countdown=function(options){var otherArgs=Array.prototype.slice.call(arguments,1);return this.each(function(){if (typeof options=='string'){$.countdown['_'+options+'Countdown'].apply($.countdown,[this].concat(otherArgs));}else {$.countdown._attachCountdown(this,new CountdownInstance(options));}});};$(function(){$.countdown=new Countdown();});})(jQuery);