var childHovers=null;
var ie=document.all!=null;
var initialized=false;
initPrimNav = function() {
	if (document.getElementsByTagName) 
	{
		resize();
		if (!initialized)
		{
			window.setTimeout("initPrimNav()", 600);
			window.setTimeout("initPrimNav()", 1200);
			initialized=true;
		}
	}
	
	
}

function resize()
{
	var baseTop=getWindowInnerSize().height;
	var footerTop = baseTop+147-166;
	navRoot = document.getElementsByTagName("UL")[0];
	parse(navRoot);		
	var divs = document.getElementsByTagName("DIV");
	var divBody=null;
	var divFooter=null;
	for (var i=0; i<divs.length; i++)
	{
		if (divs[i].className=="Footer")
		{
			divFooter = divs[i];				
		}
		if (divs[i].className=="Body")
		{
			divBody = divs[i];				
		}
	}
	var bodyElement = document.getElementsByTagName("BODY")[0];	
	if (getWindowInnerSize(window).height > (getObjectHeightObject(bodyElement) + (ie ? 18 : 0)))
	{
		bodyElement.style.height=baseTop + "px";
		divFooter.style.top=footerTop + "px";
		divFooter.style.position="absolute";
		divFooter.style.left="0";
		divBody.style.height=(baseTop - 145) + "px";				
	}
	else
	{
		
	}
	var minWidth=(820 + (ie?-20:0));
	if (getWindowInnerSize(window).width < minWidth)
	{
		divBody.style.width= "800px";
	}
	else
	{
		divBody.style.width="100%";
	}
}

function parse(navRoot){
	for (var i=0; i<navRoot.childNodes.length; i++) {
		var node = navRoot.childNodes[i];
		if (node.nodeName=="LI") {
			node.onmouseover=function() {
				if (childHovers!=null){
					return;
				}	
				if (this.parentNode.parentNode.nodeName=="LI"){
					childHovers=this;
				}
				this.className+="hover";
			}
			node.onmouseout=function() {
				this.className=this.className.replace("hover", "");
				if (this.parentNode.parentNode.nodeName=="LI"){
					if (childHovers==this){
						childHovers=null;
					}
				}
					
			}
			for (var j=0; j<node.childNodes.length; j++) {
				var childNode=node.childNodes[j];
				if (childNode.nodeName=="UL") {
					parse(childNode);
				}
			}
		}
	}

}

function getPos(id)
{
	return getPostObject(document.getElementById(id));	
}

function getPosObject(obj)
{
	var pos = {left:0, top:0};

	if(typeof obj.offsetLeft != 'undefined') {

		while (obj) {
			pos.left += obj.offsetLeft;
			pos.top += obj.offsetTop;
			obj = obj.offsetParent;
		}
		pos.top+=ie?0:0/*middleMarginTop*/;
	} else {
		pos.left = obj.left;
		pos.top = obj.top;
	}

	return pos;
}

function maxPosition()
{
	var iMaxPos = -Number.MAX_VALUE;

	for(var i = 0; i < maxPosition.arguments.length; i++) {
		if(maxPosition.arguments[i] > iMaxPos) {
			iMaxPos = maxPosition.arguments[i];
		}
	}
	return iMaxPos;
}

function setObjectHeight(id, height)
{
	var obj = document.getElementById(id);
	obj.style.height = height + "px";
}

function getObjectHeight(id)
{
return getObjectHeightObject(document.getElementById(id));
}

function getObjectHeightObject(obj)
{
	var iObjectHeight = 0;
	iObjectHeight = obj.offsetHeight;
	return parseInt(iObjectHeight);
}

function getWindowInnerSize(win)
{
	if(!win) win = window;
		var objWin = new Object();
		if(typeof win.innerWidth != 'undefined') {
			objWin.width = win.innerWidth;
			objWin.height = win.innerHeight;
		} else {
			var obj = getBody(win);
			objWin.width = parseInt(obj.clientWidth);
			objWin.height = parseInt(obj.clientHeight);
		}
		return objWin;
}

function getBody(w)
{
	return (w.document.compatMode && w.document.compatMode == "CSS1Compat") ? w.document.documentElement : w.document.body || null;
}

window.onload = initPrimNav;
window.onresize=initPrimNav;