function DriveMenuButton_mouseOver(e)
{
	var target = ReturnEventTarget((arguments.length>0 ? e : window.event), this.oDO.sTarget);
	if (target.className == "Button")
		target.className = "ButtonHover";
}

function DriveMenuButton_mouseOut(e)
{
	var target = ReturnEventTarget((arguments.length>0 ? e : window.event), this.oDO.sTarget);
	if (target.className == "ButtonHover")
		target.className = "Button";
}

DriveMenu.prototype.setMoveMenuForward = function() { alert("Menu not initialized."); };
DriveMenu.prototype.setupButtons = DriveMenu_SetupButtons;
DriveMenu.prototype.parseDMDivs = DriveMenu_ParseDMDivs;
DriveMenu.prototype.parseDMZero = DriveMenu_ParseDMZero;
DriveMenu.prototype.parseDMOne = DriveMenu_ParseDMOne;


function DriveMenu(sDriveMenuID, oDriveObject)
{
	var e = document.getElementById(sDriveMenuID);
	e.oDriveMenu = this;
	this.node = e;
	this.oDO = oDriveObject;
	this.nMenuType = 0;	// Number(e.menutype)

	switch(this.nMenuType)
	{
		case 0:
			this.oDO.sTarget = "DIV";
			this.parseDMDivs();
			break;

		case 1:
			this.parseDMZero(oDriveObject);
			break;

		case 2:
			this.parseDMOne();
			break;
	}
}

function DriveMenu_SetupButtons(arr)
{
	var nStop = arr.length;
	for (var i=0; i<nStop; i++)
	{
		var curB = arr[i];
		curB.oDO = this.oDO;
		curB.onmouseover = DriveMenuButton_mouseOver;
		curB.onmouseout = DriveMenuButton_mouseOut;
	}
}

function DriveMenu_ParseDMDivs()
{
	var arrBN = [["DMB_TurnLeft", function(){this.oDO.turnLeft();}],
				["DMB_TurnRight", function(){this.oDO.turnRight();}],
				["DMB_MoveLeft", function(){this.oDO.moveLeft();}],
				["DMB_MoveRight", function(){this.oDO.moveRight();}],
				["DMB_MoveUp", function(){this.oDO.moveUp();}],
				["DMB_MoveDown", function(){this.oDO.moveDown();}]]

	var nStop = arrBN.length;
	var arrBut = new Array(nStop);
	for (var i=0; i<nStop; i++)
	{
		arrBut[i] = document.getElementById(arrBN[i][0]);
		arrBut[i].onclick = arrBN[i][1];
	}

	this.setupButtons(arrBut);

	this.eUpDown = document.getElementById("MoveMenuUpDown");
	this.eLeftRight = document.getElementById("MoveMenuLeftRight");

	DriveMenu.prototype.setMoveMenuForward = DriveMenu_SetMoveMenuForwardZero;
}

function DriveMenu_ParseDMZero()
{
	var eTR1 = this.node.firstChild.firstChild;

	var eTurnLeft = eTR1.childNodes[0];
	var eTurnRight = eTR1.childNodes[2];

	var eMoveArea = eTR1.childNodes[1];
	this.eUpDown = eMoveArea.childNodes[0];
	this.eLeftRight = eMoveArea.childNodes[1];

	var eHeightMoveArea = eMoveArea.offsetHeight;
	eTurnLeft.style.top = eTurnRight.style.top = String(eHeightMoveArea/2) + "px";

	var eMoveUp = this.eUpDown.firstChild.childNodes[0].firstChild;
	var eMoveDown = this.eUpDown.firstChild.childNodes[1].firstChild;

	var eMoveLeft = this.eLeftRight.firstChild.firstChild.childNodes[0];
	var eMoveRight = this.eLeftRight.firstChild.firstChild.childNodes[1];

	this.setupButtons([eTurnLeft, eTurnRight, eMoveUp, eMoveDown, eMoveLeft, eMoveRight]);

	eTurnLeft.onclick = function() {this.oDO.turnLeft(); };
	eTurnRight.onclick = function() {this.oDO.turnRight(); };
	eMoveUp.onclick = function() {this.oDO.moveUp(); };
	eMoveDown.onclick = function() {this.oDO.moveDown(); };
	eMoveLeft.onclick = function() {this.oDO.moveLeft(); };
	eMoveRight.onclick = function() {this.oDO.moveRight(); };

	DriveMenu.prototype.setMoveMenuForward = DriveMenu_SetMoveMenuForwardZero;
}

function DriveMenu_ParseDMOne()
{
	var eTR1 = this.node.firstChild.firstChild;
	var eTR2 = eTR1.nextSibling;
	var eTR3 = eTR2.nextSibling;

	var eMoveLeft = eTR1.childNodes[0];
	var eMoveRight = eTR1.childNodes[1];

	var eTurnLeft = eTR2.childNodes[0];
	var eMoveUp = eTR2.childNodes[1];
	var eTurnRight = eTR2.childNodes[2];

	var eMoveDown = eTR3.firstChild;

	this.eMoveLeft = eMoveLeft;
	this.eMoveRight = eMoveRight;
	this.eMoveUp = eMoveUp;
	this.eMoveDown = eMoveDown;

	this.setupButtons([eTurnLeft, eTurnRight, eMoveUp, eMoveDown, eMoveLeft, eMoveRight]);

	eTurnLeft.onclick = function() { this.oDO.turnLeft(); };
	eTurnRight.onclick = function() { this.oDO.turnRight(); };
	eMoveUp.onclick = function() { if(this.className!="ButtonInactive") this.oDO.moveUp(); };
	eMoveDown.onclick = function() { if(this.className!="ButtonInactive") this.oDO.moveDown(); };
	eMoveLeft.onclick = function() { if(this.className!="ButtonInactive") this.oDO.moveLeft(); };
	eMoveRight.onclick = function() { if(this.className!="ButtonInactive") this.oDO.moveRight(); };

	DriveMenu.prototype.setMoveMenuForward = DriveMenu_SetMoveMenuForwardOne;
}


function DriveMenu_SetMoveMenuForwardZero(bForward)
{
	if (this.bForward != bForward)
	{
		if (bForward)
		{
			this.eUpDown.style.visibility = "visible";
			this.eLeftRight.style.visibility = "hidden";
		}
		else
		{
			this.eUpDown.style.visibility = "hidden";
			this.eLeftRight.style.visibility = "visible";
		}
		this.bForward = bForward;
	}
}

function DriveMenu_SetMoveMenuForwardOne(bForward)
{
	if (this.bForward != bForward)
	{
		if (bForward)
		{
			this.eMoveLeft.className = this.eMoveRight.className = "ButtonInactive";
			this.eMoveUp.className = this.eMoveDown.className = "Button";
		}
		else
		{
			this.eMoveLeft.className = this.eMoveRight.className = "Button";
			this.eMoveUp.className = this.eMoveDown.className = "ButtonInactive";
		}
		this.bForward = bForward;
	}
}