

var client_width;
var client_height;

function calc_client_size() {
    client_width = 0;
    client_height = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
	client_width = window.innerWidth;
	client_height = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	client_width = document.documentElement.clientWidth;
	client_height= document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {	
	client_width = document.body.clientWidth;
	client_width = document.body.clientHeight;
    }
}    


function on_scroll() {
    /*
    var m = document.getElementById("mainmenu");

    var v = document.body.scrollTop;
    if( !v ) {
	v = window.pageYOffset;
    }

    alert( "style " + m.style + ", top: " + m.style.top );
    m.style.top = v + "px";
    */
    
}

function menu_mouse_over(ev) {
    this.direction = -15;
    if (!frob_timer) {
	frob_timer = setInterval(
				 function () {
				     frob();
				 },
				 50
	);
    }
}

function menu_mouse_out(ev) { 
    //    this.direction = -0.2;
}


function hide_by_id(id) {
    var e = document.getElementById(id);
    if( e ) {
        e.style.visibility = "hidden";
        e.style.display = "none";
    }
}

function on_load() {
    hide_by_id("jswarn");
    hide_by_id("blurb");
    // start_menu_frob();
    //    menu_mouse_out(); 
}

function on_menu_hover() {

}

function on_mouse_over(n,yonly) {
    var menu = document.getElementById(n);
    // alert( "mouse over: " + menu );
    if( !yonly ) {
	menu.style.overflow = "auto";
    } else {
	menu.style.overflowY = "auto";
    }
}

function on_mouse_out(n) {
    var menu = document.getElementById(n);
    // alert( "mouse out: " + menu );
    menu.style.overflow = "hidden";
}

function on_resize() {
    /*
    var menu = getElementById("mainmenu");

    menu.style.height = (client_height - 100) + "px";
    alert( "menu height now: "  + menu.style.height );
    */
}

/*
function get_transform(e) {
    var s = e.style;
    if( typeof s.transform != "undefined" ) {
	return "transform";
    } else if( typeof s.WebkitTransform != "undefined" ) {
	return "WebkitTransform";
    } else if( typeof s.MozTransform != "undefined" ) {
	return "MozTransform";
    } else {
	return null;
    }
}


var frob_list = [];

function hex(c) {
    return "#" + (c * 65536 + c * 256 + c).toString(16);
}


var next_frob = 0;
var frob_timer;

function frob() {
    if( !frob_list.length ) {
	return;
    }

    var active = 0;
    for( var i = 0; i < frob_list.length; i++ ) {
	var e = frob_list[i];
	var d = e.direction;

	if( d ) { 
	    active++;
	}
    }

    if( active == 0 ) {
	clearInterval(frob_timer);
	frob_timer = null;
	return;
    }

    var to_do = active;
    if( to_do > 10 ) {
	to_to = 10;
    }

    while( to_do > 0 ) {
	next_frob++;
	if( next_frob > frob_list.length ) {
	    next_frob = 0;	    
	}

	var e = frob_list[next_frob];
	var d = e.direction;
	
	if( d ) {	    
	    to_do--;

	    var f = e.current;
	    if( !f ) {
		f = 212;	    
	    }
	    
	    f = f + d;
	    if( d < 0 && f < 0 ) {
		e.direction = -d;
		f = 0;

	    } else if( d > 0 && f > 212 ) {
		e.direction = 0;
		e.style.color = e.original;

	    } else {
	    // e.style.color = 100 + 10*f;
		e.style.color = hex(f);
		// alert( "now: " + e.style.color  + " from '" + hex(f) + "'" );
		e.current = f;
	    }
	}
    }
}


function frob_attach(e) {
    if( e.nodeName == 'A' ) {
	e.addEventListener("mouseover",menu_mouse_over,false);
	e.addEventListener("mouseout",menu_mouse_out,false);
	frob_list[frob_list.length] = e;
	e.original = e.style.color;
    }

    for( var i = 0; i < e.childNodes.length; i++ ) {
	frob_attach(e.childNodes[i]);
    }
}

var frob_interval;

function start_menu_frob() {
    var m = document.getElementById('body');


    for( var i = 0; i < m.childNodes.length; i++ ) {
	frob_attach(m.childNodes[i]);
    }
}
*/