var menu;
function initmenu() { // Popup menu
	if (document.getElementById) {
		var menu = document.getElementById('menu');
		var toplevel = menu.childNodes;
		var x;
		for (x = 0; x < toplevel.length; x ++) {
			var curele = toplevel[x].childNodes[0];
			if (curele.tagName == 'A') {
				this.inithover(curele);
			}
		}
		this.currentmenu = false;
		this.timer = false;
	}
}
initmenu.prototype.inithover = function(ele) {
	if (ele.childNodes[0].tagName == 'IMG') {
		ele.img = ele.childNodes[0];
		var hoverimg = ele.img.src;
		hoverimg = hoverimg.replace('n__', 'o__');
		ele.hoverimg = new Image();
		ele.hoverimg.src = hoverimg;
		ele.normalimg = new Image();
		ele.normalimg.src = ele.img.src;
		ele.onmouseover = this.mouseover;
		ele.onmouseout = this.mouseout;
		var li = ele.parentNode;
		var abs = this.abs(li);
		if ((li.childNodes[1] != null) && (li.childNodes[1].tagName == 'UL')) {
			li.childNodes[1].style.left = abs[1] + 'px';
			li.childNodes[1].style.top = (abs[0] + ele.offsetHeight) + 'px';
			li.childNodes[1].style.width = ele.offsetWidth + 'px';
			li.childNodes[1].menuwidth = ele.offsetWidth - 20;
			li.childNodes[1].initted = false;
			li.childNodes[1].isvisible = false;
			li.childNodes[1].menuparent = false;
			li.childNodes[1].menubutton = ele;
		}
	}
}
initmenu.prototype.abs = function(n) {
	var t = 0,l = 0;
	while (n && (n.style.position != 'relative') && (n.id != 'layout')) {
		t += n.offsetTop; l += n.offsetLeft; n = n.offsetParent;
	}
	return [t,l];
}
initmenu.prototype.close = function() {
	menu.closeuntil(false);
}
initmenu.prototype.closesoon = function() {
	this.timer = setTimeout(this.close,1300);
}
initmenu.prototype.norush = function() {
	clearTimeout(this.timer);
}
initmenu.prototype.mouseover = function() {
	if (this.img) {
		this.img.src = this.hoverimg.src;
	}
	var ul = this.parentNode.childNodes[1];
	if ((ul != null) && (ul.tagName == 'UL')) {
		if (!ul.isvisible) {
			ul.isvisible = true;
			if (!ul.initted) {
				ul.initted = true;
				var x,y;
				for (x = 0; x < ul.childNodes.length; x ++) {
					y = ul.childNodes[x].childNodes[0];
					if (y.tagName == 'A') {
						y.onmouseover = menu.mouseover;
						y.onmouseout = menu.mouseout;
						if (navigator.userAgent.indexOf("MSIE 5") != -1) { // oldie
							y.style.width = (ul.menuwidth + 20) + 'px';
						} else {
							y.style.width = ul.menuwidth + 'px';
						}
						y.img = false;
						var li = ul.childNodes[x];
						var abs = menu.abs(li);
						if ((li.childNodes[1] != null) && (li.childNodes[1].tagName == 'UL')) {
							li.childNodes[1].style.width = '120px';
							li.childNodes[1].menuwidth = 100;
							li.childNodes[1].style.marginLeft = (ul.offsetWidth + 1) + 'px';
							li.childNodes[1].style.marginTop = li.offsetTop + 'px';
							li.childNodes[1].initted = false;
							li.childNodes[1].isvisible = false;
							li.childNodes[1].menuparent = ul;
							li.childNodes[1].menubutton = false;
						}
					}
				}
			}
			ul.style.visibility = 'visible';
			menu.closeuntil(ul.menuparent);
			menu.currentmenu = ul;
		}
	} else {
		menu.closeuntil(this.parentNode.parentNode);
	}
	menu.norush();
}
initmenu.prototype.closeuntil = function(ele) {
	while (this.currentmenu && (this.currentmenu != ele)) {
		if (this.currentmenu.menubutton) {
			this.currentmenu.menubutton.img.src = this.currentmenu.menubutton.normalimg.src;
		}
		this.currentmenu.style.visibility = 'hidden';
		this.currentmenu.isvisible = false;
		this.currentmenu = this.currentmenu.menuparent;
	}
}
initmenu.prototype.mouseout = function() {
	var ul = this.parentNode.childNodes[1];
	if (this.img) {
		if ((ul == null) || (ul.tagName != 'UL') || (!ul.isvisible)) {
			this.img.src = this.normalimg.src;
		}
	}
	menu.closesoon();
}
if (navigator.userAgent.indexOf('KHTML') != -1) {
	if (document.readyState=='complete') {
		init();
	} else {
		window.onload = init;
	}
} else {
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", init, false);
	} else {
		init();
	}
}
function fixobjects() {
	if (document.getElementById) {
		if (navigator.userAgent.indexOf("MSIE") != -1) { // ieonly
			var obj = document.getElementsByTagName('object');
			var x;
			for (x = 0; x < obj.length; x ++) {
				obj[x].outerHTML = obj[x].outerHTML;
			}
		}
	}
}
fixobjects();
