
var curMenu = "";
var x1,x2,y1,y2,mx,my;
var i=1, j=1;
document.onmouseout = checker;

function checker(e)
{
	if(!e) e= window.event;
	mx = e.clientX;
	my = e.clientY;
	//document.getElementById("bock").innerHTML = "\nY:" + y1 + "-" + my + "-" + y2 +"\nX:" + x1 + "-" + mx + "-" + x2;
	if(curMenu != "" && (mx < x1 || mx >= x2 || my < y1 || my >= y2) && document.getElementById(curMenu + "x").style.visibility == "visible")
	{
		document.getElementById(curMenu + "x").style.visibility= "hidden";
	}
}

function getPosition(element)
{
	var elem=element,tagname="",x=0,y=0;
	while ((typeof(elem)=="object")&&(typeof(elem.tagName)!="undefined"))
	{
		y+=elem.offsetTop;
		x+=elem.offsetLeft;
		tagname=elem.tagName.toUpperCase();
		if (tagname=="BODY" || tagname == "HTML")
			elem=0;
		if (typeof(elem)=="object")
			if (typeof(elem.offsetParent)=="object")
				elem=elem.offsetParent;
  	}
	position=new Object();
	position.x=x;
	position.y=y;
	return position;
}

function do_menu(menId,parentObj,xOffset,yOffset)
{
	if(curMenu != "" && menId != (curMenu + "x"))
	{
		document.getElementById(curMenu + "x").style.visibility = "hidden";
	}
	with(document.getElementById(menId))
	{
		
		var pos = getPosition(document.getElementById(parentObj));
		x1 = pos.x;
		y1 = pos.y;
		x2 = x1 + document.getElementById(parentObj).offsetWidth + xOffset;
		y2 = y1 + document.getElementById(parentObj).offsetHeight + offsetHeight + yOffset;
		curMenu = document.getElementById(parentObj).id;
		style.left = pos.x  + xOffset + "px";
		style.top  = pos.y  + yOffset + document.getElementById(parentObj).offsetHeight -1 + "px";
		
		
		// Korrektur fuer angaben verschiedener Browser
		var ds = pos.x - getPosition(document.getElementById(menId)).x;
		var dw = document.getElementById(parentObj).offsetWidth - offsetWidth;
		//alert(ds + " " + dw);
		if(ds != 0)
			style.top = pos.x - ds;
		if(dw != 0)
			style.width=(document.getElementById(parentObj).offsetWidth + dw) + "px";
		style.visibility="visible";
		//document.getElementById("bock").innerHTML ="x: " + style.left + "\ny:" + style.top + "\nv:" + style.visibility;
	}
}


function constructMenu()
{
	
	var menus = "", target="";
	for(var node in this.rootNode.childNodes)
	{
		var lv1men;
		if(this.rootNode.childNodes[node].childCount > 0)
		{
			menus = menus +  "<div style=\"width:100px\" id=\"m" + node + "x\" class=\"submenu\" ><table width=100% border=0 style=\"border-collapse:collapse;\" >";
			for(var subnode in this.rootNode.childNodes[node].childNodes)
			{
				with(this.rootNode.childNodes[node].childNodes[subnode])
				{
					menus = menus +  "<tr><td onMouseOver=\"this.style.backgroundColor='#ffffff';\" onMouseOut=\"this.style.backgroundColor='';\" ><a class=\"menulink\" href=\"" + url + "\" target=\""+target+"\">" + caption + "</a></td></tr>" + "\n";
				}
			}
			menus = menus +  "</table></div>";
			
		}
		
	}
	document.write("</tr></table>");
	document.write(menus);
	
}

function addNode(id,caption,url,target)
{
	this.rootNode.childNodes[id] = new menuNode(caption,url,target);
	this.rootNode.childCount++;
	this.currentLv1Node=this.rootNode.childNodes[id];
}

function addSubNode(id,caption,url,target)
{
	this.currentLv1Node.childNodes[id] = new menuNode(caption,url,target);
	this.currentLv1Node.childCount++;
	this.currentLv2Node = this.currentLv1Node.childNodes[id];
}

function menuNode(caption,url,target)
{
	this.caption = caption;
	this.url= url;
	this.childNodes = new Object();
	this.target = target;
	this.childCount = 0;
}

function obDropDown()
{
	this.rootNode = new menuNode("root","");
	this.currentLv1Node = this.rootNode;
	this.currentLv2Node = this.rootNode;
	this.currentLv3Node = this.rootNode;
	this.construct = constructMenu;
	this.addNode = addNode;
	this.addSubNode = addSubNode;
}


var menu = new obDropDown();
