var maxitems = 16; // How many items are allowed to show
var menuwidth='165' //default menu width
var menubgcolor='#EFEFEF'  //menu bgcolor
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed

var lastMenu;
var menuArr = new Array();
var disID;
var opera=!!window.opera;
var ie4=document.all&&!opera;
var ns6=document.getElementById&&!document.all;


// Specify obj2 as "this" in onmouseover to display on left of link
function showMore(obj, e, obj2)
{
	//alert(listType(e, "number"));
	if(!e&&event) e = event;
	var mo = obj;
	if(typeof(mo)=="string")
	{
		mo = document.getElementById(mo);
	}
	else if(typeof(mo)=="object")
	{
		mo = obj.parentNode;
		
		while(mo&&mo.className != null && mo.className!="NLQ")
			mo = mo.parentNode;
			
		mo = mo.nextSibling;
		if(mo.nodeName=="#text")
			mo = mo.nextSibling;
	}
	//alert(listAllTypes(e));
	var toadd=true;
	for(var kid in menuArr)
		if(kid==mo) toadd=false;
	if(toadd) menuArr.push(mo);
	mo.style.display = "none";
	try {
		ensureSize(mo, obj2);
	} catch(err) { alert(err.message); }
	clearhide();
	hideMore();
	mo.style.display = "";
	showhide(mo.style, e, "visible", "hidden", "");
	mo.onmouseover = clearhide;
	mo.onmouseout = delayhidemenu2;
	//lastMenu = mo;
	//alert(mo.style.visibility);
	return clickreturnvalue();
}
function getText(obj)
{
	if(obj.innerText) return obj.innerText.replace(/\s+/gi, " ").replace(/<[^>]+>/gi, "");
	if(obj.textContent) return obj.textContent.replace(/\s+/gi, " ").replace(/<[^>]+>/gi, "");
	return obj.innerText;
}
function findChildByNode(obj, node)
{
	if(!obj.childNodes) return null;
	for(var i=0; i<obj.childNodes.length; i++)
		if(obj.childNodes[i].nodeName==node)
			return obj.childNodes[i];
	return null;
}
function ensureSizeDiv(obj)
{
	//if(ns6||opera)
		//obj.style.paddingRight = "3px";
}
function getParentByNodeName(obj, name)
{
	while(!!obj.parentNode&&obj.parentNode.nodeName!=name)
		obj = obj.parentNode;
	return obj;
}
function ensureSize(obj, lnk)
{
	obj.style.display = "";
	if(!obj.style.width)
	{
		var maxlength = 10;
		var robj = findChildByNode(obj, "TABLE");
		if(robj==null) return ensureSizeDiv(obj);
		robj = robj.rows;
		for(var i=0; i<robj.length; i++)
			if(getText(robj[i]).length>maxlength)
				maxlength = getText(robj[i]).length;
		obj.style.width = ((6*maxlength)+30) + "px";
	}
	var rs = findChildByNode(obj, "TABLE").rows;
		for(var i=0; i<rs.length; i++)
		{
			//window.status = rs[i].firstChild.nodeName;
			if(ns6||opera)
				rs[i].firstChild.style.paddingRight = "3px";
			//else
				//findChildByNode(rs[i].firstChild, "A").style.paddingRight = "3px";
		}
	//alert(obj.outerHTML);
	//obj.style.cssText+=" overflow:none;";
	var windowedge = (ie4 && !window.opera) ? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
	var rheight = findChildByNode(obj, "TABLE").rows[0].offsetHeight;
	var maxheight = windowedge - obj.offsetTop;
	maxheight = maxheight - (maxheight % rheight);
	if(maxheight>(rheight*maxitems))
		maxheight = (rheight*maxitems);
	//if(ie4)
		maxheight++;
	if(obj.offsetHeight>maxheight)
	{
		obj.style.height = maxheight + "px";
		obj.style.overflow="auto";
	}
	//obj.scrollTop = 0;
	if(lnk != undefined)
	{
		obj.style.left = (getObjLeft(lnk) - obj.offsetWidth - 6) + "px";
		obj.style.top = getObjTop(lnk) + "px";
	}
}
function getSimpleLeft(obj)
{
	if(!obj.offsetLeft||isNaN(obj.offsetLeft)) return 0;
	var left = obj.offsetLeft;
	if(!isNaN(obj.scrollLeft))
		left -= obj.scrollLeft;
	if(!isNaN(obj.clientLeft))
		left += obj.clientLeft;
	return left;
}
function getObjLeft(obj)
{
	var left = 0;
	if(!!obj.offsetParent)
	{
		if(!isNaN(obj.offsetLeft))
			left += obj.offsetLeft;
		while (!!obj)
		{
			left += getSimpleLeft(obj);
			//top += (obj.offsetTop-obj.scrollTop+obj.clientTop);
			obj = obj.offsetParent;
		}
	}
	return left;
}
function getSimpleTop(obj)
{
	if(!obj.offsetTop||isNaN(obj.offsetTop)) return 0;
	var Top = obj.offsetTop;
	if(!isNaN(obj.scrollTop))
		Top -= obj.scrollTop;
	if(!isNaN(obj.clientTop))
		Top += obj.clientTop;
	return Top;
}
function getObjTop(obj)
{
	var top = 0;
	if(!!obj.offsetParent)
	{
		if(!isNaN(obj.offsetTop))
			top += obj.offsetTop;
		while (!!obj)
		{
			top += getSimpleTop(obj);
			obj = obj.offsetParent;
		}
	}
	return top;
}
function getLeft(obj)
{
	if(obj==null || obj==undefined) return 0;
	var x = 0;
	if(!isNaN(obj.offsetLeft))
	{
		if(obj.nodeName == "DIV" || obj.nodeName == "A")
		//{
			x = new Number(obj.offsetLeft);
		//}
		else if (obj.nodeName == "TD")
		{
			x = getTDLeft(obj.previousSibling);
			//alert(obj.parentNode.parentNode.parentNode.parentNode.nodeName);
			return x + getLeft(getParentByNodeName(obj, "TABLE").parentNode);
		}
		//else alert(obj.nodeName + "\n" + listType(obj, "number"));
	}
	return x + getLeft(obj.parentNode);
}
function getTDLeft(td)
{
	if(td == undefined || td == null) return 0;
	var x = 0;
	if(!isNaN(td.offsetWidth))
		x = new Number(td.offsetWidth);
	return x + getTDLeft(td.previousSibling);
}
function getTop(obj)
{
	if(obj==null || obj==undefined) return 0;
	var y = 0;
	if(!isNaN(obj.offsetTop))
		if(obj.nodeName == "TD" || obj.nodeName == "DIV" || obj.nodeName == "TABLE" || obj.nodeName == "A")
			y = new Number(obj.offsetTop);
	return y + getTop(obj.parentNode);
}
function listAllTypes(obj)
{
	return listType(obj,"string") + "\n" + listType(obj,"number") + "\n" + listType(obj,"object") + "\n" + listType("function");
}
function listType(obj,typ)
{
	var ret = "";
	for(var kid in obj)
		if(typeof(obj[kid])==typ)
		{
			var tmp = obj[kid];
			if(typeof(tmp)=="string")
			{
				if(tmp==undefined) continue;
				if(tmp==null) continue;
				if(tmp=="") continue;
				if(tmp.length > 43) tmp = tmp.substring(0, 40) + "...";
			}
			ret += kid + " = " + tmp + "\n";
		}
	return ret;
}
function showAll(obj)
{
	var ret = "";
	for(kid in obj)
		ret+=kid+" ";
	return ret;
}
function clearhide()
{
	if(disID)
		clearTimeout(disID);
	disID = null;
}
function hideMore()
{
	//alert("hiding");
	for(var kid in menuArr)
		if(menuArr[kid]&&menuArr[kid].style&&menuArr[kid].style.visibility=="visible")
		{
			menuArr[kid].style.visibility="hidden";
			menuArr[kid].style.display = "none";
		}
}
function delayhidemenu2()
{
	disID = setTimeout("hideMore()", disappeardelay);
}
function listAll(obj)
{
	var ret = "";
	for(kid in obj)
		ret+=kid+" ";
	return ret;
}

function getposOffset(what, offsettype)
{
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null)
	{
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth)
{
	//if (ie4||ns6)
	//	dropmenuobj.style.left=dropmenuobj.style.top="-500px";
		
	//if (menuwidth!=""){
	//	dropmenuobj.widthobj=dropmenuobj.style;
	//	dropmenuobj.widthobj.width=menuwidth;
	//}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
		obj.visibility=visible;
	else if (e.type=="click")
		obj.visibility=hidden;
}

function iecompattest()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function clickreturnvalue(){
	if (ie4||ns6)
		return false;
	return true;
}

function contains_ns6(a, b)
{
	while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	return false;
}

/*function dynamichide(e)
{
	if (ie4&&!dropmenuobj.contains(e.toElement))
		delayhidemenu();
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu();
}*/

function hidemenu2(e)
{
	if(lastMenu&&lastMenu.style) {
		lastMenu.style.visibility="hidden";
		return true;
	}
	return false;
}
function hidemenu(e)
{
	if(hidemenu2(e)) return;
	if (typeof dropmenuobj!="undefined")
	{
		if (ie4||ns6)
			dropmenuobj.style.visibility="hidden";
	}
}

function delayhidemenu()
{
	if (ie4||ns6)
		delayhide=setTimeout("hidemenu()",disappeardelay);
}

function clearhidemenu()
{
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide);
}

if (hidemenu_onclick=="yes")
	document.onclick=hidemenu;
