var to=new Array(); // timout for hiding menu
var active_menu = 0;

var menuTimeOut = 500;
var menuTimeFadein = 70;
var menuOpacity = 100;

function getpos(el) {
	xPos=el.offsetLeft;
	yPos=el.offsetTop;
	el=el.offsetParent;
	while(el != null) {
		xPos +=el.offsetLeft;
	 	yPos +=el.offsetTop
		el=el.offsetParent
	}
	result = new Array(xPos,yPos);
	return new Array(xPos, yPos);
}

function id(tag) {
	return document.getElementById(tag);
}

function hidemenu(nr) {
	id("menu"+nr).style.display="none"
}

function einblenden(nr,rest) {
	step = Math.min(rest,10);
	opacity = id("menu"+nr).style.opacity * 100;
	id("menu"+nr).style.opacity = (opacity + step)/100;

	rest = rest-step;
	if (rest > 0) {
		setTimeout("einblenden("+nr+","+rest+")", menuTimeFadein);
	}

}
function align_background_in_links(tag,margin) {
	tags = tag.childNodes;
	for (i=0; i< tags.length; i++) {
		t=tags[i];
		if(t.nodeName == "A") {
			t.style.backgroundPosition=margin+"px";
		}
	}
	return;
}

function menuover(nr,e) {
	if (e) {
		coords = getpos(e);
		id("menu"+nr).style.left=coords[0]+"px";
		id("menu"+nr).style.top=coords[1]+22+"px";
		id("menu"+nr).style.zIndex=15;
		align_background_in_links(id("menu"+nr),-coords[0]-10+70);

		id("menu"+nr).style.opacity=1;
	}
	if (to[nr]) {
		clearTimeout(to[nr]);
	}
	if (active_menu != nr) {
		if (active_menu) {
			hidemenu(active_menu);
			clearTimeout(to[active_menu]);
		}
		active_menu=nr;

		id("menu"+nr).style.opacity=0.1;
		einblenden(nr,menuOpacity);
	}
	id("menu"+nr).style.display="block";
}

function menuout(nr) {
	to[nr]=setTimeout('hidemenu('+nr+')', menuTimeOut);
}

function show_it(name) {
	id(name).style.display="block";
	return false;
}
function hide_it(name) {
	id(name).style.display="none";
	return false;
}
