// JavaScript Document
window.onload = function() {
  setFooter();
  check_menu('main_menu');
  /* check_menu('alternative_menu'); */
  fix_ie_hover_bug('main_menu');
}
window.onresize = function() {
  setFooter();
}
function getWindowHeight() {
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') {
		windowHeight=window.innerHeight;
	}
	else {
		if (document.documentElement&&document.documentElement.clientHeight) {
			windowHeight=document.documentElement.clientHeight;
		}
		else {
			if (document.body&&document.body.clientHeight) {
				windowHeight=document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function setFooter() {
	if (document.getElementById) {
		var windowHeight=getWindowHeight();
		if (windowHeight>0) {
			var contentHeight=obj_height('header')+obj_height('navigation')+obj_height('content');
			var footerElement=document.getElementById('footer');
			var footerHeight=footerElement.offsetHeight;
			if (windowHeight-(contentHeight+footerHeight)>=0) {
				document.getElementById('global_wrap').style.height = (windowHeight-obj_height('header'))+'px';
				// dump(document.getElementById('global_wrap').style.height)
				footerElement.style.position='absolute';
				footerElement.style.bottom='0px';
			}
			else {
				footerElement.style.position='static';
			}
		}
	}
}
function check_menu (id) {
	// needed for Opera 7.54
	var listWidth = 0;
    var list = document.getElementById(id);
    var listItems = list.childNodes;
    for (var i = 0; i < listItems.length; i ++) {
        if(listItems[i].nodeName == 'LI') {
			listWidth += listItems[i].offsetWidth;
		}
     }
    if(obj_width(id) < listWidth) {
		list.style.width = listWidth+'px';
	}
}
function fix_ie_hover_bug(navi_obj) {
	if (document.all&&document.getElementById&&(navigator.userAgent.toLowerCase().indexOf('opera') == -1)) {
		navRoot = document.getElementById(navi_obj);
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.style.width = node.offsetWidth+"px";
				node.onmouseover=function() {
					this.className+=" iebug-hover";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" iebug-hover", "");
				}
			}
		}
	}
}
function obj_width(id) {
	obj = document.getElementById(id);
	return obj.offsetWidth;
}
function obj_height(id) {
	obj = document.getElementById(id);
	return obj.offsetHeight;
}
function dump(text) {
	if(!document.getElementById('dump')) {
		embryo = document.createElement('div');
		dump_obj = document.body.appendChild(embryo);
		dump_obj.setAttribute('id','dump');
	}
	else {
		dump_obj = document.getElementById('dump');
	}
	dump_obj.innerHTML = text;
}
function dump_var(variable){
	dump(variable+" = "+eval(variable));
}