var melTimer = 0;

//countdown_clock(2006,11,29,2006,12,6,00,00,00);
function countdown_clock(sYr,sMo,sDay,dYr,dMo,dDay,dHr,dMin,dSec){
	Today = new Date();
	Todays_Year = Today.getFullYear() - 2000;
	Todays_Month = Today.getMonth() + 1;
	//Computes the time difference between the client computer and the server.
	Server_Date = (new Date((sYr - 2000), sMo, sDay, 0, 0, 0)).getTime();
	Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(),Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();

	countdown(dYr, dMo, dDay, dHr, dMin, dSec,(Todays_Date - Server_Date), sYr);                
}

function countdown(year, month, day, hour, minute, seconds, time_difference, yeartoday){
	Today = new Date();
	Todays_Year = Today.getYear() - 2000;
	Todays_Month = Today.getMonth() + 1;
	//		console.log(day + ' : ' +Todays_Month);
	//Convert today's date and the target date into miliseconds.
	Todays_Date = (new Date(yeartoday, Todays_Month, Today.getDate(),
	Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();
	Target_Date = (new Date(year, month, day, hour, minute, seconds)).getTime();

	//Find their difference, and convert that into seconds.
	//Taking into account the time differential between the client computer and the server.
	var timeLeft = Math.round((Target_Date - Todays_Date) / 1000);
//	console.log('timeLeft : ' + timeLeft);
	//timeLeft = 0;
		var dayimg = '';
		var hoursimg = '';
		var minutesimg = '';
		var secondimg = '';
		var days_of_month = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
		dt = new Date(); // today's date.
		if((dt.getYear()%4==0)&&((dt.getYear()%100!=0)||(dt.getYear()%400==0))) days_of_month[1] = 29;//  if it's a leap year
		
	if(timeLeft > 0){
		var gday = (Today.getDate()>day)?(day+days_of_month[Todays_Month-1]):day;
		
		var day2 = gday - Today.getDate() -1;
//		console.log(day + ' : ' +Todays_Month);
		//More datailed.
		var dayimg = '';
		var day2 = ""+day2;
		if(day2.length == 1){ dayimg += '<strong class="countdown-0">0</strong><strong class="countdown-'+day2+'">'+day2+'</strong>';	}
		else{ for(i = 0; i < day2.length; i++){	dayimg += '<strong class="countdown-'+day2.charAt(i)+'">'+day2.charAt(i)+'</strong>';	}	}
		timeLeft %= (60 * 60 * 24);
		hours = Math.floor(timeLeft / (60 * 60));
//		console.log('timeLeft : ' + timeLeft );
//		console.log('hours : ' + Today.getHours() );
		hours += '';
		var hoursimg = '';
		if(hours.length == 1){ hoursimg += '<strong class="countdown-0">0</strong><strong class="countdown-'+hours+'">'+hours+'</strong>'; }
		else{	for(i = 0; i < hours.length; i++){ hoursimg += '<strong class="countdown-'+hours.charAt(i)+'">'+hours.charAt(i)+'</strong>';}	}
		timeLeft %= (60 * 60);
		minutes = Math.floor(timeLeft / 60);
		minutes += '';
		var minutesimg = '';
		if(minutes.length == 1){minutesimg += '<strong class="countdown-0">0</strong><strong class="countdown-'+minutes+'">'+minutes+'</strong>';	}
		else{	for(i = 0; i < minutes.length; i++){minutesimg += '<strong class="countdown-'+minutes.charAt(i)+'">'+minutes.charAt(i)+'</strong>';	}	}
		timeLeft %= 60;
		second = timeLeft;
		second += '';
		var secondimg = '';
		if(second.length == 1){	secondimg += '<strong class="countdown-0">0</strong><strong class="countdown-'+second+'">'+second+'</strong>'; }
		else{	for(i = 0; i < second.length; i++){	secondimg += '<strong class="countdown-'+second.charAt(i)+'">'+second.charAt(i)+'</strong>';}}
		$('countdown').innerHTML = '<sp'+'an id="dayimg">' + dayimg +'</sp'+'an>';
		$('countdown').innerHTML += '<sp'+'an id="hoursimg">'+ hoursimg + '</sp'+'an>';
		$('countdown').innerHTML += '<sp'+'an id="minutesimg">'+minutesimg + '</sp'+'an>';
		$('countdown').innerHTML += '<sp'+'an id="secondimg">'+secondimg + '</sp'+'an>';
		//Recursive call, keeps the clock ticking.
		melTimer = setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + seconds + ',' + time_difference + ',' + yeartoday + ');', 1000);
	}else{
		refreshFotw();
	}
}