//+-----------------------------------------------------------------------------+
//| zimtkorn GmbH                                                               |
//| Gjuchstrasse 19                                                             |
//| 8953 Dietikon                                                               |
//+-----------------------------------------------------------------------------+
//| Projektbezeichnung: yourinternet                                            |
//+-----------------------------------------------------------------------------+
//| Datei:              menu.js                                                 |
//+-----------------------------------------------------------------------------+
//| Das Urheberrecht an diesem Dokument (Code) verbleibt auf unbeschränkte Zeit |
//| bei der zimtkorn GmbH, Dietikon. Ohne deren schriftliche Einwilligung darf  |
//| es weder vervielfaeltigt, veraendert noch an Dritte, auch nicht in abgeaen- |
//| derter Form, ganz oder teilweise mitgeteilt, zugaenglich oder nutzbar ge-   |
//| macht werden. Dieses Dokument ist nach Art. 2 Abs. 3 URG urheberrechtlich   |
//| geschützt. Des weiteren gelten die Allgemeinen Geschäftsbedingungen der     |
//| zimtkorn GmbH, Dietikon                                                     |
//+-----------------------------------------------------------------------------+
// 
// Development History:
// 2002-06-28  ker  created
// 2002-11-22  ker  updated for use within alva.ch

var menuLevels = new Array();
var mnuX, mnuY;
var sx = 0, sy = 0;

moveHandler.add("updateCursorPos()");

function showMenu(id, indent) {
	var curLevel = menuLevels[indent];
	var curMenu = null;
	if (curLevel == null) {
		// this is the first use for this level, so create the structs
		curLevel = new Array();
		menuLevels[indent] = curLevel;
	}
	
	hideMenusFromLevel(indent);
	curMenu = curLevel[id];
	if (curMenu == null) {
		curMenu = new dynLayer("mnu" + id);
		curLevel[id] = curMenu;
		curMenu.rollIId = null;
		if (curMenu.obj == null) {
			curLevel[id] = null;
			return;
		}
	}
	
	if (bDHTML) {
		sx = document.body.scrollLeft;
		sy = document.body.scrollTop;
	}
	if (indent == 0) {
		curMenu.pos(156, 124 + 16 * id);
	}
	else {
		var parentMenu = menuLevels[indent - 1][getParentId(id)];
		curMenu.pos(parentMenu.left() + parentMenu.width() - 1 - sx, mnuY - 10 + sy);
	}
	curMenu.active = true;
	/*if (!curMenu.rollIId) {
		// roll only, if not yet rolling
		curMenu.clip(0, 0, 0, 0);
		curMenu.percent = 0;
		curMenu.rollIId = setInterval("rollMenu(\'" + id + "\'," + indent + ");", 1);
	}*/
	curMenu.vis(true);
	curMenu.event.onmouseover = function() { activateMenu(id, indent); };
	curMenu.event.onmouseout = function() { deactivateMenu(id, indent); };
}

function deactivateMenu(id, indent) {
	if (!menuLevels[indent] || !menuLevels[indent][id] || 
			!menuLevels[indent][id].obj) {
		return;
	}
	menuLevels[indent][id].active = false;
	// recursively set the active flag for the parents
	if (indent > 0) {
		deactivateMenu(getParentId(id), indent - 1);
	}
	setTimeout("hideMenu(\'" + id + "\'," + indent + ");", 1500);
}

function hideMenu(id, indent) {
	if (menuLevels[indent] && menuLevels[indent][id] && 
			menuLevels[indent][id].obj && !menuLevels[indent][id].active) {
		menuLevels[indent][id].vis(false);
		hideMenusFromLevel(indent, true);
	}
}

function activateMenu(id, indent) {
	menuLevels[indent][id].active = true;
	// recursively set the active flag for the parents
	if (indent > 0) {
		activateMenu(getParentId(id), indent - 1);
	}
}

function hideMenusFromLevel(indent, bWatch) {
	// hide all menus that are in this or higher levels
	for (var l = indent; menuLevels[l] != null; l++) {
		for (var k in menuLevels[l]) {
			if (menuLevels[l][k] && menuLevels[l][k].obj && 
					(!bWatch || !menuLevels[l][k].active)) {
				menuLevels[l][k].vis(false);
			}
		}
	}
}

function rollMenu(id, indent) {
	var curMenu = menuLevels[indent][id];
	if (curMenu.percent > 100) {
		clearInterval(curMenu.rollIId);
		curMenu.rollIId = null;
		curMenu.percent = 0;
		return;
	}
	curMenu.clip(0, 0, curMenu.width() * curMenu.percent / 100, curMenu.height() * curMenu.percent / 100);
	curMenu.percent += 4;
}

function getParentId(id) {
	var pos = id.lastIndexOf("_");
	var pid = id.substring(0, pos);
	return pid;
}

function updateCursorPos() {
	if (bDHTML) {
		mnuX = event.clientX;
		mnuY = event.clientY;
	}
	else {
		mnuX = event.pageX;
		mnuY = event.pageY;
	}
}
