$(document).ready( function() {
	if ($('[rel=countdown]').length>0) {
		$('[rel=countdown]').countdown();
	}
});

$.fn.countdown = function(cdTimer) {
	if (cdTimer) clearTimeout(cdTimer);
	
	var obj = $(this);
	var destDate = strtotime('2010-09-12 13:00:00');
	var curDate = time();
	
	var left = destDate - curDate;
	if (left<=0) {
		obj.html('C U in 2011!');
		return;
	}
	
	hours =  Math.floor(left/3600);
	minutes = Math.floor((left - (hours*3600)) / 60);
	secondes = left - (hours*3600) - (minutes*60);
	
	obj.html(hours + ':' + minutes + ':' + secondes + ' <span style="font-weight:normal;text-transform:lowercase;">to go</span>');
	
	cdTimer = setTimeout(function(){
		obj.countdown(cdTimer);
	}, 1000);
};
