﻿SubMenuPopupTimer = 0;

// Menu Object
function Menu(MenuName, TableClass, RowClass, ActiveClass) {
    if (!window.Menus) Menus = new Array();
    this.menuName = MenuName;
    this.items = new Array();
    this.tableClass = TableClass;
    this.rowClass = RowClass;
    this.activeClass = ActiveClass;
    this.container = null;
    this.addItem = MenuAddItem;
    this.addJSItem = MenuAddJSItem;
    this.addBreak = MenuAddBreak;
    this.Render = MenuRender;
    this.Hide = MenuHide;
    
    Menus[MenuName] = this;
}

function MenuAddItem(Display,Link) {
    if (Link.indexOf(':') == -1){
        Link = SiteURL + Link;
    }
    this.items.push (new MenuItem(this, Display, Link));
}

function MenuAddJSItem(Display, Link) {
    this.items.push (new MenuJSItem(this, Display, Link));
}

function MenuAddBreak() {
    this.items.push (new MenuBreak());
}

function MenuRender(x, y) {
    if (document.readyState) {
        if (document.readyState!='complete') return;        
    }
    
    if (this.container == null) {
        this.container = document.createElement('DIV'); 
        this.container.style.position = 'ABSOLUTE';
        document.body.appendChild(this.container);
        
        var table = document.createElement('TABLE'); 
        table.className = this.tableClass;
        table.cellSpacing=0;
        table.cellPadding=0;
        this.container.appendChild(table);
        
        var TableBody = document.createElement('TBODY');
        table.appendChild (TableBody);
        
        for (var i=0; i<this.items.length; i++) {
            this.items[i].Render(TableBody, this);
        }
        
    } else {
        this.container.style.display='block';
    }
    this.container.style.left = x+'px';
    this.container.style.top = y+'px';
}

function MenuHide() {
    if (this.container) {
        this.container.style.display='none';
        window.status='';
    }
}

// MenuItem Object

function MenuItem(Parent,Display,Link) {
    this.parent = Parent;
    this.display = Display;
    this.link = Link;
    this.Render = MenuItemRender;
}

function MenuItemRender(aTableParent, aParent) {
    
    var NewRow=document.createElement('TR');
    aTableParent.appendChild (NewRow);
    
    var NewCell=document.createElement('TD');
    NewCell.innerHTML = '&nbsp;<a href="' +this.link+ '">' + this.display + '</a>&nbsp;';
    NewCell.className = aParent.rowClass;
    
    NewCell.onmouseover = ClearTimer;
    NewCell.onmouseout = SetNewTimer;
    NewCell.parent = aParent;
    NewCell.menuItem = this;
    NewRow.appendChild(NewCell);
    
}

function MenuItemMouseOver() {
    this.className = this.parent.activeClass;
    window.status = this.menuItem.link;
    ClearTimer();
}

function MenuItemMouseOut() {
    this.className = this.parent.rowClass;
    SetNewTimer();
}

function MenuItemClick() {
    window.navigate(this.menuItem.link);
}

// MenuJSItem Object

function MenuJSItem(Parent,Display,Link) {
    this.parent = Parent;
    this.display = Display;
    this.link = Link;
    this.Render = MenuJSItemRender;
}

function MenuJSItemRender(aTableParent, aParent) {
    var NewRow=document.createElement('TR');
    aTableParent.appendChild (NewRow);
    
    var NewCell=document.createElement('TD');
    NewCell.innerHTML = '&nbsp;<a href="#">' + this.display + '</a>&nbsp;';
    NewCell.onclick=MenuJSItemClick;
    NewCell.className = aParent.rowClass;
    NewCell.onmouseover = ClearTimer;
    NewCell.onmouseout = SetNewTimer;
    NewCell.parent = aParent;
    NewCell.menuItem = this;
    NewRow.appendChild(NewCell);
}

function MenuJSItemClick() {
    HideLastMenu();
    eval(this.menuItem.link);
    return false;
}

// MenuBreak Object

function MenuBreak() {
    this.Render = MenuBreakRender;
}

function MenuBreakRender(aTableParent, aParent) {
    var NewRow=document.createElement('TR');
    aTableParent.appendChild (NewRow);
    
    var NewCell=document.createElement('TD');
    NewCell.innerHTML=' ';
    NewCell.className = 'MenuRule';
    NewRow.appendChild(NewCell);
}

// IFramePopup Object

function IFramePopup(IframeName, Class, URL, XOffset) {
    if (!window.Menus) Menus = new Array();    
    this.iframeName = IframeName;
    this.styleClass = Class;
    this.url = URL;
    this.xOffset = (XOffset) ? XOffset : 0;
    this.Render = IFramePopupRender;
    this.Hide = MenuHide;
    Menus[IframeName] = this;
}

function IFramePopupRender(x, y) {
    if (this.container == null) {
        this.container = document.createElement('DIV'); 
        this.container.onmouseover=ClearTimer;
        this.container.onmouseout=SetNewTimer;
        this.container.style.position = 'ABSOLUTE';
        document.body.appendChild(this.container);
        
        var iframe = document.createElement('IFRAME'); 
        iframe.src = this.url;
        iframe.className = this.styleClass;
        iframe.frameBorder=0;
        iframe.marginWidth='0px';
        iframe.marginHeight='0px';
        iframe.scrolling='no'
        this.container.appendChild(iframe);
        
    } else {
        this.container.style.display='block';
    }
    x += this.xOffset;
    this.container.style.left = x+'px';
    this.container.style.top = y+'px';
}

// Timers

function ClearTimer() {
    if (SubMenuPopupTimer!=0){
	    window.clearTimeout(SubMenuPopupTimer);
	    SubMenuPopupTimer=0;
    }
}

function SetNewTimer() {
    ClearTimer();
    SubMenuPopupTimer=window.setTimeout("HideLastMenu()",100,"JavaScript");
}

function ShowMenu (MenuName,SrcObject) {    
    HideLastMenu();
    var EventTarget = SrcObject;
    var AnchorDiv = document.getElementById('anchorDiv');
    CurrentMenu = Menus[MenuName];   
    CurrentMenu.Render(EventTarget.offsetLeft + AnchorDiv.offsetLeft , AnchorDiv.offsetTop);
}

function HideLastMenu() {
    ClearTimer();
    if (window.CurrentMenu) CurrentMenu.Hide();
}