//*** CLASS MenuToolbar ***************************************************
function MenuToolbar(id, label, width, height, bgColor, fontColor, borderColor, imgUrl) {
	this._id = id;
	
	//interface Avatar
	this._projection = new Projection(id, this, width, height, 8, INIT_VANISH_X, INIT_VANISH_Y, INIT_VANISH_Z, DEFAULT_SPEED);
	this._projection._parent = this; //register this Avatar with its child Projection for callbacks
	this._domId = "MenuToolbar_" + id;
	this._label = label;
	this._bgColor = bgColor;
	this._fontColor = fontColor;
	this._borderColor = borderColor;
	this._imageUrl = imgUrl;
	//end interface
	
	//interface Agent
	this._isSelfTargeting = 0;
	this._isOpened = 0;
	this._isParked = 0;
	this._isClosing = 0;
	this._isMouseOver = 0;
	this._isWatching = 0;
	//end interface
	
	this.createDOM();
	//this._projection.set3DPosition(10, 10, 50);
}

MenuToolbar.prototype._id;
MenuToolbar.prototype._projection;
MenuToolbar.prototype._domId;
MenuToolbar.prototype._label;
MenuToolbar.prototype._bgColor;
MenuToolbar.prototype._fontColor;
MenuToolbar.prototype._borderColor;
MenuToolbar.prototype._imageUrl;
MenuToolbar.prototype._isSelfTargeting;
MenuToolbar.prototype._isOpened;
MenuToolbar.prototype._isClosing;
MenuToolbar.prototype._isParked;
MenuToolbar.prototype._isMouseOver;
MenuToolbar.prototype._isWatching;

//interface Avatar
MenuToolbar.prototype.reachedTarget = function() {		
	if(this._isClosing == 1) {
			this._isOpened = 0;
			this._isClosing = 0;
	} else {
			//finished opening
	}
	this._projection._speed = DEFAULT_SPEED;
	this._isSelfTargeting = 0;
}

//interface Avatar
MenuToolbar.prototype.createDOM = function() {
	var ProjectionScreen2D_DOM =  document.getElementById('ProjectionScreen2D');
	var ToolbarDOM = document.createElement("div");
	
	var IdAttr = document.createAttribute("id");
	IdAttr.nodeValue = this._domId;
	ToolbarDOM.setAttributeNode(IdAttr);
	
	var ClassAttr = document.createAttribute("class");
	ClassAttr.nodeValue = "menu_toolbar";
	ToolbarDOM.setAttributeNode(ClassAttr);
	
	ProjectionScreen2D_DOM.appendChild(ToolbarDOM);
	
	$("div#" + this._domId).append("[<a class=\"menu_tool_axis\" href=\"\">horiz/vert</a>]<br/>[<a class=\"menu_tool_clockwise\" href=\"\">counter/clock</a>]<br/>[<a class=\"menu_tool_mode\" href=\"\">wheel/shuffle</a>]");
	$("div#" + this._domId).css("width", this._projection._width).css("height", this._projection._height);
	$("div#" + this._domId).css("font-size", this._projection._fontsize).css("color", this._fontColor).css("background-color", this._bgColor).css("border-color", this._borderColor);
	
	$("div#" + this._domId + "//a.menu_tool_axis").bind("click", handleMenuToolAxis);
	$("div#" + this._domId + "//a.menu_tool_clockwise").bind("click", handleMenuToolClockwise);
	$("div#" + this._domId + "//a.menu_tool_mode").bind("click", handleMenuToolMode);
	//$("div#" + this._domId).bind("mouseover", handleMouseOverToolbar);
	//$("div#" + this._domId).bind("mouseout", handleMouseOutToolbar);
}

//interface Avatar
MenuToolbar.prototype.updateDOM = function() {
	//this function is highly performance critical! Keep it as fast as possible!
	var AvatarDOM = document.getElementById(this._domId);
	AvatarDOM.style.left = this._projection._projectedX + "px";
	AvatarDOM.style.top = this._projection._projectedY + "px";
	AvatarDOM.style.width = this._projection._projectedWidth + "px";
	AvatarDOM.style.height = this._projection._projectedHeight + "px";
	AvatarDOM.style.fontSize = this._projection._projectedFontsize + "pt";
	AvatarDOM.style.zIndex = (VIRTUAL_SPACE_DEPTH + 100) - this._projection._posZ;
	if(this._imageUrl != "") {
		AvatarDOM.lastChild.width = this._projection._projectedWidth;
		AvatarDOM.lastChild.height = this._projection._projectedHeight;
	}
}

//interface Avatar
MenuToolbar.prototype.removeDOM	= function() {
	$("div#" + this._domId).remove();
}

//interface Avatar
MenuToolbar.prototype.showDOM	= function() {
	$("div#" + this._domId).show();
}

//interface Avatar
MenuToolbar.prototype.hideDOM	= function() {
	$("div#" + this._domId).hide();
}


MenuToolbar.prototype.openView = function() {
	this._isOpened = 1;
	this.showDOM();
}

MenuToolbar.prototype.closeView = function() {
	this.hideDOM();
	this._isOpened = 0;
}

MenuToolbar.prototype.warpToActiveMenu = function() {
	this._projection.set3DPosition(MENU_STACK[ACTIVE_MENU_ID]._menuAvatar._projection._posX, MENU_STACK[ACTIVE_MENU_ID]._menuAvatar._projection._posY - UNIQUE_MENU_TOOLBAR._projection._height, MENU_STACK[ACTIVE_MENU_ID]._menuAvatar._projection._posZ);
}
//*** END CLASS MenuToolbar **************************************************
