 countDownDays = 0;
 countDownHours = 0;
 countDownMinutes = 0;
 countDownSeconds = 0;
 timerId = null;
 $(document).ready(function(){
 	$.getJSON("/feeds/nextRaceCountDown.php?jsoncallback=?", function(data){
 		countDownDays = data.days;
 		countDownHours = data.hours;
 		countDownMinutes = data.mins;
 		countDownSeconds = data.secs;
 		startWith(countDownDays, countDownHours, countDownMinutes, countDownSeconds);
 		timerId = setInterval("countDown()", 1000);
 		//countDown();
 	});
 }
 );

 function startWith(days, hours, minutes, seconds){
 	var hundred = parseInt(days / 100);
 	var ten = parseInt((days - (hundred * 100)) / 10);
 	var unit = parseInt(days - ((ten * 10) + (hundred * 100)));
 	$("span.dayHundreds > img").css("top", -25 * hundred);
 	$("span.dayTens > img").css("top", -25 * ten);
 	$("span.dayUnits > img").css("top", -25 * unit);
 	
 	ten = parseInt(hours / 10);
 	unit = parseInt(hours - (ten * 10))+(((hours==10)||(hours>19)?1:0)*10);
 	$("span.hourTens > img").css("top", -25 * ten);
 	$("span.hourUnits > img").css("top", -25 * unit);
 	
 	ten = parseInt(minutes / 10);
 	unit = parseInt(minutes - (ten * 10));
 	$("span.minuteTens > img").css("top", -25 * ten);
 	$("span.minuteUnits > img").css("top", -25 * unit);
 	
 	ten = parseInt(seconds / 10);
 	unit = parseInt(seconds - (ten * 10));
 	$("span.secondTens > img").css("top", -25 * ten);
 	$("span.secondUnits > img").css("top", -25 * unit);
 }
 
 function countDown(){
 	countDownSeconds--;
 	if (countDownSeconds < 0) {
 		countDownSeconds = 59;
 		countDownMinutes--;
 	}
 	if (countDownMinutes < 0) {
 		countDownMinutes = 59;
 		countDownHours--;
 	}
 	if (countDownHours < 0) {
 		countDownHours = 23;
 		countDownDays--;
 	}
 	seconds = countDownSeconds;
 	minutes = countDownMinutes;
 	hours = countDownHours;
 	days = countDownDays;
 	if ($("span.secondUnits > img").css("top") == "0px") {
 		$("span.secondUnits > img").css("top", -25 * 10);
 		
 		if ($("span.secondTens > img").css("top") == "0px") {
 			$("span.secondTens > img").css("top", -25 * 6);
 			
 			if ($("span.minuteUnits > img").css("top") == "0px") {
 				$("span.minuteUnits > img").css("top", -25 * 10);
 				
 				if ($("span.minuteTens > img").css("top") == "0px") {
 					$("span.minuteTens > img").css("top", -25 * 6);
 					
 					switch (hours) {
 						case 20:
 							$("span.hourUnits > img").css("top", -25 * 10);
 							break;
 						case 10:
 							$("span.hourUnits > img").css("top", -25 * 10);
 							break;
 						case 23:
 							$("span.hourUnits > img").css("top", -25 * 14);
 							break;
 						default:
 							break;
 					}
 					if ($("span.hourTens > img").css("top") == "0px") {
 						$("span.hourTens > img").css("top", -25 * 3);
 					}
 				}
 			}
 		}
 	}
 	
 	if (countDownDays < 0) {
 		clearInterval(timerId);
 		return;
 	}
 	
 	
 	
 	var hundred = parseInt(days / 100);
 	var ten = parseInt((days - (hundred * 100)) / 10);
 	var unit = parseInt(days - ((ten * 10) + (hundred * 100)));
 	$("span.dayHundreds > img").animate({
 		"top": -25 * hundred
 	}, 500);
 	$("span.dayTens > img").animate({
 		"top": -25 * ten
 	}, 500);
 	$("span.dayUnits > img").animate({
 		"top": -25 * unit
 	}, 500);
 	
 	ten = parseInt(hours / 10);
 	unit = parseInt(hours - (ten * 10))+(((hours==10)||(hours>19)?1:0)*10);
 	$("span.hourTens > img").animate({
 		"top": -25 * ten
 	}, 500);
 	$("span.hourUnits > img").animate({
 		"top": -25 * unit
 	}, 500);
 	
 	ten = parseInt(minutes / 10);
 	unit = parseInt(minutes - (ten * 10));
 	$("span.minuteTens > img").animate({
 		"top": -25 * ten
 	}, 500);
 	$("span.minuteUnits > img").animate({
 		"top": -25 * unit
 	}, 500);
 	
 	ten = parseInt(seconds / 10);
 	unit = parseInt(seconds - (ten * 10));
 	$("span.secondTens > img").animate({
 		"top": -25 * ten
 	}, 500);
 	$("span.secondUnits > img").animate({
 		"top": -25 * unit
 	}, 500);
 }

