if (document.images) {
    var imgArray = new Array();
    imgArray[0] = new Image();
    imgArray[0].src = "images/timer/0.png";
    imgArray[1] = new Image();
    imgArray[1].src = "images/timer/1.png";
    imgArray[2] = new Image();
    imgArray[2].src = "images/timer/2.png";
    imgArray[3] = new Image();
    imgArray[3].src = "images/timer/3.png";
    imgArray[4] = new Image();
    imgArray[4].src = "images/timer/4.png";
    imgArray[5] = new Image();
    imgArray[5].src = "images/timer/5.png";
    imgArray[6] = new Image();
    imgArray[6].src = "images/timer/6.png";
    imgArray[7] = new Image();
    imgArray[7].src = "images/timer/7.png";
    imgArray[8] = new Image();
    imgArray[8].src = "images/timer/8.png";
    imgArray[9] = new Image();
    imgArray[9].src = "images/timer/9.png";
}

var targetYear=2010, targetMonth=4, targetDay=25, targetHour=10, targetMinute=0, targetSecond=0;

var targetDate = new Date(targetYear,targetMonth-1,targetDay,targetHour,targetMinute,targetSecond);
var oneSec = 1000;
var oneMin = 60 * oneSec;
var oneHr = 60 * oneMin;
var oneDay = 24 * oneHr;

function countDown() {
	var currentDate = new Date();
	var targetInMS = targetDate.getTime();
    
    // month left
    var monthsLeft = 0;
//alert(currentDate < targetDate);

    while(currentDate < targetDate){
	    	monthsLeft++;
    	currentDate.setMonth(currentDate.getMonth()+1);
	//alert(monthsLeft);
    }
    currentDate.setMonth(currentDate.getMonth()-1);
    var nowInMS = currentDate.getTime();
    monthsLeft--;
	
    var diff = targetInMS - nowInMS;
    
    // days left
    var scratchPad = diff / oneDay;
    var daysLeft = Math.floor(scratchPad);
    // hours left
    diff -= (daysLeft * oneDay);
    scratchPad = diff / oneHr;
    var hrsLeft = Math.floor(scratchPad);
    // minutes left
    diff -= (hrsLeft * oneHr);
    scratchPad = diff / oneMin;
    var minsLeft = Math.floor(scratchPad);
    // seconds left
    diff -= (minsLeft * oneMin);
    scratchPad = diff / oneSec;
    var secsLeft = Math.floor(scratchPad);
    // now adjust images
    setImages(monthsLeft,daysLeft, hrsLeft, minsLeft, secsLeft);
}

function setImages(months,days, hrs, mins, secs) {
    
    var i;
    months = formatNum(months,2);

    for (i = 0; i < months.length; i++) {
	pos = parseInt(months.charAt(i));
        document.images["months" + i].src = imgArray[pos].src;
    }
    days = formatNum(days, 2); 
    for (i = 0; i < days.length; i++) {
        document.images["days" + i].src = imgArray[parseInt(days.charAt(i))].src;
    }
    hrs = formatNum(hrs, 2);
    for (i = 0; i < hrs.length; i++) {
        document.images["hours" + i].src = imgArray[parseInt(hrs.charAt(i))].src;
    }
    mins = formatNum(mins, 2);
    for (i = 0; i < mins.length; i++) {
        document.images["minutes" + i].src = imgArray[parseInt(mins.charAt(i))].src;
    }
    secs = formatNum(secs, 2);
    for (i = 0; i < secs.length; i++) {
        document.images["seconds" + i].src = imgArray[parseInt(secs.charAt(i))].src;
    }
}

function formatNum(num, len) {
    
var intnum = parseInt(num);
    if(intnum<0) num=intnum+12;
    var numStr = "" + num;
    while (numStr.length < len) {
        numStr = "0" + numStr;
    }
    return numStr
}
window.onload = function() {setInterval('countDown()', 1000)};

function debug(){
var currentDate = new Date();

alert(targetDate);
alert(currentDate);
alert(currentDate<targetDate);
}