var timeOn = null;
var numMenus = 1000;

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);

var openedMenu = null;
function showMenuBar(barname) {
  
  
  if (openedMenu != null) {
     document.getElementById(openedMenu).style.display = "none"; 
  }
  
  if (document.getElementById(barname).style.display == "inline") {
	  document.getElementById(barname).style.display = "none"; 
  } else { 
	  document.getElementById(barname).style.display = "inline"; 
    openedMenu = barname;
  }
}

function bulletPoint(offURL, onURL) {	
	this.offImage = new Image();
	this.offImage.src = offURL;
	this.onImage = new Image();
	this.onImage.src = onURL;
	this.URL = String(offURL);
}

function openMe(newin) {
  flyout=window.open(newin,"flyout","");
  flyout.focus();
}

function menuOver() {
	clearTimeout(timeOn);
}

function menuOut() {
	timeOn = setTimeout("hideAllMenus()", 1000);
}


function showMenu(m_No, eventObj) {
	hideAllMenusTier(tier[m_No]-1);
	var borderModSize = borderMod[m_No];
		changeBGColour('labelCell' + m_No, onColours[m_No]);
		changeClass('menuLink' + m_No, onClass[m_No]);

	if (labelBulletName[m_No] != null){
		changeImage('menuBullet' + m_No, labelBulletName[m_No] + '.onImage');
	}
	menuActive[m_No] = true;
	if (menuType[m_No] != 'blank') {
		
		labelObj = 'labelCell'+m_No;
		
		x = getElementLeft(labelObj)-12;
		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;
	}
}

function showMenuSide(m_No, eventObj, myTier) {

	hideAllMenusTier(tier[m_No]-1);
	var borderModSize = borderMod[m_No];
		changeBGColour('labelCell' + m_No, onColours[m_No]);
		changeClass('menuLink' + m_No, onClass[m_No]);
	if (labelBulletName[m_No] != null) changeImage('menuBullet' + m_No, labelBulletName[m_No] + '.onImage');
	menuActive[m_No] = true;
	if (menuType[m_No] != 'blank') {
			labelObj = 'labelCell'+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;
	}
}

function hideAllMenus() {
	for (var i = 1; i < (currentMenuNo+1); i++) {
		if(menuActive[i] == true) hideMenu(i);
	}
}

function hideAllMenusTier(myTier) {
  for (var i = 1; i < (currentMenuNo+1); i++) {
		if( tier[i] > myTier && menuActive[i] == true) hideMenu(i);
	}
}

function hideMenu(m_No) {

		changeBGColour('labelCell' + m_No, offColours[m_No]);
		changeClass('menuLink' + m_No, offClass[m_No]);

	if (labelBulletName[m_No] != null){
		changeImage('menuBullet' + m_No, labelBulletName[m_No] + '.offImage');
	}
	menuActive[m_No] = false;
	
	if(changeObjectVisibility('menu' + m_No, 'hidden'))  return true;
    else return false;

}



function menuBar(barName, barWidth, offColour, onColour) {
	this.numLabels = 0;
	this.height = 15;
	this.labelText = new Array();
	this.rowText = new Array();
	this.offClass = 'MenuLabelLink';
	this.onClass = 'MenuLabelLinkOn';
	this.bulletAlign = 'left';
  this.align = 'left';
  this.labelWidth = barWidth
  this.offColour = offColour;
  this.onColour = onColour;

	this.addLabel = function(menuNo, labelText, labelURL, bullet, target, backcolor) {
    
    this.numLabels += 1;
		tier[menuNo] = 0;		
		borderMod[menuNo] = 1;	


	  if (menuNo != null) {
      if (backcolor != null) {
	   	  onColours[menuNo] = backcolor;
	      offColours[menuNo] = backcolor;
        this.offColour = backcolor;
        this.onColour = backcolor;
      } else {
	   	  onColours[menuNo] = this.onColour;
	      offColours[menuNo] = this.offColour;
      }
			onClass[menuNo] = this.onClass;
			offClass[menuNo] = this.offClass;
			labelBulletName[menuNo] =  bullet;
		}

		temp = new String('');
		this.rowText[this.numLabels] = new String('');
	  this.rowText[this.numLabels] += '<tr id="labelRow'+ menuNo + '">';

		temp += '<td  style="border-bottom: 1px solid black;" id="labelCell' + menuNo + '" width="'+ this.labelWidth + '" bgcolor="' + this.offColour + '" valign="middle" height="' + this.height + '" ';
		
	  if (menuNo != null) {
		  temp += ' onmouseout="menuOut(); "onmouseover="menuOver(); return !showMenuSide(' + menuNo + ', event, tier[' + menuNo + ']);"';
		/**/  
 	  }	else temp += 'return !showMenu(' + menuNo + ', event);" ';
	/**/  if (target=='new') temp += ' onclick="openMe(\'' + labelURL + '\'); return false;" ';
	/**/    else temp += ' onclick="document.location.href=\'' + labelURL + '\';" ';
		temp +='><div class="myMenuLabel' + this.align + '" width="' + this.labelWidth + '"  id="menuLabel' + menuNo +'"><a href="' + labelURL +'" class="' + this.offClass + '"';
    if (target == 'new') {
      temp += ' target="new" ';
    }
     temp += 'id="menuLink' + menuNo +'"><img src="' + eval(bullet + ".URL") + '" border="0" class="menuimage"';
    temp += 'align="' + this.bulletAlign + '" id="menuBullet' + menuNo + '" name="menuBullet' + menuNo + '">';
    
		temp += labelText + '&nbsp;&nbsp;&nbsp;</a></div></td>';
 	 this.labelText[this.numLabels] = new String(temp);
  }
	
	this.writeMenuBar = function() {
		menuBarStr = new String();
		menuBarStr += '<div id="' + barName + '"  style="display:none;"><table style="border-left: 1px solid black; border-right: 1px solid black;border-top: 1px solid black;" border="0" cellpadding="0" cellspacing="0">';
			for (var count = 0; count < this.numLabels; count++) {		
		    menuBarStr += this.rowText[count+1] + this.labelText[count+1] + '</tr>';
			}
		menuBarStr += '</table></div>';
		document.write(menuBarStr);
	}
}


function menu(menuNumber, menuWidth,offColour, onColour) {
 
	//currentMenuNo += 1;
  currentMenuNo = menuNumber;
  this.menuNumber = menuNumber
	this.numItems = 0;
	this.height = 15;
	this.itemText = new Array();
	this.rowText = new Array();
	this.align = 'left';
	this.offClass = 'MenuItemLink';
	this.onClass = 'MenuItemLinkOn';
	this.bulletAlign = 'left';
 	this.offColour = offColour;
  this.onColour = onColour;
  this.itemsAlign = "left";
  this.itemWidth = menuWidth;


	this.addItem = function(itemText, itemURL, menuNo, bullet, target) {
 
	
    this.numItems += 1;
		var tempId = currentMenuNo + '_' + this.numItems;
	
		if (menuNo != null) {
			tier[menuNo] = tier[currentMenuNo] + 1;
			onColours[menuNo] = this.onColour;
			offColours[menuNo] = this.offColour;
			onClass[menuNo] = this.onClass;
			offClass[menuNo] = this.offClass;
			labelBulletName[menuNo] = bullet;
			if (this.o_Bor != null) borderMod[menuNo] = 1;	
			else borderMod[menuNo] = 0;	
		}
		
		temp = new String('');
		this.rowText[this.numItems] = new String('');
		
		if (menuNo != null) {
			this.rowText[this.numItems] += '<tr id="labelRow'+ menuNo + '">';
			temp += '<td style="border-bottom: 1px solid black;" id="labelCell'+ menuNo + '" width="'+ this.itemWidth + '" bgcolor="' + this.offColour + '" valign="middle" height="' + this.height + '" ';
		} else {
			this.rowText[this.numItems] += '<tr>';
			temp += '<td style="border-bottom: 1px solid black;" id="itemCell' + tempId + '" width="'+ this.itemWidth + '" bgcolor="' + this.offColour + '" valign="middle" height="' + this.height + '" class="' + this.align + 'Menu"';
		}		
		if (target=='new') temp += ' onclick="openMe(\'' + itemURL + '\'); return false;" ';
	  else temp += ' onclick="document.location.href=\'' + itemURL + '\';" ';
		
		if (menuNo != null) {			
		  temp += ' onmouseover="menuOver(); return !showMenuSide(' + menuNo + ', event, tier[' + menuNo + ']); " onmouseout=" menuOut(); "';
		} else {
		  temp += ' onmouseover="changeClass(\'menuLink' + tempId + '\',\'' + this.onClass + '\'); hideAllMenusTier(tier[' + this.menuNumber + ']); menuOver();  changeBGColour(\'itemCell' + tempId + '\', \'' + this.onColour + '\'); changeImage(\'menuItemBullet' + tempId + '\', \'' + bullet + '.onImage\'); " onmouseout="menuOut(); changeClass(\'menuLink' + tempId + '\',\'' + this.offClass + '\'); changeBGColour(\'itemCell' + tempId + '\', \'' + this.offColour + '\'); changeImage(\'menuItemBullet' + tempId + '\', \'' + bullet + '.offImage\'); "';
    }
		temp += '><div class="myMenuItem' + this.align + '" width="' + this.itemWidth + '"';
	
		if (menuNo != null) temp += ' id="menuLabel' + menuNo +'"';
		else temp += ' id="menuItem' + tempId +'"';
		
		temp += '><a href="' + itemURL  + '" class="' + this.offClass + '"';
    if (target == 'new') temp += ' target="new"';  
		if (menuNo != null) temp += 'id="menuLink' + menuNo +'"';
		else temp += 'id="menuLink' + tempId +'"';
		temp +='>';
		
		if (bullet != null) {
			if (menuNo != null) temp += '<img src="' + eval(bullet + ".URL") + '" border="0" class="menuimage" align="' + this.bulletAlign + '" id="menuBullet' + menuNo + '" name="menuBullet' + menuNo + '">';
			else temp += '<img src="' + eval(bullet + ".URL") + '" border="0" class="menuimage" align="' + this.bulletAlign + '" id="menuItemBullet' + tempId + '" name="menuItemBullet' + tempId + '">';
		}
  	temp += itemText + "&nbsp;" + '</a></div></td>';	
  	this.itemText[this.numItems] = new String(temp);
	}
	this.writeMenu = function() {
  	var menuStr = new String();
		o_Bor = this.o_Bor;
		i_Bor = this.i_Bor;

    menuType[currentMenuNo] = 'default';
		menuStr += '<div id="menu' + this.menuNumber + '" name="menu' + this.menuNumber + '" class="myMenu" width="' + menuWidth + '"	 style="width:' + menuWidth + ';">';
    menuStr += '<table style="border-left: 1px solid black; border-right: 1px solid black;border-top: 1px solid black;" border="0" cellpadding="0" cellspacing="0" width="' + menuWidth + '">';
			for (var count = 0; count < this.numItems; count++) {
         menuStr += this.rowText[count+1] + this.itemText[count+1] + '</tr>';
   		}
		menuStr += '</table></div>';
		document.write(menuStr);
	}
}
