/* 

	---------------------------------
	Javascript Menu Class System
	---------------------------------
	Author:		Keith Foster
	Version:		1.16
	Update:		Stanford Medical.
	#1 - Add Divider Functionality.
	
*/

// GLOBAL VARIABLES
var timeOn = null;
var menuActive = new Array();
var tier = new Array();
var currentMenuNo=0;
var filterfocus = false;
var timer=null;

//copied from old menu_class
//RootMenu only takes 8 args in new version last two are "out", "on"
function build_topnav()
{			

	//alert('in function build_topnav');	
	topNav = new RootMenu("topNav", top_config[0], top_config[1], top_config[2], top_config[0], top_config[3][0], top_config[3][1], top_config[3][2]);//, top_config[4][0], top_config[4][1]);
			
	//alert('TopNav' + topNav);
	
	build_submenus("topNav", top_items);
	buildSubMenus();
	
	//alert('after build_submenus');
}

function build_submenus(parent, arr)
{
	var menu = eval(parent);
	for(var i=0; i<arr.length; i++)
	{
		//			bookmark
		menu.addItem(arr[i][0], arr[i][1], arr[i][2], arr[i][3], arr[i][4], arr[i][5], arr[i][6], arr[i][7]);
	}
}

// GLOBAL METHODS
function getMenuKey()
{
	var url = window.location.toString();
	var menu_key = "";
	for(key in keys)
	{
		for(var i=0; i<keys[key].length; i++)
		{
			if(url.indexOf(keys[key][i])!=-1)
			{
				menu_key = key;
				break;
			}
		}
	}
	if(menu_key=="") menu_key="root";
	return menu_key;
}
function addChildren(arr)
{
	var i=11, count=0;
	while(typeof(arr[i])!="undefined")
	{
		if(arr[i][0]=="DIVIDER") 
		{
			if(arr[i][1])
				eval(arr[0]+".addDivider('"+arr[i][1]+"');");
			else
				eval(arr[0]+".addDivider();");
		}
		else
		{
			eval(arr[0]+".addItem(arr[i][0], arr[i][1], arr[i][2], arr[i][3], arr[i][4], arr[i][5]);");
		}
		i++;
	}
}
function buildSubMenus()
{
	var key = getMenuKey();
	for(i in keys)
	{
		eval("buildSubMenu(\'"+i+"\');");
	}
	// THIS BUILDS THE TOP NAV SUBMENUS.
	for(var i=1;i<=4; i++)
	{		
		var key;
		var width, intTemp;
		var arrTemp;
		switch(i){case 1: key="cs"; width=145; break; case 2: key="hl"; width=140; break; case 3: key="ne"; width=123; break; case 4: key="dp"; width=175; break;}
		eval("tn_SM"+i+" = new SubMenu('tn_SM"+i+"', 'Generic', "+width+", 'vertical', 1, 0, 1, 'left', 'right', 1, null);");
		arrTemp = menu_items[key];
		intTemp = 5;		
		while(typeof(arrTemp[3][intTemp])!="undefined")
		{
			eval("tn_SM"+i+".addItem(arrTemp[3][intTemp][0], arrTemp[3][intTemp][1], arrTemp[3][intTemp][2], "+width+", 'left', null);");
			intTemp++;
		}
		eval("tn_SM"+i+".build();");
	}
}
function buildSubMenu(key)
{
	var key=(key)?key:getMenuKey();
	var smenus=submenu_items[key];
	if(smenus)
	{
		for(var a=0; a<smenus.length; a++)
		{
			eval(smenus[a][0]+"= new SubMenu('"+smenus[a][0]+"', '"+smenus[a][1]+"', "+smenus[a][2]+", '"+smenus[a][3]+"', "+smenus[a][4]+", "+smenus[a][5]+", "+smenus[a][6]+", 'right', 'right', "+smenus[a][9]+", null);");
			if(typeof(smenus[a][11])!="undefined")
				addChildren(smenus[a]);
			eval(smenus[a][0]+".build();");
		}
	}
}

// not used
function buildRootMenu()
{	
	var text=getFileName(window.location.toString());
	var key = getMenuKey();	
	cool = new RootMenu("cool", "stanford_RM", "vertical", 183, "stanford_RM", 2, 0, 0);
	var arr = menu_items[key];	
	for(var i=0; i<arr.length; i++)
	{
		var class_name=(arr[i][1]==text)?"redBold":arr[i][3];
		cool.addItem(arr[i][0], arr[i][1], 183, "left", arr[i][2], "stanford_RM", class_name, arr[i][4]);
		var j=5;
		while(typeof(arr[i][j])!="undefined")
		{
			class_name=(arr[i][j][1]==text)?"redBold":arr[i][j][3];
			cool.addItem(arr[i][j][0], arr[i][j][1], 183, "left", arr[i][j][2], "stanford_RM", class_name, arr[i][j][4]);
			j++;
		}
	}
}

function redirect(url, obj)
{
	if(url.substring(0, 10).toLowerCase()=="javascript")
	{
		eval(url);
	}
	else
	{
		// Handle external url case
		if(url != undefined && url != null && url.indexOf("external:") != -1)
		{
			//alert("url before: " + url);
			url = url.replace(/external:/i, "");
			//alert("url after: " + url);
			window.open(url, '_blank');
		}
		else
		{
			// handle other url (internal)
			window.location = url;
		}
	}
	
	if(url.match("switchHubs")==null)
		setTimeout("hideAllMenus(\'"+obj+"\')", 300);
}
var offMenu = true;
function menuOver() {
	offMenu = false;
	clearTimeout(timeOn);
}

function menuOut(obj)
{
	offMenu = true;
	if(!filterfocus)
		timeOn = setTimeout("hideAllMenus(\'"+obj+"\')", 300);
}

function showMenu(m_No, obj, callingId) {
	clearInterval(timer);
	var strMenu = (m_No==obj||obj==null)?m_No:obj+m_No;
	var menu = eval(m_No);
	var cmenu = (obj!=null)?eval(obj):menu;
	menu.parentItem = obj;	
		
	var onClass = (getElement(strMenu).className==cmenu.offClass||getElement(strMenu).className==cmenu.onClass)?cmenu.onClass:getElement(strMenu).className+"_over";

	var url = window.location.toString();
	hideAllMenusTier(tier[m_No]-1, obj);
	var borderModSize = menu.border;
	if (ns4) {
		changeBGColour('menuLabel' + m_No, onColours[m_No]);
	} else {
		if(getElement(callingId).className)
		{
			changeClass(callingId, onClass);
		}
	}
	menuActive[m_No] = true;
	
	if (ns4) labelObj = 'menuLabel'+m_No;
	else labelObj = callingId;
	
	x = getElementLeft(labelObj);
	y = getElementTop(labelObj) + getElementHeight(labelObj);
		
	if (menu.align == 'center')  x = x + ((getElementWidth(labelObj)-getElementWidth('menu'+obj))/2);
	if (menu.align == 'right')  x = x + ((getElementWidth(labelObj)-getElementWidth('menu'+obj)))+borderModSize;
		
	if(mac_ie)
		y += 1;
	moveXY('menu'+m_No, x, y);
		
	if(changeClass('menu'+m_No, 'myMenuShown'))
	{		
		if(obj=="BHMenu")
		{		
			preloadLogos();
			getElement("hubFilter").focus();			
		}		
		return true;
	}
	else return false;
}
function isSpace(item)
{
	var space = true;
	if(getElementLeft(item)+getElementWidth(item)+110> getViewportWidth())
		space = false;
	return space;
}
function showMenuSide(m_No, obj, callingId) {
	var menu = eval(m_No);
	var cmenu = eval(obj)
	var space = true;
	
	menu.parentItem = obj;
	if(tier[m_No]!=tier[obj]+1)
		tier[m_No]=tier[obj]+1;
	hideAllMenusTier(tier[m_No]-1, obj);
	var borderModSize = cmenu.border;
	
	var onClass = (getElement(obj+m_No).className==cmenu.offClass)?cmenu.onClass:getElement(obj+m_No).className+"_over";
	
	if (ns4) 
	{
		changeBGColour('menuLabel' + m_No, onColours[m_No]);
	}
	else
	{
		if(getElement('tdImage' + m_No))
			changeClass('tdImage' + m_No, onClass);
		changeClass('subIDLink' + m_No, onClass);
		changeClass('subID'+callingId, onClass);
		if(getElement('arrow'+callingId))
		{	
			//alert("Calling ID: " + callingId);
			var image = getElement('arrow'+callingId).src.toString();
			//alert("Before: " + image + "And GetElement = " + getElement('arrow'+callingId).src);
			image = getApplicationPath() + "templates/stanford/" + getFileName(image.substring(0,image.indexOf("_off")) + "_on.gif");
			//alert("After: " + image);			
			changeImage('arrow'+callingId, image);
		}
		changeClass(callingId, onClass);
	}
	
	menuActive[m_No] = true;
	
	if (ns4) 
		labelObj = 'menuLabel'+m_No;
	else 
		labelObj = callingId;
	
	x = getElementLeft(labelObj);
	y = getElementTop(labelObj) - borderModSize-(cmenu.cellpadding);
	space = isSpace(labelObj);
	
	if (menu.calign=='right' && space) 
		x = x + getElementWidth(labelObj)+getElementWidth("subID"+callingId)+borderModSize;
	else
	{
		if(getElement("tdImage"+m_No))
			x = x - getElementWidth('menu'+m_No)-getElementWidth('tdImage'+m_No);
		else
			x = x - getElementWidth('menu'+m_No)+borderModSize;
	}
	//safari isnt aligning the sidemenus correctly:
	
	if(safari) y--;	
	moveXY('menu'+m_No, x, y);	
	changeClass('menu'+m_No, 'myMenuShown');
}

function hideAllMenus(obj) {
	var url = window.location.toString();
	for (var i in menuActive)
	{
		if(menuActive[i])
		{
			hideMenu(obj, i);
		}
	}
	if(getElement('imgBH'))
		changeImage('imgBH', 'imgBH');
	if(getElement('imgCOMenu') && url.search("search_root") != -1)
		changeImage('imgCOMenu', 'imgSCOMenu');
	else if(getElement('imgCOMenu'))
		changeImage('imgCOMenu', 'imgCOMenu');
		
	if(getElement('imgSearch'))
		if(!safari)
		{
			if(getFileName(getElement('imgSearch').src)=="search_on.gif")
				changeImage('imgSearch', 'imgSearch');
		}
		else
		{
			if(getFileName(getElement('imgSearch').src)=="safari_search_on.gif")
				changeImage('imgSearch', 'imgSearch');
		}
	if(getElement('itemCellContext'))
		if(getElement("itemCellContext").tagName == 'IMG')
			if(!safari)
			{
			
				if(getFileName(getElement('itemCellContext').src)=="search_on.gif")
					changeImage('itemCellContext', 'imgSearch');
			}
			else
			{
				if(getFileName(getElement('itemCellContext').src)=="safari_search_on.gif")
					changeImage('itemCellContext', 'imgSearch');
			}
}

function hideAllMenusTier(myTier, obj) 
{
	for (var i in tier) {
		if( tier[i] > myTier && menuActive[i] == true)
		{
			if(i!="BHMenu") hideMenu(obj, i);
		}
	}
}


function hideMenu(obj, m_No) {
	var menu = eval(m_No);	
	var pItem = "";
	pItem = (menu.parentItem)?menu.parentItem+m_No:m_No;
	
	if (ns4) {
		changeBGColour('menuLabel' + pItem, offColours[m_No]);
	} else {
		if(getElement(pItem))
			var offClass = (getElement(pItem).className)?getElement(pItem).className.toString().replace("_over", ""):null;
		else
			alert("ERROR: HTML Item Doesnt Exist!");
		
		if(getElement('tdImage' + pItem))
			changeClass('tdImage' + pItem, offClass);
		changeClass(pItem, offClass);
		
		//if(getElement('subIDLink' + pItem))
		//	changeClass('subIDLink' + pItem, offClass);
		if(getElement('subID'+pItem))
		{
			changeClass('subID'+pItem, offClass);
		}
		if(getElement('arrow'+pItem))
		{
			var image = getElement('arrow'+pItem).src.toString();
			//alert('getElement(arrow+pItem): ' + getElement("'arrow\'"+pItem) );
			//alert('pItem: ' + pItem);
			//alert('image0: ' + image);
			//image = "images/global/interface/"+getFileName(image.substring(0,image.indexOf("_on"))+"_off.gif");
			
			image = getApplicationPath() + "templates/stanford/" + getFileName(image.substring(0,image.indexOf("_on"))+"_off.gif");

			//alert('getImage:  ' + getFileName(image.substring(0,image.indexOf("_on"))+"_off.gif") );
			//alert('image:  ' + image);			
			changeImage('arrow'+pItem, image);
		}
	}
	menuActive[m_No] = false;
	
	if(changeClass('menu'+m_No, 'myMenuHidden'))
		return true;
    else return false;
}

function delayedDisplay(child,parent, id)
{
	timer = setInterval("showMenu('"+child+"', '"+parent+"', '"+id+"')", 250);
}

function Menu(id, width, className, cellpadding, cellspacing, border)
{
	this.init(id, width, className, cellpadding, cellspacing, border);
}

Menu.prototype.init = function(id, width, className, cellpadding, cellspacing, border)
{
	this.strHTML = "";
	this.children = new Array();
	this.objectName = id;
	this.width = width;
	this.align = new Array();
	this.className = className;
	this.cellpadding = cellpadding;
	this.cellspacing = cellspacing;
	this.border = border;
}
Menu.prototype.addItem = function(str, child)
{
	this.menuItems[this.menuItems.length] = [str, child];
}

// SUBMENU CLASS
SubMenu.prototype = new Menu;

function SubMenu(id, type, width, orientation, cellpadding, cellspacing, border, align, calign, mytier, maxitems, vi, admin, switchNo, path)
{
	this.base = Menu;
	this.base(id, width, type, cellpadding, cellspacing, border);
	currentMenuNo += 1;
	this.maxitems = maxitems;
	this.numItems = 0;
	this.startingVI =  vi||0;
	this.visibleIndex = vi||0;
	this.height = 15;
	this.itemText = new Array();
	this.rowText = new Array();
	this.children = new Array();
	this.internal = new Array();
	this.external = new Array();
	this.alpha = new Array();
	this.align = align||"right";
	this.calign = calign||"right";
	this.offClass = type;
	this.onClass = type+'_over';
	this.orientation = orientation;
	this.menuType = type;
	this.menuWidth = width;
	this.targetType = 'self'; // self, iframe, frame, new
	this.targetFrame = '_self'; // _self, _blank or (i)frame name
	if(!tier[id]) tier[id]=mytier;
	if(!menuActive[id]) menuActive[id]=false;
	this.admin = admin; // show or not show admin mode link.
	this.switchNo = switchNo;
	this.path = path;
	this.parentItem = null;
}

	SubMenu.prototype.buildRow = function(itemText, itemURL, menuNo, itemWidth, align, img, tempId){
	
	var temp="";
	var newURL = itemURL;
	
	if(newURL != "#")
	{
		newURL = ' onclick="redirect(\'' + newURL + '\', \'' + this.objectName + '\');"'
	}
	else
	{
		newURL = ' ';
	}
		
	switch(this.menuType)
	{
		case "quickLinks":
			//var class_name = (this.numItems%2==1)?"quickLinks1":"quickLinks2";
			var class_name="quickLinks2";
			if (menuNo != null) 
			{
				if (this.orientation =='vertical') 
				{
					this.rowText[this.numItems] += '<tr id="labelRow'+ menuNo + '">';
				}
				
				temp += '<td ' + newURL + ' class="'+class_name+'" style="padding-left:5px;" id="itemCell'+ menuNo + '" width="'+ itemWidth + '" valign="middle" height="' + this.height + '" ';
				
				//alert("L535 - " + temp);
			} 
			else 
			{
				if (this.orientation =='vertical') 
				{
					this.rowText[this.numItems] += '<tr>';
				}
				
				temp += '<td ' + newURL + ' class="'+class_name+'" style="padding-left:5px;" colspan="2" id="itemCell' + tempId + '" width="'+ itemWidth + '" valign="middle" height="' + this.height + '"';
				
				//alert("L546 - " + temp);
			}

			if (!ns4) {
				if (menuNo != null) {			
					if (this.orientation =='vertical') 
						temp += ' onmouseover="return !showMenuSide(\'' + menuNo + '\', \''+this.objectName+'\');"';
					else 
						temp += ' onmouseover="return !showMenu(\'' + menuNo + '\', \''+this.objectName+'\'); "';
				} else {
						temp += ' onmouseover="changeClass(\'itemCell'+tempId+'\', \''+this.onClass+'\'); hideAllMenusTier(tier[\'' + this.objectName+ '\'], \''+this.objectName+'\');" onmouseout="changeClass(\'itemCell'+tempId+'\', \''+class_name+'\');"';
				}
			} 
			temp += '>';
			temp +='<div ';
			break;
		default:
			if (menuNo != null) 
			{
				if (this.orientation =='vertical') 
				{
					this.rowText[this.numItems] += '<tr id="labelRow'+ menuNo + '" width="'+itemWidth+'">';
				}
				
				temp += '<td ' + newURL + ' class="'+this.menuType+'" style="padding-left:5px;" id="'+this.objectName+menuNo + '" valign="middle" height="' + this.height + '" ';
				
				//alert("L572 - " + temp);
			} 
			else 
			{
				if (this.orientation =='vertical') 
				{	
					this.rowText[this.numItems] += '<tr>';
				}
				
				temp += '<td ' + newURL + ' class="'+this.menuType+'" style="padding-left:5px;" colspan="2" id="itemCell' + tempId + '" width="'+ itemWidth + '" valign="middle" height="' + this.height + '"';
				
				//alert("L583 - " + temp);				
			}

			if (!ns4) {
				if (menuNo != null) {			
					if (this.orientation =='vertical') 
						temp += ' onmouseover="return !showMenuSide(\'' + menuNo + '\', \''+this.objectName+'\', this.id);"';
					else 
						temp += ' onmouseover="return !showMenu(\'' + menuNo + '\', \''+this.objectName+'\', this.id); "';
				} else {
						temp += ' onmouseover="changeClass(\'itemCell'+tempId+'\', \''+this.onClass+'\'); hideAllMenusTier(tier[\'' + this.objectName+ '\'], \''+this.objectName+'\');" onmouseout="changeClass(\'itemCell'+tempId+'\', \''+this.offClass+'\');"';
				}
			} 
			temp += '>';

			temp +='<div ';
			break;
	}
	return temp;
}

SubMenu.prototype.addItem = function(text, url, child, width, align, image, internal)
{
	this.numItems += 1;
	var tempId = this.objectName + '_' + this.numItems;
	if(child!=null)
		this.children[this.children.length]=child;
	if (child != null) {
		tier[child] = tier[this.objectName] + 1;
	}
	if(internal==1)
		this.internal[this.internal.length] = this.numItems;
	else if(internal==2)
		this.external[this.external.length] = this.numItems;
	
	temp = new String('');
	this.rowText[this.numItems] = new String('');
	
	temp += this.buildRow(text, url, child, width, align, image, tempId);
	
	switch(align)
	{
		case "right":
			temp += ' class="myMenuItemleft" width="' + width + '"';
			break;
		case "center":
			temp += ' class="myMenuItemcenter" width="' + width + '"';
			break;
		default:
			temp += ' class="myMenuItemLeft" width="' + width + '"';
			break;
	}
	
	if (child != null) temp += ' id="menuLabel' + child +'"';
	else temp += ' id="menuItem' + tempId +'"';

	temp += '>'+text;
	
	if (ns4) temp += '</layer></ilayer>';
	else temp += '</div>';

	temp += '</td>';
	
	if(child!=null)
	{
		temp+='<td align="right" id="subID'+this.objectName+child+'" onmouseover="return !showMenuSide(\'' + child + '\', \''+this.objectName+'\', this.previousSibling.id); ">';
		if(this.align=="left")
		{
			//temp+='<img id="arrow'+this.objectName+child+'" src="images/global/interface/arrow_right_off.gif" border="0" height="11px" /></td>';
			temp+='<img id="arrow'+this.objectName+child+'" src="' + getApplicationPath() + 'templates/stanford/arrow_right_off.gif" border="0" height="11px" /></td>';		
			//alert(temp);
		}
		else
			temp+='<img id="arrow'+this.objectName+child+'" src="' + getApplicationPath() + 'templates/stanford/arrow_right_off.gif" border="0" height="11px" /></td>';
	}		
	this.itemText[this.numItems] = new String(temp);
}

SubMenu.prototype.addDivider = function(text)
{
	var divider_text = (text)?text:"------------------------------"
	var class_name = (text)?"grey":"divider";
	this.numItems += 1;
	temp = new String('');
	this.rowText[this.numItems] = new String('');
	var colspan = 2;
	temp+= '<tr><td class="'+class_name+'" colspan="'+colspan+'">'+divider_text+'</td>';
	this.itemText[this.numItems] = new String(temp);
}

SubMenu.prototype.build = function()
{
	var menuStr = new String();
	menuStr += '<div id="menu'+this.objectName+ '" name="menu' + currentMenuNo + '" onmouseover="menuOver();" onmouseout="menuOut(\''+this.objectName+'\');" class="myMenuHidden" width="' + this.menuWidth + '"';
	if (!ns4) menuStr += ' style="width:' + this.menuWidth + 'px;"';
	menuStr+= '><table cellpadding="'+this.cellpadding+'" cellspacing="'+this.cellspacing+'" bgColor="#FFFFFF" width="' + this.menuWidth + '" class="'+this.menuType+'">';
	menuStr += '<tr><td width="'+this.menuWidth+'" class="'+this.menuType+'">';
	menuStr += '<table width="100%" cellpadding="3" cellspacing="0" border="0" id="hubs">';
	if (this.orientation == 'vertical') {	
		for (var count = 0; count < this.numItems; count++) 
		{
			menuStr += this.rowText[count+1];
			menuStr += this.itemText[count+1];
			menuStr += '</tr>';
		}
	} else {
		menuStr += '<tr>';
		for (var count = 0; count < this.numItems; count++) {
			menuStr += this.rowText[count+1];			
			menuStr += this.itemText[count+1];
		}
		menuStr +=  '</tr>';
	}
	menuStr += '</table></td></tr></table></div>';
	document.write(menuStr);
}

// ROOTMENU CLASS
function RootMenu(objName, id, orientation, width, className, cellpadding, cellspacing, border)
{
	this.base = Menu;
	this.base(objName, width, className, cellpadding, cellspacing, border);
	this.numLabels = 0;
	this.barName = id;
	this.i_Bor = 0;	
	this.o_Bor = 0;	
	this.height = 15;
	this.labelText = new Array();
	this.rowText = new Array();
	this.offClass = this.barName;
	this.onClass = this.barName+"_over";
	this.bulletAlign = 'left';
	this.targetType = 'self'; // self, iframe, frame, new
	this.targetFrame = '_self'; // _self, _blank or (i)frame name
	this.orientation=orientation;	
	if(!tier[objName]) tier[objName]=1;
	if(!menuActive[objName]) menuActive[objName]=false;
}
RootMenu.prototype = new Menu;

RootMenu.prototype.buildRow=function(type, title, url, child, width, tempId, classname)
{
	var temp = new String('');
	var class_name = (classname&&classname!=null)?classname:this.barName;
	
	if(url != "#")
	{
		url = ' onclick="redirect(\'' + url + '\', \'none\')"';
	}
	else
	{
		url = ' ';
	}
		
	switch(type)
	{
		case "stanford_RM":
			if(class_name=="stanford_RM_SHIE")
				temp += '<tr><td>&nbsp;</td></tr>';
			if (this.orientation == 'vertical') this.rowText[this.numLabels] += '<tr id="labelRow'+ child + '">';
			if(child)
			{
				temp += '<td align="left" style="padding-left:6px;" class="'+class_name+'" id="'+this.objectName+ child + '" valign="middle" width="'+ width+ 'px" height="' + this.height + '" ';
			}
			else
				temp += '<td align="left" style="padding-left:6px;" colspan="2" class="'+class_name+'" id="' + tempId + '" width="'+ width+ 'px" valign="middle" height="' + this.height + '" ';			
			if (!ns4) {
				if(child)
				{
					temp += url + ' onmouseout=" menuOut(\''+this.objectName+'\');" onmouseover="menuOver(); ';
					if (this.orientation == 'vertical') temp += 'showMenuSide(\'' + child + '\', \''+this.objectName+'\', this.id);" ';
					else temp += 'showMenu(\'' + child + '\', \''+this.objectName+'\', this.id);" ';
					
					//alert("L704 - " + temp);
				}
				else
				{
					if(class_name==this.offClass)
					{
						temp+= url + ' onMouseOver="changeClass(this.id, \''+this.onClass+'\');hideAllMenusTier(tier[\'' + this.objectName+ '\']-1, \''+this.objectName+'\');" onMouseOut="changeClass(this.id, \''+this.offClass+'\');"';
					}
					else
					{
						temp+= url + ' onMouseOver="hideAllMenusTier(tier[\'' + this.objectName+ '\']-1, \''+this.objectName+'\');"';
					}
					
					//alert("L717 - " + temp);
				}
			} 		
			temp +='>';
			break;
		default:
			if (this.orientation == 'vertical') this.rowText[this.numLabels] += '<tr id="labelRow'+ child + '">';	
			if(child)
			{
				temp += '<td class="'+this.barName+'" id="' +this.objectName+child + '" width="'+ width + '" valign="middle" height="' + 22 + 'px" ';
			}
			else
				temp += '<td colspan="2" class="'+this.barName+'" id="' + tempId + '" width="'+ width+ '" valign="middle" height="' + 22 + 'px" ';
			
			if (!ns4) {
				if(child)
				{
					temp += url + ' onmouseout=" menuOut(\''+this.objectName+'\'); clearInterval(timer);" onmouseover="menuOver(); ';
					
					//alert("L736 - " + temp);
					
					if (this.orientation == 'vertical') 
					{
						temp += 'return !showMenuSide(\'' + child + '\', \''+child+'\');" ';
					}
					else 
					{
						temp += ' delayedDisplay(\'' + child + '\', \''+this.objectName+'\',\''+this.objectName+child+'\');" ';
					}
				}
				else
				{
					temp += url + ' onmouseover="hideAllMenusTier(tier[\'' + this.objectName+ '\']-1, \''+this.objectName+'\'); changeClass(this.id, \''+this.onClass+'\');" onmouseout="changeClass(this.id, \''+this.offClass+'\');"';
					//alert("L750 - " + temp);
				}
			} 		
			temp +='>';
			
			if (ns4) {
				temp +='<ilayer><layer onmouseout="menuOut();" onmouseover="menuOver(); ';
				if (this.orientation == 'vertical') temp +='return !showMenuSide(\'' + child + '\', \''+this.objectName+'\');" ';
				else temp +='return !showMenu(\'' + child + '\', \''+this.objectName+'\');" ';
			} else {
				temp +='<div ';
			}
			break;
	}	
	return temp;
}

RootMenu.prototype.addItem = function(text, url, width, align, child, type, classname, desc)
{
	// HERE IS WHERE WE BUILD UP THE TD CELLS;
	var class_name = (classname&&classname!=null)?classname:this.barName;
	this.numLabels += 1;
	var tempId =  this.objectName+"_"+this.numLabels;
	tier[child] = 1;

	var temp = new String('');
	this.rowText[this.numLabels] = new String('');
	temp+=this.buildRow(type, text, url, child, width, tempId, class_name, desc);
	if(type!="stanford_RM")
	{
		if(child)
			temp += ' class="myMenuLabel' + align + '" width="' + width + '"  id="menuLabel' + child +'">';
		else
			temp += ' class="myMenuLabel' + align + '" width="' + width + '"  id="menuLabel' + tempId +'">';
		
		temp+=text;

		if (ns4) temp += '</layer></ilayer>';
		else temp += '</div>';
		
		//alert(temp);
	}
	else
	{		
		if(type=="stanford_RM" && (desc != null&&desc))
			temp+=text+'</td></tr><tr><td class="stanford_RM_desc" colspan="2">'+desc;
		else
		{
			temp+=text;
		}
	}
	
	temp += '</td>';
	var class_name = (classname)?class_name:"darkgrey";
	
	
	if(url != "#")
	{
		url = ' onclick="redirect(\'' + url + '\', \'none\')"';
	}
	else
	{
		url = ' ';
	}
	
	if(child && this.orientation!="horizontal")
		temp+= '<td class="' + class_name + '" width="16px" id="subID' + this.objectName+child + '"' + url + '" onMouseOver="showMenuSide(\'' + child + '\', \'' + this.objectName + '\', this.previousSibling.id);"><img id="arrow' + this.objectName+child + '" src="' + getApplicationPath()+ 'templates/stanford/arrow_right_off.gif" border="0" height="11px" /></td>';//src="images/global/interface/arrow_right_off.gif"

	//alert("L807 - " + temp);
	
	this.labelText[this.numLabels] = new String(temp);	
}

RootMenu.prototype.build = function()
{
	o_Bor = this.o_Bor;
	i_Bor = this.i_Bor;
	menuBarStr = new String();
	menuBarStr += '<div id="' + this.barName + '" width="'+this.width+'" align="center"><table width="'+this.width+'" border="'+this.border+'" cellpadding="'+this.cellpadding+'" cellspacing="'+this.cellspacing+'" class="'+this.barName+'">';
	if (this.orientation == 'vertical') {
		for (var count = 0; count < this.numLabels; count++) {		
			menuBarStr += this.rowText[count+1];
			menuBarStr += this.labelText[count+1];		
			menuBarStr += '</tr>';
		}
	} else {
		menuBarStr += '<tr>';
		for (var count = 0; count < this.numLabels; count++) {		
			menuBarStr += this.rowText[count+1];			
			menuBarStr += this.labelText[count+1];
		}
		menuBarStr +=  '</tr>';
	}
	menuBarStr += '</table></div>';
	document.write(menuBarStr);
}