var z_index = { "vert_menu" : ["vert_menu_shaper", "horiz_menu_shaper"], "horiz_menu" : ["horiz_menu_shaper", "vert_menu_shaper"] } ;

function d(text)
{
	document.getElementById("utilityLinks").innerHTML = text 
}
function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/-(w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}
function leftOffset(what) {
	var totaloffset= what.offsetLeft;
	var parentEl= what.offsetParent;
	while (parentEl!=null){
		totaloffset+=parentEl.offsetLeft;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}
function topOffset(what) {
	var totaloffset= what.offsetTop;
	var parentEl= what.offsetParent;
	while (parentEl!=null){
		totaloffset+=parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}
var ie5=document.all&&document.getElementById ;

function get_menu_adj(a)
{
	var menu = 0 ;
	for (i = 0 ; i < a.parentNode.childNodes.length; i++) {
		if (a.parentNode.childNodes[i].nodeName == "UL") {
			return a.parentNode.childNodes[i] ;
		} 
	}
	
	if (ie5 && a.childNodes[1].nodeName == "TABLE") {
		return a.childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
	}
}
function get_menu(a)
{
	return a.parentNode.parentNode ;
}
function get_div(menu)
{
	var div = 0 ;
	
	while (menu.parentNode) {
		if (menu.parentNode.nodeName == "DIV")
			return menu.parentNode ;
		menu = menu.parentNode ;
	}
}
function get_li(div)
{
	for (i = 0 ; i < div.childNodes.length ; i++)
		if (div.childNodes[i].nodeName == "UL")
			for (j = 0 ; j < div.childNodes[i].childNodes.length; j++)
				if (div.childNodes[i].childNodes[j].nodeName == "LI")
					return div.childNodes[i].childNodes[j] ; 
}
var scrollSpeed = 25 
var scrollAmount = 5

function ma(a) {
	var menu
	menu = get_menu_adj(a) 
	
	if (!menu)
		return ;
	
	var div
	div = get_div(menu) ;
	
	if (z_index[div.id]) {
		document.getElementById(z_index[div.id][0]).style.zIndex = 100 ;
		document.getElementById(z_index[div.id][1]).style.zIndex = 2 ;
	}
	
	menu.style.marginTop = "" ;
	
	var menuTop = topOffset(menu) ;
	var bottomEdge = ie5 ? document.documentElement.clientHeight : window.innerHeight ;
	 
	if (menu.clientHeight > bottomEdge) 
	{
		var scrollY 
		if (document.all)
    	{
			scrollY = document.documentElement.scrollTop ? 
				document.documentElement.scrollTop : 
				document.body.scrollTop 
    	}   
   		else
    	{
        	scrollY = window.pageYOffset;
    	}
	
		menuTop -= scrollY
		
		var parent_li
		
		if (menu.parentNode.nodeName != "LI")
			parent_li = menu.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
		else
			parent_li = menu.parentNode 
		
		if (parent_li.parentNode.parentNode == div)
			return false
		
		var li = get_li(div)
		
		var div1 = document.createElement("div") 
		var div2 = document.createElement("div") 
		var divcontainer = document.createElement("div") 
		
		menu.parentNode.appendChild(divcontainer) 
		
		divcontainer.appendChild(div1) 
		divcontainer.appendChild(menu) 
		divcontainer.appendChild(div2)
		
		div1.style.left = div2.style.left = getStyle(menu, "left") 
		div1.className = "uparrow" 
		div2.className = "downarrow" 
		
		var scrollUpLimit
		var scrollDownLimit
		
		if (div.className == "menu") 
		{
			div1.style.top = -(menuTop-li.clientHeight) + "px" 
			div2.style.top = bottomEdge - (menuTop + li.clientHeight) + "px" 
			menuTop -= li.clientHeight + div1.clientHeight
			
			scrollUpLimit = li.clientHeight + div1.clientHeight - 2
			scrollDownLimit = bottomEdge - 18
		}
		else if (div.className = "vmenu")
		{
			div1.style.top = -(menuTop+3) + "px" 
			div2.style.top = bottomEdge - menuTop - 24 + "px" 
			scrollUpLimit = 18
			scrollDownLimit = bottomEdge - 20
			menuTop -= 17
		}
		menu.style.marginTop = -menuTop  + "px" 
	
		var tid = 0 
		var scrolltid = 0 
		
		var scrollTop = topOffset(menu)
		
		div1.onmouseover = function() {  
			if (scrolltid)
			{
				clearInterval(scrolltid) 
			}
			div1.style.backgroundColor = "#aaa"
				
			scrolltid = setInterval(function () {
			//change
				if (scrollTop <= scrollUpLimit + scrollY) 
				{
					menuTop -= scrollAmount
					scrollTop += scrollAmount
					menu.style.marginTop = -menuTop + "px"
				}
			}, scrollSpeed) 
		} 
		
		div1.onmouseout = function() {
			clearInterval(scrolltid) 
			div1.style.backgroundColor = "#ccc"
		}
		
		div2.onmouseover  = function() {
			if (scrolltid)
				clearInterval(scrolltid) 
				
			div2.style.backgroundColor = "#aaa"
			
			scrolltid = setInterval(function () {
			//change
				 if (scrollTop + menu.clientHeight >= scrollDownLimit + scrollY) {
			 		menuTop += scrollAmount
					scrollTop -= scrollAmount
			 		menu.style.marginTop = -menuTop + "px"
			 	}
			 }, scrollSpeed) 
		 } 
		 div2.onmouseout = function() {
			clearInterval(scrolltid) 
			div2.style.backgroundColor = "#ccc"
		}
		var overfn = function() {
			if (tid) {
				clearTimeout(tid) 
				tid = 0 
			}
		} ;
		var outfn = function () {
			if (!tid)
				tid = setTimeout(function () {
						var pn = divcontainer.parentNode 
						pn.appendChild(menu) 
						pn.removeChild(divcontainer)
						
						menu.onmouseover = null 
						menu.onmouseout = null 
						pn.onmouseover = null 
						pn.onmouseout = null 
					}, 1) 
		} ;
		divcontainer.onmouseover = overfn 
		divcontainer.onmouseout = outfn 
		
		menu.onmouseover = overfn 
		menu.onmouseout = outfn 
			
		parent_li.onmouseover = overfn 
		parent_li.parentNode.onmouseout = outfn 
		
	} 
	else if (div.className == "umenu") {
		var li = get_li(div)
		var li_top = topOffset(li) 
		if (menuTop + menu.clientHeight > li_top) 
		{
			menu.style.marginTop = -(menu.clientHeight + menuTop - li_top) + "px" 
		}
	}
	else if (div.className == "vmenu") {
		if (menuTop + menu.clientHeight > bottomEdge)
		{
			menu.style.marginTop = -(menu.clientHeight + menuTop - bottomEdge)  + "px" ;
		}
	}
	
	return false ;
}
function hideSelectField()
{
	var selectField = document.getElementById('selectFieldDiv');
	if(selectField)
	selectField.style.display="none";
}
function showSelectField()
{
	var selectField = document.getElementById('selectFieldDiv');
	if(selectField)
	selectField.style.display="block";
}