var out = new String(); 
var vidc = 0;
function MenuBar(type, size)
{
	this.type = type;
	this.size = size;
	this.origin = new Point(0,0,0);
	this.menus = new Array();
	this.addMenu = addMenu;
	this.write = writeMenuBar;
}
function writeMenuBar()
{
	out = out + "<DIV class='menuBar1' style='Z-INDEX: " + this.origin.z + "; LEFT: " + this.origin.x + "px; TOP: " + this.origin.y + "px; '>";
	
	for (var i = 0; i < this.menus.length; i++)
	{
		this.menus[i].write();
	}
	out = out + "</DIV>";
	return out;
}
function Point(x, y, z)
{
	this.x = x;
	this.y = y;
	this.z = z;	
}
function Size(x, y)
{
	this.x = x;
	this.y = y;
}
function Menu(title, type, value, origin, size)
{
	this.title = title;	
	this.nid = vidc++;
	this.type = type;
	this.value = value;
	this.origin = origin;
	this.size = size;
	this.menus = new Array();
	this.addMenu = addMenu;
	this.hide = hideMenu;
	this.show = showMenu;
	this.write = writeMenu;
}

function writeMenu()
{
	var add = "";
	switch(this.type)
	{
		case 1:
			var cls = "menuTitle";
			if(this.menus.length < 1)
			{				
				cls = "menuTitleNoDrop";
			}
			out = out + "<DIV class='menuGround" + this.type + "' id='g" + this.nid + "' onMouseOver='gotFocus(" + this.nid + ", " + this.type + ", " + this.value[1] + ', "' + cls + '"' + ");' onMouseOut='lostFocus(" + this.nid + ", " + this.type + ", " + this.value[0] + ', "' + cls + '"' + ");' style='Z-INDEX: " + this.origin.z + "; LEFT: " + this.origin.x + "px; TOP: " + this.origin.y + "px;'>";
			out = out + "<DIV class='menuTitle" + this.type + "out' id='t" + this.nid + "' style='Z-INDEX: " + this.origin.z + "; LEFT: " + this.origin.x + "px; TOP: " + this.origin.y + "px; WIDTH: " + this.size.x + "; HEIGHT: " + this.size.y + ";'>";			
			
			if (this.value[2])
			{
				add = " onClick='window.location = " + '"' + this.value[2] + '"' + ";' style ='CURSOR: hand;' ";
			}
			out = out + "<IMG " + add + " id='i" + this.nid + "' src=" + this.value[0] + ">";
			out = out + "</DIV>";		
			out = out + "<DIV class='menuBody" + this.type + "' id='b" + this.nid + "'  style='Z-INDEX: " + this.origin.z + "; POSITION: absolute; VISIBILITY = hidden; LEFT: 0px; TOP: 0px; WIDTH: " + this.size.x + "'>";
			if(this.menus.length < 1)
			{				
				out = out + "<input type=hidden style='POSITION: absolute; HEIGHT: 0px; WIDTH: 0px;'>";
			} else {
				for (var i = 0; i < this.menus.length; i++)
				{
					this.menus[i].write();
				}				
			}
			out = out + "</DIV>";
			out = out + "</DIV>";			
		break;
		case 2:			
			out = out + "<DIV onmouseover='gotFocus(" + this.nid + ", " + this.type + ", 0" + ', "menuTitle"' + ");' onmouseout='lostFocus(" + this.nid + ", " + this.type + ", 0" + ', "menuTitle"' + ");' onClick='window.location = " + '"' + this.value + '"' + ";' class='menuTitle" + this.type + "out' id='t" + this.nid + "' style='Z-INDEX: " + this.origin.z + "; LEFT: " + this.origin.x + "px; TOP: " + this.origin.y + "px; WIDTH: " + this.size.x + ";'>" + this.title + "</DIV>";
		break;
		
	}
}
function gotFocus(nid, type, value, oClass)
{
	var eobj;
	switch(type)
	{
		case 1:
			eobj = document.getElementById("b" + nid);
			eobj.style.visibility = 'inherit';
			eobj.style.position = '';
			
			eobj = document.getElementById("i" + nid);
			eobj.src = value;
			
		break;
		case 2:
			
		break;
		
	}
	eobj = document.getElementById("t" + nid);	
	eobj.className = oClass + type + "over";
}
function lostFocus(nid, type, value, oClass)
{
	var eobj;
	switch(type)
	{
			case 1:
				eobj = document.getElementById("b" + nid);
				eobj.style.visibility = 'hidden';
				eobj.style.position = 'absolute';
				eobj.style.left = 0;
				eobj.style.top = 0;
				eobj = document.getElementById("i" + nid);
				eobj.src = value;
				
			break;
			case 2:
				
			break;			
	}
	eobj = document.getElementById("t" + nid);
	eobj.className = oClass + type + "out";
}
function showBody(nid)
{
	var eobj = document.getElementById("b" + nid);
	eobj.style.visibility = 'inherit';
	eobj.style.position = '';
}

function hideBody(nid)
{
	
}

function addMenu(title, type, value)
{
	var origin = new Point(this.origin.x, this.origin.y, this.origin.z);
	switch(type)
	{
		case 1:
			origin.x = this.menus.length * this.size.x + origin.x + 0;
			origin.y = origin.y;
			origin.z = origin.z + 1;
			break;
		case 2:
			origin.x = origin.x;
			origin.y = origin.y;
			origin.z = origin.z + 1;
			break;
	}
	
	
	this.menus[this.menus.length] = new Menu(title, type, value, origin, new Size(this.size.x, this.size.y));
	
}
function hideMenu()
{
	
}
function showMenu()
{
	
}