/*************** Begin setting variables with constant values.  ***************/
/*
 Add 2 spaces before every line in the page source. (This doesn't change any
   functionality of the menus, only just how it looks in the document's source
   code when viewed in the browser.)
*/
var psDepth = 2;
/*
 The length of time in milliseconds (1/100 of a second) before a menu disappear
   from view. 100 milliseconds is the same as 1 second. 200 = 2 seconds, 1000 =
   10 seconds, etc.
*/
var timeLength = 100;
/*********************** Begin setting other variables. ***********************/
/*
 A temporary variable.
*/
var timeOn = null;

var numMenus = 50;

var currentMenuNo = 0;
var menuActive = new Array(numMenus);
var tier = new Array(numMenus);
var borderMod = new Array(numMenus);
var offClass = new Array(numMenus);
var onClass = new Array(numMenus);
var offColours = new Array(numMenus);
var onColours = new Array(numMenus);
var labelBulletName = new Array(numMenus);
var menuType = new Array(numMenus);
var menus = new Array(numMenus);
/*********************** Begin creating some functions. ***********************/
/*
 SourceDepth()
   Converts a numeric whole value into white-space. The only purpose for this
     function is to clean up the aftermath of the working menu in the page
     source.
*/
function SourceDepth(sDepth){
 depthSpace = '';
 if(sDepth != 0 && sDepth > 0){
  for(i = 0;i < sDepth;i++){
   depthSpace += ' ';
  }
 }
 return depthSpace;
}
/*
 openMe()
   A function used for opening a link in a new window. This function may later
     be removed but still has a little life left in it.
*/
function openMe(newin){
 flyout=window.open(newin,"flyout","");
}
/*
 menuOver()
   Stops the timeOut sequence when a menu is currently being hovered.
*/
function menuOver(){
 clearTimeout(timeOn);
}
/*
 menuOut()
   Begins the timeOut sequence. The amount of time before the function in the
     sequence is called is based the value of timeLength and is represented in
     milliseconds.
*/
function menuOut(){
 timeOn = setTimeout("hideAllMenus()", timeLength);
}
/*
 showMenu()
   This function should be self-explanitory, but if there is any question about
     what it does, then it shows a menu when given a number. That number is
     decided upon in the menu.js file and represents a menu to which it was
     assigned.
*/
function showMenu(m_No, eventObj){
 hideAllMenusTier(tier[m_No]-1);
 var borderModSize = borderMod[m_No];
 menuActive[m_No] = true;
 if(menuType[m_No] != 'blank'){
  if(ns4) labelObj = 'menuLabel'+m_No;
  else labelObj = 'labelCell'+m_No;
  x = getElementLeft(labelObj)-borderModSize;
  y = getElementTop(labelObj) + getElementHeight(labelObj);
  if(menus[m_No].align == 'center')
      x = x + ((getElementWidth(labelObj)-getElementWidth('menu'+m_No))/2);
  if(menus[m_No].align == 'right')
      x = x + ((getElementWidth(labelObj)-getElementWidth('menu'+m_No)))
        + (borderModSize*2);
  moveXY('menu' + m_No, x, y);
  if(changeObjectVisibility('menu' + m_No, 'visible')) return true;
  else return false;
 }
}
/*
 showMenuSide() - updating -
   This is an obsolete function and was primarily used in order to display an
     image that represents a border on the side of the menu. This function will
     eventually be removed.
*/
function showMenuSide(m_No, eventObj, myTier) {
	hideAllMenusTier(tier[m_No]-1);
	var borderModSize = borderMod[m_No];
	menuActive[m_No] = true;
	if (menuType[m_No] != 'blank') {
		if (ns4) {
			labelObj = 'menuLabel'+m_No;
		} else {
			labelObj = 'labelCell'+m_No;
			if (mac_ie) labelObj = 'labelRow'+m_No;
		}
		x = getElementLeft(labelObj);
		y = getElementTop(labelObj) - borderModSize;

		if (menus[m_No].align=='right') x = x + getElementWidth(labelObj);
		else x = x - getElementWidth('menu'+m_No);

		moveXY('menu' + m_No, x, y);
	
		if(changeObjectVisibility('menu' + m_No, 'visible')) return true;
	    else return false;
	}
}
/*
 hideAllMenus()
   Self-explanitory function. Hides all visible menus from view.
*/
function hideAllMenus() {
	for (var i = 1; i < (currentMenuNo+1); i++) {
		if(menuActive[i] == true) hideMenu(i);
	}
}
/*
 hideAllMenuTier()
   This function is the same as hideAllMenus() but refers to all sub-menus that
     are currently visible.
*/
function hideAllMenusTier(myTier) {
	for (var i = 1; i < (currentMenuNo+1); i++) {
		if( tier[i] > myTier && menuActive[i] == true) hideMenu(i);
	}
}
/*
 hideMenu()
   This function hides a specified menu.
*/
function hideMenu(m_No) {
	menuActive[m_No] = false;
	
	if(changeObjectVisibility('menu' + m_No, 'hidden'))  return true;
    else return false;

}
/************************ Begin creating some objects. ************************/
/*
 menuBar()
   This object represents the main navigational menu.
*/
function menuBar(barName, orientation) {
  /***** Add properties to this object. *****/
	this.numLabels = 0;
	this.height = 16;
	this.orientation = orientation;
	this.labelText = new Array();
	this.rowText = new Array();
	this.offClass = 'MenuLabelLink';
	this.onClass = 'MenuLabelLinkOn';
//	this.bulletAlign = 'left';
	this.targetType = 'self'; // self, iframe, frame, new
	this.targetFrame = '_self'; // _self, _blank or (i)frame name
	
  /***** Add methods to this object. *****/
  /*
   addLabel()
     This method adds a new label to this object.
  */	
	this.addLabel = function(labelText, menuNo, labelURL, align) {
		this.numLabels += 1;
		tier[menuNo] = 0;		
		if (this.o_Bor != null) borderMod[menuNo] = 1;	
		else borderMod[menuNo] = 0;	
		if (menuNo != null) {
			onClass[menuNo] = this.onClass;
			offClass[menuNo] = this.offClass;
		}
		
		temp = new String('');
		this.rowText[this.numLabels] = new String('');
		if (this.orientation == 'vertical') this.rowText[this.numLabels]
        += '  <tr id="labelRow'+ menuNo + '">' + "\n";

		temp += '     <td id="labelCell' + menuNo
          + '" class="labelCell" valign="middle" ';

		if (!ns4) {
			temp += ' onmouseout="menuOut(); "onmouseover="menuOver(); ';
			if (this.orientation == 'vertical') temp
          += 'return !showMenuSide(' + menuNo + ', event, tier[' + menuNo
           + ']);" ';
			else temp += 'return !showMenu(' + menuNo + ', event);" ';
			if (this.targetType=='self') temp
          += ' onclick="document.location.href=\'' + labelURL + '\';" ';
			if (this.targetType=='new') temp
          += ' onclick="openMe(\'' + labelURL + '\'); return false;" ';
			if (this.targetType=='frame') temp
          += ' onclick="parent.' + this.targetFrame
           + '.document.location.href=\'' + labelURL + '\';" ';
			if (this.targetType=='iframe') temp
          += ' onclick="' + this.targetFrame + '.location.href=\'' + labelURL
           + '\';" ';
		} 		
		temp += '>' + "\n";
		
		if (ns4) {
			temp += '<ilayer>' + "\n"
            + '<layer onmouseout="menuOut();" onmouseover="menuOver(); ';
			if (this.orientation == 'vertical') temp
          += 'return !showMenuSide(' + menuNo + ', event, tier[' + menuNo
           + ']);" ';
			else temp +='return !showMenu(' + menuNo + ', event);" ';
		} else {
			temp += '      <div ';
		}
		
		temp += ' class="myMenuLabel' + align + '" id="menuLabel' + menuNo +'">'
          + "\n" + '       <a href="' + labelURL +'" target="'
          + this.targetFrame + '" class="' + this.offClass + '" id="menuLink'
          + menuNo +'">';

		temp += labelText;


    temp + '</a>' + "\n";
		
		if (ns4) temp += '</layer>' + "\n" + '</ilayer>' + "\n";
		else temp += '      </div>' + "\n";
		
		temp += '     </td>' + "\n";		
		this.labelText[this.numLabels] = new String(temp);

	}
	/*
	 writeMenuBar()
	   A method which is used in order to draw the full list of labels in the
	     main navigation menu.
  */
	this.writeMenuBar = function() {
		o_Bor = this.o_Bor;
		i_Bor = this.i_Bor;
		menuBarStr = new String();
		menuBarStr += "\n" + SourceDepth(psDepth) + '<div id="' + barName + '">'
                + "\n" + SourceDepth(psDepth)
                + ' <table border="0" cellpadding="0" cellspacing="0">' + "\n";
		if (this.orientation == 'vertical') {
			if (o_Bor != null) menuBarStr = menuBarStr;
			for (var count = 0; count < this.numLabels; count++) {		
				menuBarStr += this.rowText[count+1];
				if (o_Bor != null) menuBarStr = menuBarStr;
				menuBarStr += this.labelText[count+1];
				if (o_Bor != null) menuBarStr = menuBarStr;				
				menuBarStr += SourceDepth(psDepth) + '  </tr>' + "\n";
				if (i_Bor != null && count < (this.numLabels-1)) {
					if (o_Bor != null) menuBarStr = menuBarStr;
					else menuBarStr = menuBarStr;
				}
			}
			if (o_Bor != null) menuBarStr = menuBarStr;
		} else {
			if (o_Bor != null) {
				if (i_Bor != null) menuBarStr = menuBarStr;
				else menuBarStr = menuBarStr;
			}
			menuBarStr += SourceDepth(psDepth) + '  <tr>' + "\n";
			if (o_Bor != null) menuBarStr = menuBarStr; 
			for (var count = 0; count < this.numLabels; count++) {		
				menuBarStr += this.rowText[count+1];			
				menuBarStr += this.labelText[count+1];
				if (i_Bor != null && count < (this.numLabels-1)) {
					menuBarStr = menuBarStr;
				}
			}
			if (o_Bor != null) {
				menuBarStr = menuBarStr;
				if (i_Bor != null) menuBarStr = menuBarStr;
				else menuBarStr = menuBarStr; 
			}
			menuBarStr +=  SourceDepth(psDepth) + '  </tr>' + "\n";
		}
		menuBarStr += SourceDepth(psDepth) + ' </table>' + "\n"
                + SourceDepth(psDepth) + '</div>' + "\n";
		document.write(menuBarStr);
	}
}
/*
 menu()
   This object represents any drop-down menus.
*/
function menu(orientation) {
  /***** Add some properties to this object. *****/
	currentMenuNo += 1;
	this.numItems = 0;
	this.height = 16;
	this.itemText = new Array();
	this.rowText = new Array();
	this.align = 'left';
	this.offClass = 'MenuItemLink';
	this.onClass = 'MenuItemLinkOn';
	this.orientation = orientation;
	this.targetType = 'self'; // self, iframe, frame, new
	this.targetFrame = '_self'; // _self, _blank or (i)frame name

  /***** Add some methods to this object. *****/
  /*
   addItem()
     This method adds an item to the current menu.
  */
	this.addItem = function(itemText, menuNo, itemURL, align) {
		this.numItems += 1;
		
		var tempId = currentMenuNo + '_' + this.numItems;
	
		if (menuNo != null) {
			tier[menuNo] = tier[currentMenuNo] + 1;
			onClass[menuNo] = this.onClass;
			offClass[menuNo] = this.offClass;
			if (this.o_Bor != null) borderMod[menuNo] = 1;	
			else borderMod[menuNo] = 0;	
		}
		
		temp = new String('');
		this.rowText[this.numItems] = new String('');
		
		if (menuNo != null) {
			if (this.orientation =='vertical') this.rowText[this.numItems]
          += SourceDepth(psDepth) + '  <tr id="labelRow'+ menuNo + '">' + "\n";
			temp += SourceDepth(psDepth) + '   <td id="labelCell'+ menuNo
            + '" valign="middle" ';
		} else {
			if (this.orientation =='vertical') this.rowText[this.numItems]
          += SourceDepth(psDepth) + '  <tr>' + "\n";
			temp += SourceDepth(psDepth) + '   <td id="itemCell' + tempId
            + '" valign="middle" class="' + align + 'Menu"';
		}		
		if (!ns4) {
			if (this.targetType=='self') temp
          += ' onclick="document.location.href=\'' + itemURL + '\';" ';
			if (this.targetType=='new') temp
          += ' onclick="openMe(\'' + itemURL + '\'); return false;" ';
			if (this.targetType=='frame') temp
          += ' onclick="parent.' + this.targetFrame
           + '.document.location.href=\'' + itemURL + '\';" ';
			if (this.targetType=='iframe') temp
          += ' onclick="' + this.targetFrame + '.location.href=\'' + itemURL
           + '\';" ';
			if (menuNo != null) {			
				if (this.orientation =='vertical') temp
            += ' onmouseover="menuOver(); return !showMenuSide(' + menuNo
             + ', event, tier[' + menuNo + ']); " onmouseout=" menuOut();"';
				else temp += ' onmouseover="menuOver(); return !showMenu(' + menuNo
                  + ', event); " onmouseout=" menuOut();"';
			} else {
				temp += ' onmouseover="changeClass(\'menuLink' + tempId + '\',\''
              + this.onClass + '\'); hideAllMenusTier(tier[' + currentMenuNo
              + ']); menuOver();" onmouseout="menuOut(); changeClass(\'menuLink'
              + tempId + '\',\'' + this.offClass + '\');"';
			}
		} 
		temp += '>' + "\n";
				
		if (ns4) {
			temp += '<ilayer>' + "\n" + '<layer ';
			if(menuNo != null) { 
				if (this.orientation == 'vertical') temp
            += 'onmouseover="menuOver(); return !showMenuSide(' + menuNo
             + ', event, tier[' + menuNo + ']);" onmouseout="menuOut();"';
				else temp += 'onmouseover="menuOver(); return !showMenu(' + menuNo
                   + ', event);" onmouseout="menuOut();"';
			} else {
				temp += 'onmouseover="hideAllMenusTier(tier[' + currentMenuNo
              + ']); menuOver();" onmouseout="menuOut();"';
			}
		} else {
			temp += SourceDepth(psDepth) + '    <div ';
		}
		temp += ' class="myMenuItem' + align + '"';
	
		if (menuNo != null) temp += ' id="menuLabel' + menuNo +'"';
		else temp += ' id="menuItem' + tempId +'"';
		
		temp += '>' + "\n" + SourceDepth(psDepth) + '     <a href="' + itemURL
          + '" target="' + this.targetFrame + '" class="' + this.offClass + '"';
		if (menuNo != null) temp += 'id="menuLink' + menuNo +'"';
		else temp += 'id="menuLink' + tempId +'"';
		temp +='>';
		
		temp += itemText + '</a>' + "\n";
		
		if (ns4) temp += '</layer>' + "\n" + '</ilayer>' + "\n";
		else temp += SourceDepth(psDepth) + '    </div>' + "\n";

		temp += SourceDepth(psDepth) + '   </td>' + "\n";	
		this.itemText[this.numItems] = new String(temp);
	}
	/*
	 writeMenu()
	   Draws the completed menu.
  */
	this.writeMenu = function() {
		var menuStr = new String();
		o_Bor = this.o_Bor;
		i_Bor = this.i_Bor;
		if (this.numItems == 0) menuType[currentMenuNo] = 'blank';
		else menuType[currentMenuNo] = 'default';
		menuStr += "\n" + SourceDepth(psDepth) + '<div id="menu' + currentMenuNo
             + '" class="myMenu"';
		if (!ns4) menuStr = menuStr;
		menuStr += '>' + "\n" + SourceDepth(psDepth)
             + ' <table border="0" cellpadding="0" cellspacing="0">' + "\n";
		if (this.orientation == 'vertical') {
			if (o_Bor != null) menuStr = menuStr;
			for (var count = 0; count < this.numItems; count++) {
				menuStr += this.rowText[count+1];
				if (o_Bor != null) menuStr = menuStr;
				menuStr += this.itemText[count+1];
				if (o_Bor != null) menuStr = menuStr;
				menuStr += SourceDepth(psDepth) + '  </tr>' + "\n";
				if (i_Bor != null && count < (this.numItems-1)) {
					if (o_Bor != null) menuStr = menuStr;
					else menuStr = menuStr;
				}
			}
			if (o_Bor != null) menuStr = menuStr;
		} else {
			if (o_Bor != null) {
				if (i_Bor != null) menuStr = menuStr;
				else menuStr = menuStr;
			}
			menuStr += SourceDepth(psDepth) + '  <tr>' + "\n";
			if (o_Bor != null) menuStr = menuStr; 
			for (var count = 0; count < this.numItems; count++) {		
				menuStr += this.rowText[count+1];			
				menuStr += this.itemText[count+1];
				if (i_Bor != null && count < (this.numItems-1)) {
					menuStr = menuStr;
				}
			}
			if (o_Bor != null) {
				menuStr = menuStr;
				if (i_Bor != null) menuStr = menuStr;
				else menuStr = menuStr; 
			}
			menuStr +=  SourceDepth(psDepth) + '  </tr>' + "\n";
		}
		menuStr += SourceDepth(psDepth) + ' </table>' + "\n" + SourceDepth(psDepth)
             + '</div>' + "\n";
		document.write(menuStr);
	}
}
