var timer_id = null;
var timer_running = false;

function stop_clock (){
    if(timer_running)
        clearTimeout(timer_id);
    timer_running = false;
}

function show_time () {
    var now = new Date();
    var minutes = now.getMinutes();
    var hours = now.getHours();
    
    var day;
    
    switch(now.getDay()){
        case 0:
            day = "воскресенье";
            break;
        case 1:
            day = "понедельник";
            break;
        case 2:
            day = "вторник";
            break;
        case 3:
            day = "среда";
            break;
        case 4:
            day = "четверг";
            break;
        case 5:
            day = "пятница";
            break;
        case 6:
            day = "суббота";
            break;
    }
    
    var time_value = hours + ((minutes < 10) ? ":0" : ":") + minutes;
    var date_value = ((now.getDate() < 10) ? "0" : "") + now.getDate() + ((now.getMonth() < 9) ? ".0" : ".") + (now.getMonth()+1) + "." + now.getFullYear();
    
    $('#time').html(time_value);
    $('#date').html(date_value);
    $('#day').html(day);
    
    timer_id = setTimeout("show_time()", 1000);
    timer_running = true;
}

function start_clock() {
    stop_clock();
    show_time();
}
