// Menu.js

function Menu(name)
{
    this.name = name;
    this.ctrl = null;
    
    this.addmenuitem = AddMenuItem;
    
    CreateMenu(this);
    
    function CreateMenu(menu)
    {
        var host = document.getElementById("menuHost");
        
        var td = document.createElement("TD");
        td.vAlign = "top";
        host.appendChild(td);
        
        var menuTbl = document.createElement("TABLE");
        var menuBody = document.createElement("TBODY");
        var menuRow = document.createElement("TR");
        var menuCell = document.createElement("TD");
        menuTbl.appendChild(menuBody);
        menuBody.appendChild(menuRow);
        menuRow.appendChild(menuCell);
        
        td.appendChild(menuTbl);
        
        menuTbl.cellPadding = 0;
        menuTbl.cellSpacing = 1;
        
        menuCell.innerHTML = menu.name;
        menuCell.style.backgroundColor = "Blue";  
        menuCell.style.border = "1px solid Lightgrey";  
        menuCell.style.fontWeight="Bold"; 
        menuCell.colSpan = 2;
        menuCell.align = "center";
        
        menu.ctrl = menuBody;
    }
    
    function AddMenuItem(name, url, graphic, highlight, blob)
    {
        if(this.ctrl == null)
            return;
        
        var menuRow = document.createElement("TR");
        var graphCell = document.createElement("TD");
        var linkCell = document.createElement("TD");

        var graph = document.createElement("IMG");
        var link = document.createElement("A");
        
        menuRow.appendChild(graphCell);
        menuRow.appendChild(linkCell);
        graphCell.appendChild(graph);
        linkCell.appendChild(link);
        this.ctrl.appendChild(menuRow);
        
        graphCell.style.border = "1px solid gray";   
        
        linkCell.onmouseover = new Function("this.style.backgroundColor='#555555';");
        linkCell.onmouseout = new Function("this.style.backgroundColor='transparent';");
        linkCell.style.border = "1px solid gray";
        linkCell.align = "left";
        
        graph.src = "images/" + graphic;
        graph.style.width="35px";
        graph.style.height="25px";
        
        link.href = url;
        link.innerHTML = name;
        link.target = "_blank";  
        link.style.color = "white";    
        if(highlight != null && highlight == true)
        {
            link.style.fontWeight = "bold";
            link.style.color = "Yellow";
        }
        
        if(typeof(blob) != 'undefined')
        {
            var s = document.createElement("SPAN");
            linkCell.appendChild(s);
            s.style.fontSize = "8pt";
            s.style.fontStyle = "Italic";
            s.style.paddingLeft = "10px";
            s.innerHTML = blob;
        }
    }
    
}