var timerId = null;
var latentId = null;
var watchTimer = null;
var bkg = document.getElementById ( "background" );
var dimmer = document.getElementById ( "dimmer" );
var header = document.getElementById ( "header" );
var footer = document.getElementById ( "footer" );

//var deflect = document.getElementById ( "deflector" );
var announce = document.getElementById ( "announce" );
var announceShad = document.getElementById ( "announce-shadow" );
var dateTime = document.getElementById ( "dateTime" );
var sync = true;
var h, w;

//deflect.onmousemove = function() { return false; };
header.onmousemove = function() { return false; };
footer.onmousemove = function() { return false; };
announce.onmousemove = function() { return false; };
announceShad.onmousemove = function() { return false; };

function adjust () {
    clearTimeout ( timerId );
    clearTimeout ( latentId );
    timerId = setTimeout ( internalAdjust, 200 );
    latentId = setTimeout ( internalAdjust, 220 );
}

function todayString() {
    var now = new Date();
    return month(now)+"/" + day(now)+"/" + year(now)+" " + hours(now)+":" + mins(now)+":" + secs(now);
}

function month ( now ) {
    return now.getMonth() + 1;
}

function day ( now ) {
    return now.getDate();
}

function year ( now ) {
    return now.getFullYear();
}

function hours ( now ) {
    return checkZero ( now.getHours() );
}

function mins ( now ) {
    return checkZero ( now.getMinutes() );
}

var ps = null;
var s = null;
function secs ( now ) {
    ps = s;
    s = now.getSeconds();
    if ( null != ps && sync && ps != s ) {
        sync = false;
    }
    return sync ? s + "  sync" : checkZero ( s );
}

function checkZero ( amount ) {
    if ( amount < 10 ) {
        return "0" + amount;
    }
    return amount;
}

function internalAdjust() {
    h = document.documentElement.clientHeight;
    h = h < 550 ? 550 : h;
    w = document.documentElement.clientWidth;
    w = w < 550 ? 550 : w;
    
    bkg.style.width = w + "px";
    bkg.style.left = 0 + "px";
    bkg.style.top = 0 + "px";
    bkg.style.height = h + "px";
    dimmer.style.width = w + "px";
    dimmer.style.height = h + "px";
    dimmer.style.left = 0 + "px";
    dimmer.style.top = 0 + "px";
    //deflect.style.width = w + "px";
    //deflect.style.height = h + "px";
    dateTime.style.top = 80 + "px";
    dateTime.style.left = 107 + "px";
    dateTime.style.width = 200 + "px";
    dateTime.style.height = 18 + "px";
    
    performAdjust();
}

function showDateTime() {
    clearTimeout ( watchTimer );
    dateTime.childNodes[0].nodeValue = todayString();
    if ( sync ) {
        watchTimer = setTimeout ( function() { showDateTime(); }, 5 );
    } else {
        watchTimer = setTimeout ( function() { showDateTime(); }, 1000 );
    }
}
        
window.onresize = adjust;
showDateTime();

