var timeOn = null;
var currentMenuType = null;
var currentMenuNo = 0;
var offClass = new Array();
var onClass = new Array();
var offColours = new Array();
var onColours = new Array();
var labelBulletName = new Array();
var itemBulletName = new Array();
var menus = new Array();
var hideMenu = null;
var hideNo = null;

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","")
}

function menuOver() {
	clearTimeout(timeOn);
}

function menuOut(menuType, m_No) {
	currentMenuType = menuType;
	currentMenuNo = m_No;
	timeOn = setTimeout("hideThisMenu()", 20);
}

function hideThisMenu() {
	var menuType = currentMenuType;
	var m_No = currentMenuNo;
	changeBGColour(menuType + 'Label' + m_No, offColours[menuType]);
	changeClass(menuType + 'LabelLink' + m_No, offClass[menuType]);
	changeImage(menuType + 'menuBullet' + m_No, labelBulletName[menuType] + '.offImage');

	var itemsObj = menuType + 'Table' + m_No;

	if(changeObjectVisibility(itemsObj, 'hidden'))  return true;
    else return false;
}

function showMenu(menuType, m_No) {
	var numMenus = menus[menuType];
	for(var i = 0; i <= numMenus; i++){
		if( i != m_No)
			hideThisMenu();
	}

	changeBGColour(menuType + 'Label' + m_No, onColours[menuType]);
	changeClass(menuType + 'LabelLink' + m_No, onClass[menuType]);
	changeImage(menuType + 'menuBullet' + m_No, labelBulletName[menuType] + '.onImage');

	var labelObj = menuType +'Label'+m_No;
	var itemsObj = menuType + 'Table' + m_No;

	var x = getElementLeft(labelObj);
	var y = getElementTop(labelObj) + getElementHeight(labelObj);
	x = x + (getElementWidth(labelObj)-getElementWidth(itemsObj));

	moveXY(itemsObj, x, y);

	if(changeObjectVisibility(itemsObj, 'visible')) return true;
    else return false;
}

function menu(menuType, menuNo, barWidth, barHeight){
	this.menuName = menuType + 'Menu' + menuNo;
	this.barWidth = barWidth;
	this.barHeight = barHeight;
	this.bulletWidth = 20;
	this.labelName = null;
	this.labelWidth = barWidth - this.bulletWidth;
	this.labelLink = null;
	this.label = null;
	this.offClass = menuType + 'MenuLabelLink';
	this.onClass = menuType + 'MenuLabelLinkOn';
	this.targetType = 'self'; // self, iframe, frame, new
	this.targetFrame = '_self'; // _self, _blank or (i)frame name
	
	if( menus[menuType] == null || menus[menuType] == '')
		menus[menuType] = 0;
	else
		menus[menuType]++;
	
	this.addLabel = function(bullet, labelText, offColour, onColour, labelURL) {
		onColours[menuType] = onColour;
		offColours[menuType] = offColour;
		onClass[menuType] = this.onClass;
		offClass[menuType] = this.offClass;
		labelBulletName[menuType] = bullet;
		this.labelName = menuType + 'Label' + menuNo;
		temp = new String();
		temp += '<tr> <td id="' + this.labelName + '" style="padding-bottom: 1px; text-align: center; vertical-align: middle; width:' + this.barWidth + 'px; height: ' + this.barHeight + 'px; color: ' + onColour + '; border: 1px solid ' + onColour + '; background-color: ' + offColour + '" ';
		
		//for showing and hiding menu
		temp += ' onmouseout="menuOut(\'' + menuType + '\', ' + menuNo + '); " onmouseover="menuOver(); ';
		temp += 'return !showMenu(\'' + menuType + '\', ' + menuNo + ');" ';

		if( labelURL != null){
		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 + '\';" ';
		
		this.labelLink = 'href="' + labelURL +'"';
		}

		temp +='>';
		temp +=	'<a class="' + menuType + 'MenuLabelLink" id="' + menuType + 'LabelLink' + menuNo + '" ' + this.labelLink + '>' + labelText;
		temp += '<img id="'+ menuType + 'menuBullet' + menuNo + '" style="border: 0px; padding: 0px; margin: 0px;" src="' + eval(bullet + ".URL") + '"></a>';
		temp += '</td> </tr>';

		this.label = new String(temp);
	}

	this.writeMenu = function() {
		tempMenu = new String();
		tempMenu += '<div id="' + this.menuName + '" name="' + this.menuName + '"> <table cellspacing="0" cellpadding="0">';
		tempMenu += this.label;
		tempMenu += '</table> </div>';
		document.write(tempMenu);
	}
}

function menuItems( menuType, menuNo, itemWidth, itemHeight) {
	this.tableName = menuType + 'Table' + menuNo;
	this.itemWidth = itemWidth;
	this.itemHeight = itemHeight;
	this.tempItems = new String();
	this.offClass = menuType + 'MenuItemLink';
	this.onClass = menuType + 'MenuItemLinkOn';
	this.targetType = 'self'; // self, iframe, frame, new
	this.targetFrame = '_self'; // _self, _blank or (i)frame name
	this.addTopBorder = '';

	this.addItem = function(bullet, itemText, itemNo, offColour, onColour, itemURL) {
		this.border = onColour;
		itemBulletName[menuNo] = bullet;
		this.itemName = menuType + 'Item' + menuNo + '_' + itemNo;
		this.itemLink = menuType + 'ItemLink' + menuNo + '_' + itemNo;
		this.itemBullet = menuType + 'ItemBullet' + menuNo + '_' + itemNo;
		
		//add border to top item
		if(itemNo == 0)
			this.addTopBorder = 'border-top: 1px solid' + this.border + '; ';
		else
			this.addTopBorder = '';
		
		temp = new String();
		temp += '<tr> <td id="' + this.itemName + '" style="vertical-align: middle; width: ' + this.itemWidth + 'px; height: ' + this.itemHeight + 'px; color: ' + onColour + '; ' + this.addTopBorder + 'border-bottom: 1px solid ' + onColour + '; border-right: 1px solid ' + onColour + '; background-color: ' + offColour + '; margin: 0px; padding: 0px;" ';

		//for showing and hiding menu
		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 + '\';" ';
		temp += ' onmouseover="changeClass(\'' + this.itemLink + '\',\'' + this.onClass + '\'); menuOver(); changeBGColour(\'' + this.itemName + '\', \'' + onColour + '\'); changeImage(\''+ this.itemBullet + '\', \'' + itemBulletName[menuNo] + '.onImage\');" onmouseout="menuOut(\'' + menuType + '\', ' + menuNo + '); changeClass(\'' + this.itemLink + '\',\'' + this.offClass + '\'); changeBGColour(\'' + this.itemName +  '\', \'' + offColour + '\'); changeImage(\''+ this.itemBullet + '\', \'' + itemBulletName[menuNo] + '.offImage\');"';

		temp += '>';				
		temp +=	'<a class="' + menuType + 'MenuItemLink" id="' + this.itemLink + '" href="' + itemURL +'">';
		temp += '<img id="' + this.itemBullet + '" style="border: 0px; padding: 0px; margin-right: 5px;" src="' + eval(bullet + ".URL") + '">';
		temp += itemText + ' </a>';
		temp += '</td> </tr>';

		this.tempItems += new String(temp);
	}

	this.writeMenuItems = function() {
		tempMenuItems = new String();
		tempMenuItems += '<div class="myMenu" id="' + this.tableName + '" name="' + this.tableName + '"> <table style="width: ' + this.itemWidth + 'px; border-left: 1px solid ' + this.border + ';" cellspacing="0" cellpadding="0">';
		tempMenuItems += this.tempItems;
		tempMenuItems += '</table> </div>';
		document.write(tempMenuItems);
	}
}
