// Breite eines Menüeintrags in Pixel
var menuWidth = 152;
// Höhe eines Menüeintrags in Pixel
var menuHeight = 22;
// Verzögerung beim Einblenden der Untermenüs in Millisekunden
var menuDelay = 10;
// Zeit in Sekunden nach der das Menü automatisch wieder einklappt (0 -> nie) 
var closeMenuDelay = 5;
// Farbe des Menürahmens
var borderColor = "#004A80";
// Hintergrundfarbe des Menüs
var bgColor = "#ffffff";
// Selektierte Hintergrundfarbe des Menüs
var overBGColor = "#F16F10";
// Farbe der Menüschrift
var fontColor = "#000000";
// Selektierte Farbe der Menüschrift
var overFontColor = "#ffffff";
// Font Familie falls keine globalen Stylesheets benutzt werden
var font = "Arial,sans-serif";
// Gibt an, ob die Schriftart und -größe durch ein Stylesheet global definiert sind
// <td> und normaler Font müssen im CSS überschrieben werden
var useGlobalCSS = false;
// Pfad der Grafik
var img = "menu/pfeil.gif";
// Größe der quadratischen Grafik
var imgSize = 1;

/*********** NN4 resize handling **********/
var ww,wh;
if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4)
{
	ww = window.innerWidth;
	wh = window.innerHeight;
	window.onresize = _onresize;
}

function _onresize()
{
	if (window.innerHeight != wh || window.innerWidth != ww)
	{
		ww = window.innerWidth;
		wh = window.innerHeight;
		document.location.reload();
	} 
}

/*********** globals **********/
var menuArray = new Array();
var dl = document.layers;
var zi = 10;
var sci = null;
var osi = null;
var timer = 0;
var imgStr = "<img src='" + img + "' width=" + imgSize + " height=" + imgSize + " border=0 vspace=" + (menuHeight / 2 - imgSize / 2) + " hspace=0>";
imgStr = dl ? ("<layer left=" + (menuWidth - imgSize) + " top=0 width=" + imgSize + " height=" + menuHeight + ">" + imgStr + "</layer>") : ("<span style='height:100%;width:" + imgSize + ";float:right;overflow:hidden'>" + imgStr + "</span>");
document.onclick = hideMenu;
if (closeMenuDelay > 0)
	window.setInterval("hideMenuAutomation()", 1000);
	
function layer(l)	{return (dl ? document.layers[l] : document.all[l]);}
function subLayer(ml, l) {return (dl ? ml.document.layers[l] : document.all[l]);}

/*********** MenuItem **********/
function MenuItem_draw(it, c, bc)
{
	var content = it.content;

	if (it.child != null)
		content = imgStr + content;
		
	if (dl)
		if (useGlobalCSS)
			it.write ("<table height=" + menuHeight + " cellpadding=0 cellspacing=0><tr><td valign='middle'><font color='" + c + "'>" + content + "</td></tr></table>");
		else
			it.write ("<table height=" + menuHeight + " cellpadding=0 cellspacing=0><tr><td valign='middle'><font face='" + font + "' size=-1 color='" + c + "'>" + content + "</td></tr></table>");
	else
	{
		it.style.lineHeight = menuHeight + "px";
		it.style.color = c;
		if (!useGlobalCSS)
		{
			it.style.fontFamily = font;
			it.style.fontSize = "12px";
		}
		it.write(content);
	}
	it.setBGColor(bc);
	it.setDim(menuWidth - 1, menuHeight - 1);
}

function MenuItem_over()
{
	if (osi != null && !dl)
		MenuItem_draw(layer(osi), fontColor, bgColor);

	MenuItem_draw(this, overFontColor, overBGColor);

	timer = 0;
	osi = this.id;
	
	hideSubMenu(this.id);

	if(this.child != null)
	{
		sci = this.child.id;
		posChildMenu(this);
		window.setTimeout("showSubMenu('" + sci + "');", menuDelay);
	}
}

function MenuItem_out()
{
	osi = null;

	MenuItem_draw(this, fontColor, bgColor);	
	
	if (sci != null)
	{
		window.clearTimeout();
		sci = null;
	}
}

function MenuItem_write(t)
{
	if (dl)
	{
		this.document.open();
		this.document.write(t);
		this.document.close();
	}
	else
		this.innerHTML = t;
}

function MenuItem_click()
{
	window.document.location.href = this.url;
}

function MenuItem_setURL(u)
{
	this.url = u;	
}

function MenuItem_setContent(c)
{
	this.content = c;	
}

function MenuItem_setChild(c)
{
	this.child = c;	
}

/*********** Menu **********/
function Menu_setDim(w,h)
{
	if (dl)
	{
		this.width = w;
		this.height = h;
		this.clip.left = 0;
		this.clip.top = 0;
		this.clip.width = w;
		this.clip.height = h;
	}
	else
	{
		this.style.pixelWidth = w;
		this.style.pixelHeight = h;
		this.style.clip = 'rect(' + 0 + ',' + w + ',' + h + ',' + 0 +')';
	}
}

function Menu_setPos(x,y)
{
	if (dl)
	{
		this.left = x;
		this.top = y;
	}
	else
	{
		this.style.pixelLeft = x;
		this.style.pixelTop = y;
	}
}

function Menu_setRect(x,y,w,h)
{
	this.setDim(w,h);
	this.setPos(x,y);
}

function Menu_setZIndex(z)
{
	if (dl)
		this.zIndex = z;
	else
		this.style.zIndex = z;
}

function Menu_setBorderColor(c)
{
	if(dl)
		this.bgColor = c;
	else
		this.style.backgroundColor = c;
}

function Menu_setCount(c)
{
	this.count = c;
}

function Menu_setParent(p)
{
	this.parent = p;
}

function Menu_getLeft()
{
	if (dl)
		return this.left;
	else
		return this.style.pixelLeft;
}

function Menu_getTop()
{
	if (dl)
		return this.top;
	else
		return this.style.pixelTop;
}

function Menu_getWidth()
{
	if (dl)
		return this.width;
	else
		return this.style.pixelWidth;
}

function Menu_getHeight()
{
	if (dl)
		return this.height;
	else
		return this.style.pixelHeight;
}

function Menu_show()
{	
	if (this.parent == null)
		hideMenu(0);

	for (i = 0; i < this.count; i++)
	{
		it = subLayer(this, this.id + 'i' + i);

		it.setRect = Menu_setRect;
		it.setDim = Menu_setDim;
		it.setPos = Menu_setPos;
		it.setBGColor = Menu_setBorderColor;
		it.getLeft = Menu_getLeft;
		it.getTop = Menu_getTop;
		it.getWidth = Menu_getWidth;
		it.getHeight = Menu_getHeight;
		it.onmouseover = MenuItem_over;
		it.onmouseout = MenuItem_out;
		it.onmouseup = MenuItem_click;
		it.write = MenuItem_write;
	
		MenuItem_draw(it, fontColor, bgColor);
		it.setRect(1, i * menuHeight + 1, menuWidth - 1, menuHeight - 1);
	}
	
	if (dl)
		this.visibility = "visible";
	else
		this.style.visibility = "visible";
}

function Menu_hide()
{
	if (dl)
		this.visibility = "hidden";
	else
		this.style.visibility = "hidden";
}

/*********** general **********/
function initMenu(mnr, x, y, items)
{
	var d = layer('m' + mnr);
	var l = items.length / 2;
	
	menuArray[mnr] = d;

	d.setRect = Menu_setRect;
	d.setDim = Menu_setDim;
	d.setPos = Menu_setPos;
	d.setZIndex = Menu_setZIndex;
	d.setBorderColor = Menu_setBorderColor;
	d.setCount = Menu_setCount;
	d.setParent = Menu_setParent;
	d.getLeft = Menu_getLeft;
	d.getTop = Menu_getTop;
	d.getWidth = Menu_getWidth;
	d.getHeight = Menu_getHeight;
	d.show = Menu_show;
	d.hide = Menu_hide;
	
	d.setRect(x, y, menuWidth + 1, menuHeight * l + 1);
	d.setZIndex(zi++);
	d.setBorderColor(borderColor);
	d.setCount(l);
	d.setParent(null);
	
	for (i = 0; i < l; i++)
	{
		var it = subLayer(d, d.id + 'i' + i);
			
		if (dl)
			it.captureEvents(Event.MOUSEUP);

		it.setContent = MenuItem_setContent;
		it.setURL = MenuItem_setURL;
		it.setChild = MenuItem_setChild;
	
		it.setContent("&nbsp;&nbsp;" + items[i * 2]);
		it.setURL(items[i * 2 + 1]);
		it.setChild(null);
	}
}

function setChild(ml, sl, cml)
{
	var p = layer(ml);
	var c = layer(cml);
	c.setParent(p);
	subLayer(p, sl).setChild(c);
}

function showMenu(l)
{
	layer(l).show();
}

function showSubMenu(l)
{
	if (sci != null && sci == l)
		showMenu(l);
} 

function posChildMenu(m)
{
	var p = layer('m' + getMenuIndex(m.id));
	var x = p.getLeft() + m.getLeft() + menuWidth - imgSize - 2;
	var y = p.getTop() + m.getTop() + 3;
	var ww = dl ? window.innerWidth : document.body.clientWidth;

	if ((x + m.child.getWidth() > ww) && (p.getLeft() - menuWidth >= 0))
		x = p.getLeft() - menuWidth + imgSize + 2;

	m.child.setPos(x, y);
}

function hideMenu(l)
{
	hideMenuArray(getMenuIndex(l));
}

function hideSubMenu(l)
{
	hideMenuArray(1 + getMenuIndex(l));
}

function hideMenuArray(mnr)
{
	for (i = mnr; i < menuArray.length; i++)
		menuArray[i].hide();
	zi = 10;
}

function hideMenuAutomation()
{
	if (timer++ > closeMenuDelay)
	{
		timer = 0;
		hideMenuArray(0);
		sci = null;
	}
}

function getMenuIndex(l)
{
	var mnr = 0;
	if (l == null)
		l = 'm0'; 

	if (l.length > 0)
		if (l.indexOf('i') > 0)
			mnr = l.substring(1, l.indexOf('i'));
		else
			mnr = l.substring(1, l.length);

	return parseInt(mnr);
}
function writeMenu(mnr, cnr)
{
	document.write(dl ? ("<layer name='m" + mnr + "' visibility='hidden'>") : ("<div id='m" + mnr + "' style='position:absolute;left:0;top:0;width:2;height:2;z-index:10;visibility:hidden'>"));
	for (n = 0; n < cnr; n++)
		document.write(dl ? ("<layer name='m" + mnr + "i" + n + "'></layer>") : ("<div id='m" + mnr + "i" + n + "' style='position:absolute;left:0;top:0;width:2;height:2;z-index:10;'></div>"));
	document.write(dl ? ("</layer>") : ("</div>"));
}
function ChangeImage(Where,Which)
{
	if(Which==1)
		eval("document.images.nav" + Where + ".src='/campus/images/punkt_leer1.gif';");
	else if(Which==2)
		eval("document.images.nav" + Where + ".src='/campus/images/punkt_klein.gif';");
	else if(Which==3)
		eval("document.images.nav" + Where + ".src='/campus/images/punkt_leer.gif';");
	else
		eval("document.images.nav" + Where + ".src='/campus/images/punkt_gross3.gif';");
}
