<!-- Published: 7/19/2004 13:15 -->
function addMenu(width, leftmargin, identsize) {
	var menuID = MENUS.length;
	MENUS[menuID] = new MenuRootObj(width, leftmargin, identsize);
	return menuID;
}
function getMenu(menuID) {
	return (MENUS[menuID]);
}

function M(menuID, level, label, href) 
{
	if ((href.indexOf('.jsp')>0) || (href.indexOf('.html')>0))
		Menu(menuID, level, label, href);
	else
		Menu(menuID, level, label, href+'/index.jsp');
}

function Menu(menuID, level, label, href) {
	var root = MENUS[menuID];
	switch(level) {
		case 0: var suffix = "X"; break;
		case 1: var suffix = "XX"; break;
		case 2: var suffix = "XXX"; break;
		case 3: var suffix = "XXXX"; break;
	}
	var prefix = root.prefix;

	var newItem = new ItemObj (root.curID, level, label, href, root.width);
	if (prefix == "VT") VTlookUpTable[newItem.ID] = newItem;
	root.curID++;

	if (level == root.curLevel) {//Keep adding items to the current menu
		if (!root.curMenu) {
			root.curMenu = new MenuObj(prefix, suffix);
			root.curMenu.root = root;
			if (!root.menuRoot) {
				root.menuRoot = root.curMenu;
				if (prefix == "VT") VTROOT = root.curMenu;
			};
		}
		root.curItem = newItem;
		root.curMenu.addItem(newItem);
	} else if (level == root.curLevel+1) {//Create a submenu for the current item and add its first item
		var newMenu = new MenuObj(prefix, suffix);
		newMenu.root = root;
		newMenu.parentItem = root.curMenu.items[root.curMenu.items.length-1];
		newMenu.parentMenu = root.curMenu;
		root.curMenu.addChild(newMenu);
		root.curMenu = newMenu;

		root.curItem.setSubMenu(root.curMenu);
		root.curMenu.addItem(newItem);

		root.curItem = newItem;
		root.curLevel++;
	} else if (level < root.curLevel) {//Set the pointers to their correct positions, add item in that positions
		while (root.curLevel > level) {
			root.curMenu = root.curMenu.parentMenu;
			root.curLevel--;
		}
		root.curItem = newItem;
		root.curMenu.addItem(newItem);
	} else alert("Sequence error in menu calls from HTML");
}

function buildMenu(menuID, Xpos, Ypos) {
var generateFunction;
var root = MENUS[menuID];

	root.container = new menuContainer(menuID);
	root.container.move(Xpos, Ypos);
	traverseMenus(root.menuRoot, MENUS[menuID].prefix + "generateMenu(menu)");
	root.container.show();

	root.container.setZ(0);
	root.menuRoot.items[0].move(0,0);
	root.menuRoot.items[0].show();
	for (var i = 1; i < root.menuRoot.items.length; i++) {
		root.menuRoot.items[i].move(0, root.menuRoot.items[i-1].y + root.menuRoot.items[i-1].HTMLObj.offsetHeight);
		root.menuRoot.items[i].show();
	}
	VTROOT.activeItem = MENUS[VT].menuRoot.items[0];
	VTROOT.activeItem.activate();
}
function MenuRootObj(width, leftmargin, identsize) {
	this.prefix = "VT";
	this.itemHeight = 16;
	this.width = width;
	this.leftmargin = leftmargin;
	this.identsize = identsize;
	this.menuRoot = null;
	this.container = null;
	this.curMenu = null;
	this.curItem = null;
	this.curID = 0;
	this.curLevel = 0;	
	return this;
}

function MenuObj(prefix, suffix) {
	this.subClosedImg = eval(prefix + "ClosedImg" + suffix);
	this.subLitClosedImg = eval(prefix + "LitClosedImg" + suffix);
	this.subLitOpenImg = eval(prefix + "LitOpenImg" + suffix);
	this.pointImg = eval(prefix + "PointImg" + suffix);
	this.normalClass = prefix + "NormalMenu" + suffix;
	this.hiliteClass = prefix + "HighlightMenu"+suffix;
	this.activeClass = prefix + "ActiveMenu"+suffix;
	this.isOpen = false;
	this.activeItem = null;
	this.root = null;
	this.div = null;
	this.parentMenu = null;
	this.parentItem = null;
	this.items = new Array();
	this.children = new Array();
	this.addItem = MenuObjAddItem;
	this.addChild = MenuObjAddChild;
	return this;
}
function MenuObjAddItem (newItem) {
	this.items[this.items.length] = newItem;
	newItem.menu = this;
	newItem.indexInMenu = this.items.length-1;
}
function MenuObjAddChild (aMenu) {this.children[this.children.length] = aMenu;}

function ItemObj (ID, level, label, href, width) {
	this.ID = ID;
	this.level = level;
	this.href = href;
	this.width = width;
	this.isLit = false;
	this.div = null;
	this.HTMLObj = null;
	this.menu = null;
	this.indexInMenu = -1;
	this.subMenu = null;
	this.setSubMenu = ItemObjSetMenu;
	this.label = label;
	return this;
}
function ItemObjSetMenu (newMenu) {this.subMenu = newMenu;}

function menuContainer(menuID) {
	var newDiv = document.createElement("div");
	newDiv.className = "menu";
	newDiv.setAttribute("id", "menuContainer"+menuID);
	newDiv.style.width = MENUS[menuID].width+"px";
	this.div = document.body.appendChild(newDiv);
	this.move = moveLyr;
	this.hide = hideLyr;
	this.show = showLyr;
	this.setZ = Z;
	return this;
}
function moveLyr(x,y){this.div.style.left = x+"px"; this.div.style.top = y+"px"; this.x = x; this.y = y;}
function hideLyr(){this.div.style.visibility = "hidden";this.div.style.display = "none";}
function showLyr(){this.div.style.visibility = "visible";this.div.style.display = "block";}
function Z(newZ) {this.div.style.zIndex = newZ;}

var MENUS = new Array();
var VTlookUpTable = new Array();
var VTROOT = null;
var previousItem = null;
var TEXT = 1;

function traverseMenus(menu, action) {
	if (menu) eval(action); else return;
	for (var i = 0; i < menu.children.length; i++)
		traverseMenus(menu.children[i], action);
}
function traverseOpenMenus(menu, action) {
	if (!menu) return;
	if (menu.isOpen || (menu == MENUS[VT].menuRoot)) eval(action);
	for (var i = 0; i < menu.children.length; i++)
		traverseOpenMenus(menu.children[i], action);
}
function reverseOpenMenus(menu, action) {
	if (!menu) return;
	for (var i = 0; i < menu.children.length; i++) {
		if (menu.children[i].isOpen) reverseOpenMenus(menu.children[i], action);
	}
	eval(action);
}
function reverseMenus(menu, action) {
	if (!menu) return;
	for (var i = 0; i < menu.children.length; i++) {
		reverseMenus(menu.children[i], action);
	}
	eval(action);
}
function setMenu(menuID, contentURL) {
var wanted = -1;
	for (var i = 0; i < VTlookUpTable.length; i++) {
		if (VTlookUpTable[i].href == contentURL) {wanted = i;break;}
	}
	if (wanted != -1) {
	var found = VTlookUpTable[wanted];
		if (found.menu.parentItem) VTclickItem(found.menu.parentItem.ID);
		found.activate();//found.light();
		found.pointImg.src = found.menu.pointImg.src;
		VTROOT.activeItem = found;
	}
}

function unloadMenu(menuID) {
	reverseMenus(MENUS[menuID].menuRoot,'deleteMenu(menu)');
	
	MENUS[menuID].container.div = null;
	MENUS[menuID].container.move = null;
	MENUS[menuID].container.hide = null;
	MENUS[menuID].container.show = null;
	MENUS[menuID].container.setZ = null;

	MENUS[menuID].container = null;
	MENUS[menuID].prefix = null;
	MENUS[menuID].itemHeight = null;
	MENUS[menuID].WIDTH = null;
	MENUS[menuID].LEFTMARGIN = null;
	MENUS[menuID].curMenu = null;
	MENUS[menuID].curID = null;
	MENUS[menuID].curLevel = null;
	MENUS[menuID].menuRoot = null;
	MENUS[menuID] = null;
}
function deleteMenu(menu) {
	for (var i = 0; i < menu.items.length; i++)
		deleteItem(menu.items[i]);
	menu.arrowImg = null;
	menu.subClosedImg = null;
	menu.subLitClosedImg = null;
	menu.subLitOpenImg = null;
	menu.pointImg = null;
	menu.normalClass = null;
	menu.hiliteClass = null;
	menu.isOpen = false;
	menu.activeItem = null;
	menu.root = null;
	menu.div = null;
	menu.parentMenu = null;
	menu.parentItem = null;
	menu.items = null;
	menu.children = null;
	menu.addItem = null;
	menu.addChild = null;
	menu = null;
}

function deleteItem(Item) {
	Item.ID = null;
	Item.itemType = null;
	Item.level = null;
	Item.href = null;
	Item.target = null;
	Item.width = null;
	Item.isLit = null;
	Item.div = null;
	Item.HTMLObj = null;
	Item.menu = null;
	Item.indexInMenu = null;
	Item.subMenu = null;
	Item.setSubMenu = null;
	Item.labelNormalImg = null;
	Item.labelHiliteImg = null;
	Item.label = null;
	Item = null;
}


