var topOffset = 20;
var leftOffset = 5;

function menuItem(text, link){
	this.text = text;
	this.link = link;
}
function menuTrigger(name, text, link){
	this.name = name;
	this.text = text;
	
	this.link = link;	// Line
}
function menu(){
	var itemArray = new Array();
	var args = menu.arguments;
	this.name = args[0];
	this.trigger = args[1];
	for(i=2; i<args.length; i++){
		itemArray[i-2] = args[i];
	}
	this.menuItems = itemArray;
	this.write = writeMenu;
	this.position = positionMenu;
}
function writeMenu(){
	var menuText = '<div id="';
	menuText += this.trigger.name;
	menuText += '" class="trigger" style="top: ';
	menuText += this.top;
	menuText += 'px; left: ';
	menuText += this.left;
	menuText += 'px; "';
	menuText += 'onMouseOver="showMenu(\'';
	menuText += this.name;
	menuText += '\')" onMouseOut="hideMenu(mnuSelected)">';
	menuText += '<table border="0" width="' + this.width + 'px" height="' + this.height + 'px">';
	menuText += '<tr><td>' 
	
	
	// Line
	if (this.trigger.link) {
		menuText += '<a class="trigger" href="' + this.trigger.link + '">';
		menuText += this.trigger.text + '</a></td></tr></table></div>';
	}
	else {
		menuText += this.trigger.text + '</td></tr></table></div>';
	}
	//
	
	if (this.menuItems.length > 0) {	// Line
		menuText += '<div id="';
		menuText += this.name;
		menuText += '" class="menu" style="top: ';
		menuText += (this.top + topOffset);
		menuText += 'px; left: ';
		menuText += this.left + leftOffset;
		menuText += 'px;" '
		menuText += 'onMouseOver="showMenu(mnuSelected)" ';
		menuText += 'onMouseOut="hideMenu(mnuSelected)">';
		menuText += '<table border="0" width="' + this.width + 'px">';
		for(i=0; i<this.menuItems.length; i++){
			menuText += '<tr>';
			menuText += '<td>';
			menuText += '<a href="' + this.menuItems[i].link + '">';
			menuText += this.menuItems[i].text + '</a></td>';
			menuText += '</tr>';
		}
	}
	
	menuText += '</table></div>';
	document.write(menuText);
	document.close();
}
function positionMenu(top,left,width, height){
	this.top = top;
	this.left = left;
	this.width = width;
	
	this.height = height;	// Line
}

var mnuSelected = '';
function showMenu(menu){
	hideMenu(mnuSelected);
	document.getElementById(menu).style.visibility = 'visible';
	mnuSelected = menu;
}
function hideMenu(menu){
	if(mnuSelected!='')
		document.getElementById(menu).style.visibility = 'hidden';
}