var Countdown =
{
timer: null,
init: function(id, until) {
    Countdown.node = document.getElementById(id);
    Countdown.update(until);
    Countdown.timer = setInterval(function() {
        Countdown.update(until);
    }, 1000);
},

stop: function() {
    clearInterval(Countdown.timer);
    return true;
},

update: function(until) {

    var s = Countdown.process(new Date(), until);
    Countdown.node.innerHTML = s || Countdown.stop() && 'Всё :)';
},

difference: function(before, after)
{
if (after < before) return false;
var
days = after.getDate() - before.getDate(),
months = after.getMonth() - before.getMonth(),
years = after.getYear() - before.getYear(),
hms = (after / 1000 - before / 1000) % 86400,

seconds = Math.floor(hms % 60),
minutes = Math.floor(hms/60) % 60,
hours = Math.floor(hms/3600) % 60,

date = new Date();

if (days < 0)
{
date.setFullYear(before.getYear(), before.getMonth(), 32);
days += 32 - date.getDate();
months--;
}

if (months < 0)
{
months += 12;
years--;
}

return {
years: years,
months: months,
days: days,

hours: hours,
minutes: minutes,
seconds: seconds
};
},

process: function(before, after)
{
var diff = null, a = [], i = '';
if(!(diff = Countdown.difference(before, after))) return false;

for(i in diff)
{
if(!diff[i]) continue;
a.push('<span class="num">'
+ diff[i] +
'</span><span class="unit">'
+ Countdown.lang[i][Countdown.lang.choose( diff[i] )] +
'</span>');
}

return a.join(' ');
},

lang:
{
years: ['&nbsp;год', '&nbsp;года', '&nbsp;лет'],
months: ['&nbsp;месяц', '&nbsp;месяца', '&nbsp;месяцев'],
days: ['&nbsp;день', '&nbsp;дня', '&nbsp;дней'],
hours: ['&nbsp;час', '&nbsp;часа', '&nbsp;часов'],
minutes: ['&nbsp;минута', '&nbsp;минуты', '&nbsp;минут'],
seconds: ['&nbsp;секунда', '&nbsp;секунды', '&nbsp;секунд'],
choose: function(n)
{
var m = n % 100, i = 2;
if(m < 5 || 20 < m)
{
if((m %= 10) === 1)
{
i = 0;
}
else if(1 < m && m < 5)
{
i = 1;
}
}
return i;
}
}
};

window.onload = function()
{
Countdown.init('countbox', new Date(2010, 02, 30, 0, 0, 00));
};