var IEMac = (navigator.appVersion.indexOf("Mac") != -1 && navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var NS4 = document.layers ? true : false;

if (IEMac) {
	window.onresize = OnIEMacResize;
}

function OnIEMacResize() {
	location.reload(false);
}

// Ein Menu-Eintrag
function menu(name, text, offColor, onColor, url, parent, strobject) {
	// Attribute
	this.name = name;
	this.text = text;
	this.offColor = offColor;
	this.onColor = onColor;
	this.url = url;
	this.parent = parent;
	this.strobject = (strobject == null ? name : strobject);
	this.root = (parent == null ? this : parent.root);
	this.children = null;
	this.obj = null;
	this.childLayer = null;
	this.childLayerStyle = null;
	this.childLayerWidth = null;
	this.childLayerLeft = null;
	this.top = null;
	this.hTimeout = null;
	this.activ = false;
	this.leftIsSet = false;
	this.topIsSet = false;

	// Methoden
	this.add = menuAdd;
	this.showChildren = menuShowChildren;
	this.create = menuCreate;
	this.getObj = menuGetObj;
	this.getChildLayer = menuGetChildLayer;
	this.getChildLayerStyle = menuGetChildLayerStyle;
	this.getChildLayerWidth = menuGetChildLayerWidth;
	this.getChildLayerLeft = menuGetChildLayerLeft;
	this.setChildLayerLeft = menuSetChildLayerLeft;
	this.setChildLayerTop = menuSetChildLayerTop;
	this.getTop = menuGetTop;
	this.createTimeout = menuCreateTimeout;
	this.killTimeout = menuKillTimeout; 
}

function menuAdd(text, url, width, offColor, onColor) {
	var i;
	if (this.children == null)
		this.children = new Array();
	i = this.children.length;
	if (offColor == null) {
		offColor = this.offColor;
	}
	if (onColor == null) {
		onColor = this.onColor;
	}
	this.children[i] = new menu(this.name + '_' + i, text, offColor, onColor, url, this, this.strobject + '.children[' + i + ']');
	if (width != null) {
		this.childLayerWidth = this.childLayerWidth == null ? width : 0;
		this.childLayerWidth = this.childLayerWidth > width ? this.childLayerWidth : width;
	}
	return this.children[i];
}

function menuShowChildren(show) {
	show = (show == null ? true : show);
	if (show) {
		this.activ = true;
		this.parent.showChildren(false);
		this.activ = false;
		if (this.getChildLayerStyle() != null) {
			this.setChildLayerTop();
			this.setChildLayerLeft();
			this.getChildLayerStyle().visibility = "visible";
		}
		if (this.getObj() != null) {
			this.getObj().bgColor = this.onColor;
		}
	}
	else {
		var noActivChild = true;
		if (this.children != null) {
			var i;
			for (i = 0; i < this.children.length; i++) {
				if (this.children[i].activ) {
					noActivChild = false;
				}
				this.children[i].showChildren(false);
			}
		}
		if (this.parent != null && this.getChildLayerStyle() != null && noActivChild) {
			this.getChildLayerStyle().visibility = "hidden";
		}
		if (this.getObj() != null && noActivChild) {
			this.getObj().bgColor = this.offColor;
		}
	}
}

function menuCreate(layer) {
	if (this.children != null) {
		var i;
		with (document) {
			if (layer) {
				write('<div id=childLayer' + this.name + ' name=childLayer' + this.name + ' class=submenu>');
			} 
			else {
				write('<table border=0 cellspacing=0 cellpadding=0 id=childLayer' + this.name + '><tr><td>');
			}
			write('<table border=0 cellspacing=0 cellpadding=0 class=menuborder');
			write(this.childLayerWidth != null ? ' width=' + this.childLayerWidth : '');
			write('>');
			for (i = 0; i < this.children.length; i++) {
				write('<tr><td class=menuborder id=' + this.children[i].name + ' bgcolor=' + this.children[i].offColor);
				write(' onmouseover="' + this.root.name + '.killTimeout(); ' + this.children[i].strobject + '.showChildren();"');
				write(' onmouseout="' + this.root.name + '.createTimeout()"');
				write(' onclick="location.href=\'' + this.children[i].url + '\'"');
				if (!NS4) {
					write(' style="cursor:pointer"');
				}
				write('>');
				write('<a class=menulink href="' + this.children[i].url + '">' + this.children[i].text + '</a>');
				write('</td></tr>');
			}
			writeln('</table>');
			if (layer) {
				write('</div>');
			}
			else {
				write('</td></tr></table>');
			}
		}
		for (i = 0; i < this.children.length; i++) {
			this.children[i].create(true);
		}
	}
}

function menuGetObj() {
	if (this.obj == null) {
		if (this.name != null) {
			this.obj = findObject(this.name);
		}
	}
	return this.obj;
}

function menuGetChildLayer() {
	if (this.childLayer == null) {
		if (this.name != null) {
			this.childLayer = findObject('childLayer' + this.name);
		}
	}
	return this.childLayer;
}

function menuGetChildLayerStyle() {
	if (this.childLayerStyle == null) {
		var obj = this.getChildLayer();
		if (obj == null)
			this.childLayerStyle = null;
		else if (document.getElementById || document.all)
			this.childLayerStyle = obj.style;
		else if (document.layers)
			this.childLayerStyle = obj;
	}
	return this.childLayerStyle;
}

function menuGetChildLayerWidth() {
	if (this.childLayerWidth == null && this.getChildLayer() != null) {
		this.childLayerWidth = 0;
		if (this.getChildLayer().offsetWidth) {
			this.childLayerWidth = this.getChildLayer().offsetWidth;
		}
		else if (this.getChildLayerStyle().pixelHeight) {
			this.childLayerWidth = this.getChildLayerStyle().pixelHeight;
		}
	}
	return this.childLayerWidth;
}

function menuGetChildLayerLeft() {
	if (this.childLayerLeft == null) {
		this.childLayerLeft = 0;
		if (this.parent != null) {
			this.childLayerLeft = this.parent.getChildLayerLeft() + this.parent.getChildLayerWidth();
		}
		else {
			var mnu = this.getChildLayer();
			while (mnu != null) {
				this.childLayerLeft += mnu.offsetLeft;
				mnu = mnu.offsetParent;
			}
			if (this.getChildLayer() != null) {
				if (IEMac) {
					this.childLayerLeft -= this.getChildLayer().offsetParent.offsetLeft - 4;
				}
			}
		}
	}
	return this.childLayerLeft;
}

function menuSetChildLayerLeft() {
	if (!this.leftIsSet && this.getChildLayerStyle() != null) {
		this.getChildLayerStyle().left = this.getChildLayerLeft() + "px";
		this.leftIsSet = true;
	}
}

function menuSetChildLayerTop() {
	if (!this.topIsSet && this.getChildLayerStyle() != null) {
		this.getChildLayerStyle().top = this.getTop() + "px";
		this.topIsSet = true;
	}
}

function menuGetTop() {
	if (this.top == null) {
		this.top = 0;
		if (this.parent != null) {
			var i;
			for (i = 0; i < this.parent.children.length && this.parent.children[i] != this; i++) {
				if (this.parent.children[i].getObj() != null)
					this.top += this.parent.children[i].getObj().offsetHeight;
			}
			this.top += this.parent.getTop();
		}
		else {
			var mnu = this.getChildLayer();
			while (mnu != null) {
				this.top += mnu.offsetTop;
				mnu = mnu.offsetParent;
			}
			if (IEMac) {
				this.top -= this.root.getChildLayer().offsetParent.offsetParent.offsetTop;
			}
		}
	}
	return this.top;
}

function menuCreateTimeout() {
	this.root.hTimeout = setTimeout(this.root.name + ".showChildren(false)", 500)
}

function menuKillTimeout() {
	clearTimeout(this.root.hTimeout);
	this.root.hTimeout = null;
}

function findObject(name) {
	var obj = null;
	if (name == null)
		obj = null;
	else if (document.all)
		obj = document.all[name];
	else if (document.getElementById)
		obj = document.getElementById(name);
	else if (document.layers)
		obj = findLayer(document.layers, name);
	return obj;
}

var abc = false;

function findLayer(layers, name) {
	var layer = null;
	var i;
	for (i = 0; i < layers.length; i++) {
		if (layers[i].id == name)
			layer = layers[i];
		else if (layers[i].layers.length > 0)
			layer = findLayer(layers[i].layers, name);
		if (layer != null)
			break;
	}
	return layer;
}