﻿function ticker_element() {
    this.value = 0;
    this.parent = null;
    this.maxValue = 0;
    this.digit1 = 0;
    this.digit2 = 0;
}



function _initTicker(dayid, hourid, minuteid, secondid, timer_day, timer_hour, timer_minute, timer_second) {
    timer_day.digit1 = document.getElementById(dayid);
    timer_hour.digit1 = document.getElementById(hourid);
    timer_minute.digit1 = document.getElementById(minuteid);
    timer_second.digit1 = document.getElementById(secondid);

    timer_day.digit1.innerHTML = timer_day.value;

    timer_hour.digit1.innerHTML = timer_hour.value;

    timer_minute.digit1.innerHTML = timer_minute.value;

    timer_second.digit1.innerHTML = timer_second.value;
}

function tickBack(o,p) {
    //alert(p.value + "==>" + p);
    if (!o) {
        return false;
    }

    if (o.value > 0) {
        o.value--;
        o.digit1.innerHTML = o.value;
        
        tickAgain(p);
        return true;
    }
    else {
        if (tickBack(o.parent,p)) {
            o.value = o.maxValue - 1;
            o.digit1.innerHTML = o.value;
            return true;
        }
        else
            return false;
    }
}

function tickTock(timer_sec) {
    tickBack(timer_sec,timer_sec);
}

function tickAgain(o) {
    setTimeout(this.tickTock, 1000, o);
}
