function menu() {
	var delay = 1000;
	var chosenClass = 'chosen';
	var normalClass = 'sub';

	var m = document.getElementById('mmenu');
	m.lastOpen = m;

	var isIE = "\v"=="v";
	var isIE6 = isIE && typeof XMLHttpRequest == 'undefined';
	
	var shift = isIE6 ? 475 : 371;

	var hideBranch = function(from) {
		for (var ob = m.lastOpen; ob != from; ob = ob.parentNode.parentNode) {
			if (ob.fixer) {
				ob.parentNode.removeChild(ob.fixer);
				ob.fixer = null;
			}
			ob.style.visibility = 'hidden';
			ob.style.width = ob.style.right = 'auto';
			ob.style.left = '';
			ob.className = '';
			ob.parentNode.getElementsByTagName('a')[0].className = normalClass;
		}
		m.lastOpen = from;
	}

	var calcWidth = function(ob, recursive) {
		var w = 0;
		var children = ob.childNodes;
		for (var i=0; children[i]; i++) {
			if (!children[i].tagName) continue;
			var branchWidth = 0;
			var uls = children[i].getElementsByTagName('ul');
			if (uls.length) {
				if (recursive) {
					branchWidth = calcWidth(uls[0], true);
				}
				else {
					children[i].getElementsByTagName('a')[0].className = normalClass;
				}
			}
			if (children[i].scrollWidth + branchWidth > w) {
				w = branchWidth + children[i].offsetWidth;
			}
		}
		return w;
	}

	var setPosition = function(ob) {
		var p = ob.parentNode;
		if (p.parentNode != m) {
			// decide whether to open a branch to the left or to the right
			if (p.parentNode.parentNode.parentNode == m) {
				var w = calcWidth(p, true);
				ob.inverse = ((document.documentElement.clientWidth||document.body.clientWidth)/2 < p.parentNode.parentNode.offsetLeft + p.parentNode.parentNode.offsetWidth + w - shift);
			}
			else ob.inverse = p.parentNode.inverse;
			if (ob.inverse) {
				ob.style.left = 'auto';
				ob.style.right = '100%';
			}
			else {
				ob.style.left = '100%';
				ob.style.right = 'auto';
			}
		}
	}
	
	var setWidth = function(ob) {
		var width = calcWidth(ob, false);
		if (ob.parentNode.parentNode == m && width < ob.parentNode.clientWidth) {
			width = ob.parentNode.offsetWidth + 1;
		}
		ob.style.width = width + 'px';
	}

	var show = function(ob) {
		setPosition(ob);
		setWidth(ob);
		m.lastOpen = ob;
		if (isIE) ob.className = 'iefix';
		if (isIE6 && !ob.fixer) {
			var i = document.createElement('iframe');
			i.style.width = ob.offsetWidth + 'px';
			i.style.height = ob.offsetHeight + 'px';
			i.style.left = ob.style.left;
			i.style.right = ob.style.right;
			ob.parentNode.appendChild(i);
			ob.fixer = i;
		}
		ob.style.visibility = 'visible';
		ob.parentNode.getElementsByTagName('a')[0].className = chosenClass;
	}

	m.onmouseover = function() {
		clearTimeout(m.hideTimer);
		var tgt = (arguments[0] && arguments[0].target) || window.event.srcElement;
		if (tgt.tagName.toLowerCase() == 'span') tgt = tgt.parentNode;
		if (tgt.tagName.toLowerCase() != 'a') return;
		var ul = tgt.parentNode.getElementsByTagName('ul')[0];
		if (m.lastOpen != ul) hideBranch(tgt.parentNode.parentNode);
		if (ul) show(ul);
	}

	m.onmouseout = function() {
		m.hideTimer = setTimeout(function() {hideBranch(m)}, delay);
	}
}

function writeML(part1, part2, text, cssClass) {
	if ( text == "") {
		text= part1 + "@" + part2;
	}
	if (cssClass != "") {
		cssClass = "class=\"" + cssClass + "\"";
	}
	document.write(" <a href=\"mailto:" + part1 + "@" + part2 + "\""+ cssClass +">" + text + "</a>");
}

function checkSearchForm(form) {
	form.keyword.value = form.keyword.value.replace(/^\s+|\s+$/, '');
	if (form.keyword.value == '') {
		form.keyword.focus();
		return false;
	}
}

/* attempt to fix IE6 background flickering because of bad cache operation */
try {
	document.execCommand("BackgroundImageCache", false, true);
} catch(err) {/* not IE6 or no need to fix it */}