var JUHPCountdownx = $.klass({
	initialize : function(e){
		this.element= $(e);
		this.time = parseInt(this.element.attr('rel'));
		this.tick();
	},
	tick : function(){
		if (this.time == 0)
			this.time = 86400;
		var dd = this.time % 86400;
		var dm = dd % 3600;
		var ds = dm % 60;
		var da = {
			d : Math.floor(this.time / 86400),
			h : Math.floor(dd / 3600),
			m : Math.floor(dm / 60),
			s : Math.ceil(ds)
		}
		this.element.html((da.d == 0 ? '' : da.d + ':') +
					(da.h==0 ? '00' : (da.h < 10 ? '0' : '') + da.h) + ':' +
					(da.m==0 ? '00' : (da.m < 10 ? '0' : '') + da.m) + ':' +
					(da.s==0 ? '00' : (da.s < 10 ? '0' : '') + da.s))
		this.time--;
		var _this = this;
		setTimeout(function(){_this.tick();},1000);
	}
});
$(document).ready(function(){
	$('span.juhp-countdownx').each(function(i,e){
		new JUHPCountdownx(e);
	});
});
