function MagicDropDown()
{
	this.version = "MagicDropDown 0.9b :: Linus Skoglund 2000";
	this.left = 0;
	this.top = 68;
	this.inFrame = 'parent.frames[\"meny\"]';
	this.topFrame = 'parent.frames[\"menu\"]';
	this.subFrame = "parent.frames[\"main\"]";

	this.functionid = null;
	this.objstruct = null;
	this.countid = "root";
	this.depth = 0;
	this.submenu = new SubMenu();
	this.item = new Object();
	this.length = 0;

	this.addMenu = addMenu;
	this.drawMenu = drawMenu;
	this.drawSub = drawSub;
	this.drawTop = drawTop;
	this.getMenu = getMenu;
	this.onMenu = onMenu;
	this.showMenu = showMenu;
	this.hideMenu = hideMenu;
	this.hideAll = hideAll;
	this.selectMenu = selectMenu;
	this.unselectMenu = unselectMenu;
}
function SubMenu()
{
	this.width =100;
	this.height = 0;
	this.left = 0;
	this.top = 0;
	this.inFrame = null;
	this.topFrame = null;
	this.subFrame = null;
	this.selected = false;

	this.id = 0;
	this.objstruct = null;
	this.countid = 0;
	this.parent = new Object();
	this.functionid = null;
	this.depth = 0;
	this.frame = null;
	this.headline = null;
	this.url = null;
	this.target = null;
	this.submenu = new Object();
	this.item = new Object();
	this.length = 0;

	this.addMenu = addMenu;
	this.getMenu = getMenu;
	this.showMenu = showMenu;
	this.hideMenu = hideMenu;
	this.hideAll = hideAll;
	this.selectMenu = selectMenu;
	this.unselectMenu = unselectMenu;
}

var prevMenu = "";
var prevSelected = "";

function addMenu(id, headline, url, target)
{
	var arg = addMenu.arguments;
	if(arg.length > 2)
	{
		this.submenu[id] = new SubMenu();
		this.submenu[id].id = id;
		this.submenu[id].parent = this;
		if(this.depth > 0)
		{
			this.submenu[id].objstruct = this.objstruct + ".item[" + this.length + "]";
			this.submenu[id].countid = this.countid + this.length + "_";
			this.submenu[id].inFrame = this.subFrame;
		}
		else
		{
			this.submenu[id].objstruct = "this.item[" + this.length + "]";
			this.submenu[id].countid = "c" + this.length + "_";
			this.submenu[id].inFrame = this.topFrame;
		}
		this.submenu[id].topFrame = this.topFrame;
		this.submenu[id].subFrame = this.subFrame;
		this.submenu[id].functionid = this.functionid;
		this.submenu[id].depth = this.depth + 1;
		this.submenu[id].frame = window.name;
		this.submenu[id].headline = headline;
		this.submenu[id].url = url;
		if(target)
			this.submenu[id].target = target;
		this.item[this.length] = this.submenu[id];
		this.length ++;
	}
	else
		alert('Too few arguments when calling function \'addMenu\'\n\nSyntax:addMenu(ID, Headline, URL [,Target]);');
}

function drawMenu()
{
	document.write(this.getMenu(0));
	if(mouseUp)
		document.onclick = mouseUp;
}

function drawTop()
{
//	alert(this.getMenu(1));
	document.write(this.getMenu(1));
	if(mouseUp)
		document.onclick = mouseUp;
}

function drawSub()
{
	document.write(this.getMenu(2));
	if(mouseUp)
		document.onclick = mouseUp;
}
function mouseUp()
	{
		dropdown.hideAll();
	}
function getMenu(drawType)
{
	var text = "";
	if(this.length > 0)
	{
		var onmouseover = "";
		var show = "";
		var url;
		var target;
		var left = this.left;
		var top = this.top;
		var className;
		var i;
		var c = 0;
		var obj;
		var rowwidth = 0;

		if(this.depth == 1 && drawType != 2)
			top += this.height+7;
		else if(this.depth > 1)
		{
			top += 4;
			left += this.width-3;
		}

		if(this.depth == 0)
		{
			if(document.all)
				show = "visibility: visible;";
			else
				show = "visibility=\"show\"";
			className = "topbg";
			for(c = 0; c < this.length; c ++)
				rowwidth += this.item[c].width;
		}
		else
		{
			if(document.all)
				show = "visibility: hidden;";
			else
				show = "visibility=\"hide\"";
			className = "subbg";
			for(i = 0; i < this.length; i ++)
				if(this.item[i].width > rowwidth)
					rowwidth = this.item[i].width;
		}
		if(document.all)
			text += "<div class=\"" + className + "\" id=\"" + this.countid + "\" name=\"" + this.countid + "\" style=\"z-index: 10; position: absolute; width: " + rowwidth + "px; left: " + left + "px; top: " + top + "px; " + show + " cursor: default;\">";
		else
			text += "<layer class=\"" + className + "\" id=\"" + this.countid + "\" name=\"" + this.countid + "\" left=\"" + left + "\" top=\"" + top + "\" " + show + ">";
		text += "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"" + rowwidth + "\">";
		if(this.depth == 0)
			text += "<tr>";
			for(i = 0; i < this.length; i ++)
			{
				if(this.depth == 0 && i > 0)
					left += this.item[i-1].width+2;
				else if(i > 0)
					top += this.item[i-1].height;

				this.item[i].left = left;
				this.item[i].top = top;

				if(this.depth > 0 && this.item[i].length > 0)
					className = "submenu_children";
				else if(this.depth > 0)
					className = "submenu";
				else
					className = "topmenu";

				if(this.depth > 0)
					text += "<tr>";

				if(this.item[i].url != null && this.item[i].url != "")
					url = " href=\"" + this.item[i].url + "\"";
				else
					url = " href=\"::\" onclick=\"return false;\"";
				if(this.item[i].target != null && this.item[i].target != "")
					target = " target=\"" + this.item[i].target + "\"";
				else
					target = "";
				
				text += "<td class=\"" + className + "\" id=\"td" + this.item[i].countid + "\" onmouseover=\"" + this.functionid + ".onMenu(\'" + this.item[i].objstruct + "\');\" width=\"" + this.item[i].width + "\" height=\"" + this.item[i].height + "\" nowrap>";
				if(document.all)
					text += "<a" +  url + target + ">" + this.item[i].headline + "</a>";
				else
					text += "<a" +  url + target + " onmouseover=\"" + this.functionid + ".onMenu(\'" + this.item[i].objstruct + "\');\">" + this.item[i].headline + "</a>";
				text += "</td>";
				
				
				if(this.depth > 0)
					text += "</tr>";
			}
		if(this.depth == 0)
			text += "</tr>";
		text += "</table>";
		if(document.all)
			text += "</div>";
		else
			text += "</layer>";

		if(drawType == 2 && this.depth == 0)
			text = "";
		if(drawType != 1)
		{
			for(i = 0; i < this.length; i ++)
				text += this.item[i].getMenu(drawType);
		}
	}
	return text;
}

function onMenu(o)
{
	o = eval(o);

	if(prevMenu != "")
	{
		prevMenu = eval(prevMenu);
		if(o.depth <= prevMenu.depth && o.countid != prevMenu.countid)
		{
			prevMenu.hideMenu();
			prevMenu = "";
		}
	}
	if(document.all)
	{
		if(o.parent)
			o.parent.unselectMenu();
		o.selectMenu();
	}
	o.showMenu();
}

function showMenu()
{
	if(this.length > 0)
	{
		prevMenu = this.objstruct;
		if(document.all)
		{
			if(eval(this.item[0].inFrame + '.' + this.countid))
			{
				eval(this.item[0].inFrame + '.' + this.countid).style.top = this.item[0].top + eval(this.item[0].inFrame).document.body.scrollTop + 1;
				eval(this.item[0].inFrame + '.' + this.countid).style.visibility = "visible";
			}
//			for(var i = 0; i < eval(this.item[0].inFrame).document.forms.length; i++)
//			    for(var n = 0; n < eval(this.item[0].inFrame).document.forms[i].elements.length; n++)
//					if(eval(this.item[0].inFrame).document.forms[i].elements[n].type.substring(0,6) == "select")
//						eval(this.item[0].inFrame).document.forms[i].elements[n].style.visibility = "hidden";
		}
		else
		{
			if(eval(this.item[0].inFrame + '.document.' + this.countid))
				eval(this.item[0].inFrame + '.document.' + this.countid).visibility = "show";
		}
	}
}

function hideMenu()
{
	if(document.all)
	{
		var div = eval(this.item[0].inFrame + '.' + this.countid);
		if(div)
			div.style.visibility = "hidden";
	}
	else
	{
		var div = eval(this.item[0].inFrame + '.document.' + this.countid);
		if(div)
			div.visibility = "hide";
	}
	for(var i = 0; i < this.length; i ++)
	{
		if(this.item[i].length > 0)
			this.item[i].hideMenu();
	}
}

function hideAll()
{
	if(document.all)
	{
//		for(var i = 0; i < eval(this.item[0].inFrame).document.forms.length; i++)
//		    for(var n = 0; n < eval(this.item[0].inFrame).document.forms[i].elements.length; n++)
//				if(eval(this.item[0].inFrame).document.forms[i].elements[n].type.substring(0,6) == "select")
//					eval(this.item[0].inFrame).document.forms[i].elements[n].style.visibility = "visible";
	}
	if(this.item[0].parent.countid != "root")
	{
		if(document.all)
		{
			if(eval(this.item[0].inFrame + '.' + this.countid))
				eval(this.item[0].inFrame + '.' + this.countid).style.visibility = "hidden";
		}
		else
		{
			if(eval(this.item[0].inFrame + '.document.' + this.countid))
				eval(this.item[0].inFrame + '.document.' + this.countid).visibility = "hide";
		}
	}
	for(var i = 0; i < this.length; i ++)
	{
		if(document.all)
		{
			classObj = eval(this.item[i].inFrame + '.td' + this.item[i].countid);
			if(classObj)
			{
				if(classObj.className.substr(classObj.className.length-4) == "Over")
					classObj.className = classObj.className.substr(0, classObj.className.length-4);
			}
		}
		if(this.item[i].length > 0)
			this.item[i].hideAll();
	}
}

function selectMenu()
{
	className = eval('td' + this.countid).className;
	if(className.substr(className.length-4) != "Over")
		eval('td' + this.countid).className = className + 'Over';
}

function unselectMenu()
{
	for(var i = 0; i < this.length; i ++)
	{
		if(this.item[i].length > 0)
			this.item[i].unselectMenu();

		classObj = eval(this.item[i].inFrame + '.td' + this.item[i].countid);
		if(classObj)
		{
			if(classObj.className.substr(classObj.className.length-4) == "Over")
			{
				classObj.className = classObj.className.substr(0, classObj.className.length-4);
				break;
			}
		}
	}
}


