var Bag = null;
var Menus = new Array();
function convertToMenu(Button, Menu)
{
	if(top.pieceOfJunk || !Button || !Menu) return null;
	
	if(!Bag) {
		Bag = document.createElement('DIV'); Bag.id = 'menu_bag';
		document.getElementsByTagName('BODY')[0].appendChild(Bag);
	}
	
	Bag.appendChild(Menu);
	
	Menu.style.visibility = 'hidden';
	Menu.style.display = 'block';
	Menu.style.position = 'absolute';
	Menu.style.left = findPosX(Button) + 'px';
	Menu.style.top = findPosY(Button) + Button.offsetHeight + 'px';
	
	Button.Menu = Menu;
	
	Button.Menu.index = Menus.length;
	Menus[Menus.length] = Button.Menu;
	
	Button.onmouseover = function () {
		this.Menu.timer = clearTimeout(this.Menu.timer);
		this.Menu.style.visibility = 'visible';
	}
	Button.onmouseout = function () {
		this.Menu.timer = clearTimeout(this.Menu.timer);
		this.Menu.timer = setTimeout('hideMenu(' + this.Menu.index + ')', 100);
	}
	
	Menu.onmouseover = function () {
		this.timer = clearTimeout(this.timer);
		this.style.visibility = 'visible';
	}
	Menu.onmouseout = function () {
		this.timer = clearTimeout(this.timer);
		this.timer = setTimeout('hideMenu(' + this.index + ')', 100);
	}
	
	return Button;
}

function hideMenu(index)
{
	var Menu = Menus[index];
	if(!Menu) return;
	
	Menu.timer = clearTimeout(Menu.timer);
	Menu.style.visibility = 'hidden';
}

//Credits go to PPK of quirksmode.org for the following scripts
//THANKS!
function getObj(name)
{
  if (document.getElementById)
  {
  	return document.getElementById(name);
  }
  else if (document.all)
  {
	return document.all[name];
  }
  else if (document.layers)
  {
   	return document.layers[name];
  }
  else return null;
}
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
