/**
 * Menu 990702
 * by gary smith, July 1997
 * Copyright (c) 1997-1999 Netscape Communications Corp.
 *
 * Netscape grants you a royalty free license to use or modify this
 * software provided that this copyright notice appears on all copies.
 * This software is provided "AS IS," without a warranty of any kind.
 */

// To now if inside or outside of menu
var outside=true; 

function Menu(label) 
{
    this.type = "Menu";
    this.fontSize = 14;
    this.fontWeight = "plain";
    this.fontFamily = "arial,helvetica,espy,sans-serif";
    this.fontColor = "#000000";
    this.fontColorHilite = "#ffffff";
    this.bgColor = "#555555";
    this.menuBorder = 1;
    this.menuItemBorder = 1;
    this.menuItemBgColor = "#cccccc";
    this.menuLiteBgColor = "#ffffff";
    this.menuBorderBgColor = "#777777";
    this.menuHiliteBgColor = "#000084";
    this.menuContainerBgColor = "#cccccc";
    this.childMenuIcon = "images/arrows.gif";
    this.childMenuIconHilite = "images/arrows2.gif";
    this.defaultMenuItemWidth = 200;
    this.defaultMenuItemHeight = 20;
    this.items = new Array();
    this.actions = new Array();
    this.colors = new Array();
    this.mouseovers = new Array();
    this.mouseouts = new Array();
    this.childMenus = new Array();
		
    this.addMenuItem = addMenuItem;
    this.writeMenus = writeMenus;
    this.showMenu = showMenu;
    this.mouseTracker = mouseTracker;
    this.setMouseTracker = setMouseTracker;

    if (!window.menus) window.menus = new Array();
    this.label = label || "menuLabel" + window.menus.length;
    window.menus[this.label] = this;
    window.menus[window.menus.length] = this;
    if (!window.activeMenus) window.activeMenus = new Array();
    if (!window.menuContainers) window.menuContainers = new Array();
    if (!window.mDrag) 
    {
        window.mDrag    = new Object();
        this.setMouseTracker();
    }
}

function addMenuItem(label, action, color, mouseover, mouseout) 
{
    this.items[this.items.length] = label;
    this.actions[this.actions.length] = action;
    this.colors[this.colors.length] = color;
    this.mouseovers[this.mouseovers.length] = mouseover;
    this.mouseouts[this.mouseouts.length] = mouseout;
}

function writeMenus() 
{
    if ( document.getElementById ) 
    {
        if (!document.getElementById("simpleMenuContainer")) 
        {
            document.writeln('<SPAN ID="simpleMenuContainer"><div id="menuDiv"></div></SPAN>');
        }
    }
    window.wroteMenu = true;
}


function outSimpleMenu(e) 
{
    outside=true;
    if (  window.currentMenu && (window.currentMenu.enableHideOnMouseOut == true))
    {
    	document.getElementById('menuDiv').style.visibility='hidden';
    }
}

function onSimpleMenuItemOver(e, l, a) 
{
    outside=false;
    l.style.background = window.currentMenu.menuHiliteBgColor;
    l.style.color= window.currentMenu.fontColorHilite;
}

function onSimpleMenuItemOut(e, l, a) 
{
    l.style.background = window.currentMenu.menuItemBgColor;
    l.style.color = window.currentMenu.fontColor;
}

function onSimpleMenuItemAction(e, l, i) 
{
    document.getElementById('menuDiv').style.visibility='hidden';
    if ( window.currentMenu )
    {
    	eval("" + window.currentMenu.actions[i]);
    }
}

function hideMenu(menu)
{
    if ( outside && window.wroteMenu )
    {
        document.getElementById('menuDiv').style.visibility='hidden';
    }
}
document.onmousedown = hideMenu;


function showMenu(menu, x, y) 
{
    if (!window.wroteMenu) return;

	if (document.getElementById) 
    {
		menu.menuItemHeight = menu.menuItemHeight || menu.defaultMenuItemHeight;
        menu.menuItemWidth = menu.menuItemWidth || menu.defaultMenuItemWidth;

        var menuString = '<div id="menuDiv" STYLE="background:#444444;color='+menu.fontColor+';position:absolute;left:' + window.pageX +';top:' + window.pageY +';visibility:visible;" onMouseOut="outSimpleMenu();">'
                +'<table border=0 cellspacing=1 cellpadding=2 width='+menu.defaultMenuItemWidth+'>';
			
        for (var i=0; i<menu.items.length; i++) 
        {
            var item = menu.items[i];
            menuString += '<tr STYLE="background:'+menu.menuItemBgColor+';"><td style="font-family:'+menu.fontFamily+';font-weight:'+menu.fontWeight+';font-size:'+menu.fontSize+';" width='+menu.menuItemWidth+' height='+menu.menuItemHeight+' onMouseOver="onSimpleMenuItemOver(null,this);" onMouseOut="onSimpleMenuItemOut(null,this);" onClick="onSimpleMenuItemAction( null ,this, ' + i + ' );">' + item + '</td></tr>';
 		}

        menuString += '</table></div>';
    	document.getElementById('simpleMenuContainer').innerHTML = menuString;
        window.currentMenu = menu;
        
    }
}

function mouseTracker(e) 
{
    e = e || window.Event || window.event;
    window.pageX = e.pageX || (e.clientX + document.body.scrollLeft);
    window.pageY = e.pageY || (e.clientY + document.body.scrollTop);
}

function setMouseTracker() 
{
    if (document.captureEvents) {
        document.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
    }
    document.onmousemove = this.mouseTracker;
}
