Помогите пожалуйста с javascript "обратный отчет"

Z
На сайте с 15.02.2012
Offline
63
378

Помогите пожалуйста. Нужен яваскрипт, обратный отчет, как на http://1001golos.ru/, скрипт должен брать из базы данных дату пупликации и дату окончания "битвы", и по окончанию времени обновить запись в таблице и установить статус "closed".

Есть вот такой скрипт, но не работает...

BackCounter = new Class({

Implements: [Options, Events],
options: {
update: 1000,
big_format: "{D} {H} {M} {S}",
small_format: "<span class='number'>{number}</span> <span class='word'>{word}</span>",
lang: {
d: { 0: "Day", 1: "Days", 2: "Days" },
h: { 0: "Hour", 1: "Hours", 2: "Hours" },
m: { 0: "Minute", 1: "Minutes", 2: "Minutes" },
s: { 0: "Second", 1: "Seconds", 2: "Seconds" }
}
},
initialize: function(elements, options) {
this.setOptions(options);
this.finished = [];
this.elements = elements
},
start: function() {
if( ! this.elements) return;
this.timer = setTimeout(function(){
this.elements.each(function(item){
var date_to = item.get('data-to').toInt(),
date_now = item.get('data-now').toInt(),
days = 0, hours = 0, minutes = 0, seconds = 0;

// Increment data-now with update seconds
item.set('data-now', date_now + this.options.update / 1000);

if(date_to <= date_now) {
Array.append(this.finished, [item]);
this.fireEvent('completed');
return;
}

var diff = date_to - date_now;

// Days
if(diff > 86400) {
days = Math.floor(diff / 86400);
diff -= days * 86400;
}
// Hours
if(diff > 3600) {
hours = Math.floor(diff / 3600);
diff -= hours * 3600;
}
// Minutes
if(diff > 60) {
minutes = Math.floor(diff / 60);
diff -= minutes * 60;
}
// Seconds
seconds = diff;
// Render the template
this.setTime(item, days, hours, minutes, seconds);
}.bind(this));
this.start();
}.bind(this), this.options.update)
},
setTime: function(item, days, hours, minutes, seconds) {
var rendered = this.options.big_format.substitute({
D: this.options.small_format.substitute({
number: days,
word: Lang.numForm(days, this.options.lang.d)
}),
H: this.options.small_format.substitute({
number: hours,
word: Lang.numForm(hours, this.options.lang.h)
}),
M: this.options.small_format.substitute({
number: minutes,
word: Lang.numForm(minutes, this.options.lang.m)
}),
S: this.options.small_format.substitute({
number: seconds,
word: Lang.numForm(seconds, this.options.lang.s)
})
});
item.set("html", rendered)
},
stop: function () {
clearInterval(this.timer)
}
});

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий