
nFooterY = -1;
imgRA1 = new Array();
imgRA2 = new Array();


function getFirstChildOfType(parentNode, nodeTyp)
{
	var returnNode = null;
	if (parentNode.childNodes)
	{
		for (i = 0; i < parentNode.childNodes.length; i++)
		{
			node = parentNode.childNodes[i];
			if (node.nodeName == nodeTyp)
			{
				//alert(show_props(node, 'node') );
				//alert(show_props(node.currentStyle, 'style') );
				returnNode = node;
				break;
			}
		}
	}
	return returnNode;
}

function setSelectedNavPoints()
{
	if (document.getElementById)
	{
		setGlobalNavPoint();
		setNavPoint(jspvalTerNav);
		setNavPoint(jspvalSecNav);
		setNavPoint(jspvalPriNav);		
	}
}

var bNeedSelect = true;
function setNavPoint(navid)
{
	obj = document.getElementById(navid);
	if (obj && navid>"" )
	{
		if (bNeedSelect)
		{
			//alert(obj.id + "=selected");
			obj.className = "selected";
			bNeedSelect = false;
		}
		else
		{
			//alert(obj.id + "=expanded");
			obj.className = "expanded";
		}
	}
	return;
}

function setGlobalNavPoint()
{
	obj = document.getElementById(jspvalGlobalNav);
	if (obj && jspvalGlobalNav>"" )
	{
		//alert(obj.id + "=selected");
		obj.className = "selected";
		getFirstChildOfType(obj, 'A').className = "selected";
	}
	return;
}

function initMenu()
{
	var i;
	var j;
	var node;
	var child;
	var parent;
	
	// if the browser doesn't even support 
	// document.getElementById, give up now. 
	if (!document.getElementById)
	{
		return true;
	}
	
	// check for downlevel browsers
	// Opera 6, IE 5/Mac are not supported 
	
	var version;
	var offset;
	
	offset = navigator.userAgent.indexOf('Opera');
	if (offset != -1)
	{
		version = parseInt('0' + navigator.userAgent.substr(offset + 6), 10);
		if (version < 7)
		{
			return true;
		}
	}
	
	offset = navigator.userAgent.indexOf('MSIE');
	if (offset != -1)
	{
		if (navigator.userAgent.indexOf('Mac') != -1)
		{
			return true;
		}
	}
	
	
	//initImageArray();
	
	uls = document.getElementsByTagName("UL");
	for (uli=0; uli < uls.length; uli++)
	{
		ul = uls[uli];
		if (ul.nodeName == "UL" && ul.className == "flynav")
		{
			processFlyNav(ul);
		}
	}
	
}

function processFlyNav(child)
{
	var parent;
	
	child.style.position = "absolute";
	child.style.visibility = "hidden";
	child.style.zIndex = 1000;
	
	// attach hover to parent li
	parent = child.parentNode;
	parent.onmouseover = showFlyNav;
	parent.onmouseout = hideFlyNav;
	//alert(parent.id);
}

function showFlyNav(e)
{
	var i;
	var child;
	var point;
	
	
	if ( nFooterY < 0 )
	{
		nFooterY = getPageXY(document.getElementById("footer")).y;	
	}
	
	changeDisplayFlyParent(this, 1);
	for (i=0; i < this.childNodes.length; i++)
	{
		child = this.childNodes[i];
		//alert(child.nodeName);
		if (child.nodeName == 'UL')
		{
			point = getPageXY(this);
			//alert(point.y); alert(nFooterY); alert(child.offsetHeight);
			//nCheck1 = Math.abs(document.body.clientHeight + document.body.scrollTop - child.offsetHeight - 1);
			nCheck1 = 0;
			nCheck2 = nFooterY - child.offsetHeight;
			nYvalue = nCheck1 > 0 ? Math.min(point.y, nCheck1) : point.y;
			nYvalue = nCheck2 > 0 ? Math.min(nYvalue, nCheck2) : nYvalue;
			//alert(nYvalue);
			setPageXY(child, point.x + this.offsetWidth, nYvalue);
			child.style.visibility = 'visible';
		}
	}
	return false;
}

function hideFlyNav(e)
{
	var relatedTarget = null;
	if (e)
	{
		relatedTarget = e.relatedTarget;
		// work around Gecko Linux only bug where related target is null
		// when clicking on menu links or when right clicking and moving
		// into a context menu.
		if (navigator.product == 'Gecko' && 
			navigator.platform.indexOf('Linux') != -1 && !relatedTarget)
		{
			relatedTarget = e.originalTarget;
		}
	}
	else if (window.event)
	{
		relatedTarget = window.event.toElement;
	}
	
	if ( elementContains(this, relatedTarget) )
	{
		return false;
	}
	
	changeDisplayFlyParent(this, 0);
	
	var i;
	var child;
	for (i = 0; i < this.childNodes.length; i++)
	{
		child = this.childNodes[i];
		if (child.nodeName == 'UL')
		{
			child.style.visibility = 'hidden';
		}
	}
	return false;
}


function changeDisplayFlyParent(node, on_off)
{
	ahref = getFirstChildOfType(node, "A");
	if ( on_off == 1)
	{
		if (ahref.id && imgRA1["onn"+ahref.id])
		{
			ahref.style.backgroundImage = "url(" + imgRA1["onn"+ahref.id] + ")";
		}
		else
		{
			ahref.saveBgColor = ahref.style.backgroundColor;
			ahref.saveFgColor = ahref.style.color;
			ahref.style.backgroundColor = "#003366";
			ahref.style.color = "#ffffff";
		}
	}
	else
	{
		if (ahref.id && imgRA1["off"+ahref.id])
		{
			ahref.style.backgroundImage = "url(" + imgRA1["off"+ahref.id] + ")";
		}
		else
		{
			ahref.style.backgroundColor = "#cccccc";
			ahref.style.color = "#000000";
		}
	}
	
	return false;
	/*
	alert(
			".nodeName:\t" + ahref.nodeName + "\n" + 
			".id:\t" + ahref.id + "\n" + 
			".backgroundImage :\t" + ahref.style.backgroundImage  + "\n" + 
			".props:\t" + show_props(ahref, 'prop names') + "\n"		);		
	*/
}
	



//================================================
function show_props(obj, obj_name) 
{
	var result = "";
	for (var i in obj)
	{
		value = obj[i];
		//result += obj_name + "." + i + " = " + obj[i] + "\t";
		result += obj_name + "." + i + ",\t";
	}
	return result;
}

