
// menubar.js

// Author: ing. E.J. Loman

// Remarks: This code has been tested on:
//		- Internet Explorer 6.0
//		- Mozilla 1.0
//		- Opera 6.04
//
// Note: Use the Verdana font to view this code in all its glory :)

// Copyright 2002 by B-ware Business Software

var m_eOver = null;
var m_eMenu = null;

var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)
var isMozilla = (navigator.userAgent.indexOf('Mozilla') != -1) && !isIE && !isOpera;

function showMenu(e, mnu)
{
	hideMenu();

	m_eOver = e
	if (m_eOver) 
	{
		m_eOver.style.backgroundColor = "#ff0000";
		if (isMozilla) {
			m_eOver.addEventListener("mouseout", onmouseout, false);
		} else {
			m_eOver.onmouseout = onmouseout;
		}
	}

	m_eMenu = document.getElementById(mnu);

	if (m_eMenu)
	{
		var n = 0;
		while (e.tagName!="BODY")
		{
			n = n + e.offsetLeft;
			e = e.offsetParent;
		}
		var o = m_eMenu.style;

		if (isIE)
		{
			o.filter = "alpha(opacity=88);"; 
		}
		else if (isMozilla)
		{
			o.MozOpacity = "0.88";
			n = n + 2
		}
		o.backgroundColor = "#666666";
		o.left = n;
		o.visibility = "visible";

		if (isMozilla) {
			m_eMenu.addEventListener("mouseout", onmouseout, false);
		} else {
			m_eMenu.onmouseout = onmouseout;
		}

	}
}

function onmouseout(e)
{
	if (!e) e = window.event;

	if (isMozilla)
		e = e.relatedTarget;
	else
		e = e.toElement;

	if (m_eMenu)
	{
		if (!contains(m_eMenu, e))
		{
			hideMenu();
		}
	}
	else
	{
		hideMenu();
	}
}

function hideMenu()
{
	if (m_eMenu)
	{
		if (isMozilla)
		{
			m_eMenu.removeEventListener("mouseout", onmouseout, false);
		}

		m_eMenu.style.visibility = "hidden";
		m_eMenu = null;
	}
	if (m_eOver)
	{
		m_eOver.style.backgroundColor = "ffffff";
		m_eOver = null;
	}
}

// return true when a contains b
function contains(a, b)
{
	while (b)
	{
		if ((b = b.parentNode) == a) 
		{
			return true;
		}
	}
	return false;
}

// highlights the specified element
function highlight(e, b)
{
	if (b != 0)
	{
		e.style.backgroundColor = "#ff0000";
	} 
	else
	{
		e.style.backgroundColor = "";
	}
}

