// 2005, 2hjh

// benötigt browser_detect.js !

var correctX = 0;
var correctY = 0;

var lastMenuActuator = null;

if (!document.getElementById)
    document.getElementById = function() { return null; }

//alert(BrowserDetect.browser);

if (BrowserDetect.browser == "Explorer")
{
	var ieversion = 0;
	
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) // test for MSIE x.x;
	{
		ieversion = new Number(RegExp.$1); // capture x.x portion and store as a number
	}
	
	if (ieversion >= 8)
	{
		correctY = -20;
	}
}
else if (BrowserDetect.browser == "Firefox")
{
	if (BrowserDetect.OS == "Mac")
	{
		correctY = -7;
	}
	else
	{
		correctY = -8;
	}
}
else if (BrowserDetect.browser == "Safari")
{
	correctX = 1;
	correctY = -7;
}

// menuID = div layer
// actuatorID = anchor
function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;

    //if (window.opera) return; // I'm too tired

    actuator.onmouseover = function() {
		// letztes menu verstecken, wenn vorhanden
		if (lastMenuActuator != null) {
			if (lastMenuActuator != actuator) {
				lastMenuActuator.hideMenu();
			}
		}
		// dieses menu anzeigen, wenn nicht schon angezeigt
		if (lastMenuActuator == null) {
			if (lastMenuActuator != actuator) {
				actuator.showMenu();
			}
		}
    }

	actuator.showMenu = function() {
        menu.style.left = findPosX(actuator) + 170 + correctX + "px";
        menu.style.top = findPosY(actuator) + correctY + "px";
        menu.style.visibility = "visible";
		lastMenuActuator = actuator;
    }
	
	actuator.hideMenu = function() {
		menu.style.visibility = "hidden";
		lastMenuActuator = null;
	}
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}
