/*

	^ Requires brin.js
*/

var menusCreated = 0;

function MenuButton(labelString, linkString)
{
	var button = BaseObject();
	button.root.style.width = "80px";
	button.root.style.height = "13px";
	button.root.style.backgroundColor = "#CCC";
	button.root.style.fontFamily = "Arial, Helvetica";
	button.root.style.fontSize = "11px";
	button.root.style.color = "#103863";
	button.root.style.cursor = "pointer";
	button.root.style.paddingTop = "2px";
	button.root.style.marginBottom = "2px";
	button.root.innerHTML = "&nbsp; > "+labelString;
	
	button.onrollover = function(e)
	{
		button.root.style.backgroundColor = "#DDD";
	};
	
	button.onrollout = function(e)
	{
		button.root.style.backgroundColor = "#CCC";
	};
	
	button.root.onmouseup = function(e)
	{
		window.location = linkString;
	};
	
	return button;
}


function Menu(array, width, bgoffset, regionHandler)
{
	var menu = BaseObject();
	
	menu.index = menusCreated;
	++menusCreated;
	
	menu.isDim = true;
	menu.isDefault = false;
	
	menu.root.style.width = width+"px";
	menu.root.style.height = "150px";
	menu.root.style.backgroundImage = "url(/img/map.png)";
	menu.root.style.backgroundPosition = -bgoffset+"px 0px";
	menu.root.style.position = "absolute";
	menu.root.style.left = bgoffset+"px";
	menu.root.style.borderBottom = "1px solid #000";
	
	menu.dimmer = document.createElement("div");
	menu.dimmer.style.width = "100%";
	menu.dimmer.style.height = "100%";
	menu.dimmer.style.backgroundColor = "#FFF";
	menu.dimmer.style.opacity = "0.5";
	menu.dimmer.style.filter = "alpha(opacity=50)";
	menu.root.appendChild(menu.dimmer);
	
	menu.show = document.createElement("div");
	menu.show.style.position = "absolute";
	menu.show.style.left = "25%";
	menu.show.style.top = "50%";
	menu.show.style.visibility = "hidden";
	menu.root.appendChild(menu.show);
	
	menu.regionHandler = regionHandler;

	var i;
	for(i=0; i<array.length; i+=2)
	{
		menu.show.appendChild(MenuButton(array[i], array[i+1]).root);
	}
				
	menu.onrollover = function(e)
	{
		menu.lightBackground();
		menu.show.style.visibility = "visible";
        menu.root.style.zIndex = "100";
		
		menu.regionHandler(menu.index);
	};
	
	menu.onrollout = function(e)
	{
        menu.root.style.zIndex = "0";
		menu.dimBackground();
		menu.show.style.visibility = "hidden";
	};
	
	menu.lightBackground = function()
	{
		menu.isDim = false;
		menu.dimmer.style.opacity = "0.0";
		menu.dimmer.style.filter = "alpha(opacity=0)";	
	};
	
	menu.dimBackground = function()
	{
		menu.isDim = true;
		menu.dimmer.style.opacity = "0.5";
		menu.dimmer.style.filter = "alpha(opacity=50)";
	};
	
	return menu;
}
