// Metodo per aggiungere uno 0 se il numero ha una sola cifra
Number.prototype.addZero = function() {
    numero = this.toString();
    if (numero.length == '1')
        numero = '0'+numero;
    return numero;
}

// Classe per gestire data e ora nella barra superiore
Clock = new Class({
    url: 'clock.php',
    months: new Array('gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio', 'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre'),
    timestamp: null,

    initialize: function() {
        var params = 'action=now';
        var object = this;

        new Request({
            url: object.url,
            onSuccess: function(result_txt) {
                if (result_txt) {
                    object.timestamp = result_txt*1000;
                    object.tictac.bind(object).periodical(1000);
                }
            }
        }).send(params);
    },

    tictac: function() {
        var now = new Date(this.timestamp);

        var html = now.getDate();
        html += ' ' + this.months[now.getMonth()];
        html += ' ' + now.getFullYear();
        html += '&nbsp;&nbsp;&nbsp;' + now.getHours().addZero();
        html += '<span style="visibility:' + (now.getSeconds()%2?'visible':'hidden') + '">:</span>';
        html += now.getMinutes().addZero();

        $('date').set('html', html);
        this.timestamp += 1000;
    }
});


