var secWidth=40;
var ciukeWidth=500;
var secMargin=1;
var m_names = new Array("Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul", "Aug", "Sep",
"Oct", "Nov", "Dec");

function zerify(y){
if (x<10) return '0' + y;
else return y;
}


function builDivs(){
/*costruzione dei secondi*/
DIVs=document.getElementById('sec');
for (x=1;x<61;x++){
        DIVs.innerHTML=DIVs.innerHTML+'<div id=s' + x + ' class=s>'+ zerify(x) + '</div>';
}
/*costruzione dei minuti*/
DIVm=document.getElementById('min');
for (x=1;x<61;x++){
        DIVm.innerHTML=DIVm.innerHTML+'<div id=m' + x + ' class=m>' + zerify(x) + '</div>';
}
/*costruzione delle ore*/
DIVh=document.getElementById('hour');
for (x=1;x<25;x++){
        DIVh.innerHTML=DIVh.innerHTML+'<div id=h' + x + ' class=h>' + zerify(x) + '</div>';
}
/*costruzione dei giorni*/
DIVd=document.getElementById('day');
for (x=1;x<32;x++){
        DIVd.innerHTML=DIVd.innerHTML+'<div id=d' + x + ' class=d>' + x + '</div>';
}
/*costruzione dei mesi*/
DIVM=document.getElementById('month');
for (x=1;x<13;x++){
        DIVM.innerHTML=DIVM.innerHTML+'<div id=M' + x + ' class=M>' + m_names[x] + '</div>';
}
/*costruzione degli anni*/
DIVy=document.getElementById('year');
for (x=2009;x<2011;x++){
        DIVy.innerHTML=DIVy.innerHTML+'<div id=y' + x + ' class=y>' + x + '</div>';
}
ciukeStart();
}

function colorMe(){
for (x=1;x<61;x++){
idx='s'+x;
thisDiv=document.getElementById(idx)
bk='#7777' + decToHex(x*4);
thisDiv.style.background=bk;
}
}

function ciukeStart(){
var d = new Date()
BUGIA(d.getSeconds(),'s')
BUGIA(d.getMinutes(),'m')
BUGIA(d.getHours(),'h')
BUGIA(d.getDate(),'d')
BUGIA(d.getMonth(),'M')
BUGIA(d.getFullYear(),'y')
setTimeout('ciukeStart()',1000)
}


function BUGIA(offset,what){
var minDiv=1;
if (what=='s' || what=='m') totDiv=61;
if (what=='h') totDiv=25
if (what=='d') totDiv=32
if (what=='M') totDiv=13
if (what=='y') {totDiv=2011;minDiv=2009}

for (x=minDiv;x<totDiv;x++){
        idx=what+x;
        thisDiv=document.getElementById(idx)
        /*da tarare meglio, è la centratura*/
        p1=((x-offset)* secWidth +(ciukeWidth/2));

        /*l'anno è un caso speciale*/
        if (what=='y') {
        p1=(x - offset)*secWidth +((ciukeWidth/2) );
        }

        /*CAMBIO LO STILE*/
        /*controllo su quelli prima*/
        if (x>(totDiv-(totDiv/3))&&(what=='s')&&(offset<(totDiv/3))){
        p1=(x - offset)*secWidth +((ciukeWidth/2))-((totDiv-1)*secWidth);
        }
        /*controllo su quelli dopo*/
        if ((x<(totDiv/3))&&(what=='s')&&(offset>(totDiv/3))){
        p1=(x - offset)*secWidth +((ciukeWidth/2))+((totDiv-1)*secWidth);
        }

        if ((p1>ciukeWidth)||(p1<0)) thisDiv.style.visibility='hidden'


        else {
                thisDiv.style.left=p1+'px'
                thisDiv.style.visibility='visible'
                /*thisDiv.style.backgroundColor='#7777' + decToHex(Math.floor((x/totDiv)*256));*/
                if (x==offset){ thisDiv.className=what + ' enh'}
                else {thisDiv.className=what}
        }
}
}

function decToHex(dec)
{
var hexStr = "0123456789ABCDEF";
var low = dec % 16;
var high = (dec - low)/16;
hex = "" + hexStr.charAt(high) + hexStr.charAt(low);
return hex;
}


function ciukeStart2(){
myH=document.body.clientHeight;
thisH=document.getElementById('ck')
var d = new Date()
msg=d.getHours(),'h'
msg=msg+ ':' +d.getMinutes(),'m'
       setTimeout('ciukeStart()',6000)
       thisH.src='replace.html?s='+(myH/3)+'&text=' + msg;
    }

function setDate(){
thisD=document.getElementById('dt')
var d = new Date()
thisD.src='replace.html?s='+(myH/10)+'&text=' + (d.getMonth()+1) + ' ' + d.getDate();
}
