 
 
function prepareCountdown() {
	if (!document.getElementById) return false;
	if (!document.getElementById('countdown')) return false;
	var $countdown_div = document.getElementById('countdown');
	$countdown_div.timer = setTimeout('countdown();',1000);
}
$(document).ready(function(){
	prepareCountdown();
});
 
function countdown() {
	
	var $countdown_div = document.getElementById('countdown');
	$countdown_div.timer = setTimeout('countdown();',1000);
 
	var $countdown = Array(4);
	$countdown['days'] = parseInt(document.getElementById('countdown-days').childNodes[0].nodeValue,10);
	$countdown['hours'] = parseInt(document.getElementById('countdown-hours').childNodes[0].nodeValue,10);
	$countdown['minutes'] = parseInt(document.getElementById('countdown-minutes').childNodes[0].nodeValue,10);
	$countdown['seconds'] = parseInt(document.getElementById('countdown-seconds').childNodes[0].nodeValue,10);
	//$countdown['milliseconds'] = parseInt(document.getElementById('countdown-milliseconds').childNodes[0].nodeValue);
	
	var $time_remaining = (($countdown['days']*(86400))+($countdown['hours']*(3600))+($countdown['minutes']*(60))+($countdown['seconds']-1));
	
	$countdown['days'] = Math.floor($time_remaining/(86400));
	$countdown['hours'] = Math.floor(($time_remaining -= $countdown['days']*(86400))/3600);
	$countdown['minutes'] = Math.floor(($time_remaining -= $countdown['hours']*(3600))/60);
	$countdown['seconds'] = (($time_remaining -= $countdown['minutes']*(60))/1);
	//$countdown['milliseconds'] = $time_remaining -= $countdown['seconds']*1;
	
	//document.getElementById('countdown-milliseconds').innerHTML = pad($countdown['milliseconds'],2);
	document.getElementById('countdown-seconds').innerHTML = pad($countdown['seconds'],2);
	document.getElementById('countdown-minutes').innerHTML = pad($countdown['minutes'],2);
	document.getElementById('countdown-hours').innerHTML = pad($countdown['hours'],2);
	document.getElementById('countdown-days').innerHTML = pad($countdown['days'],3);
	//document.getElementById('countdown-fakems').innerHTML = Math.floor(Math.random()*10);
}

function pad(number, length) {
   
    var str = '' + number;
    while (str.length < length) {
        str = '0' + str;
    }
   
    return str;

}
/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
**/
 
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}