
target = new Date("10 February, 2011"); 
tzAdjustSecs = target.getTimezoneOffset() * 60;
targetEpoch = target.getTime();
/* for some reason this is not returning the right stuff... */
targetEpoch -= tzAdjustSecs;

timeFormat = function(time) {
    if (time < 10) {
        return "0" + time;
    }
    return time;
};

onCelebration = function(secs) {
    if(secs < 0) {
        $('body').css('background', 'url("pandag.jpg")');
        //$('body').css('background-size', '100%');
        return "Happy Birthday GG!<br/>";
    }
    return "";
};

updateTime = function() {
    var today = new Date();
    var todayEpoch  = today.getTime();
    todayEpoch -= tzAdjustSecs;

    if(targetEpoch < todayEpoch) {
        var secsTotal = Math.floor((todayEpoch - targetEpoch) / 1000);
        var dsecs = -secsTotal;
    }
    else {
        var secsTotal = Math.floor((targetEpoch - todayEpoch) / 1000);
        var dsecs = secsTotal;
    }

    var days = Math.floor(secsTotal / 86400);
    var secsRemain = Math.floor(secsTotal % 86400);
    var hours = Math.floor((secsRemain / 3600));
    var minutes = Math.floor((secsRemain % 3600) / 60);
    var seconds = Math.floor((secsRemain % 3600) % 60);

    var timestr = timeFormat(hours) + ":" + timeFormat(minutes) + ":" + timeFormat(seconds);
    var msg = onCelebration(dsecs);
    document.getElementById("countdown").innerHTML = msg + days +" days, " + timestr;
    var timeout=setTimeout("updateTime()",500);
};

