/*******************************************************************************
*
*	Menu.js
*		extends SubMenu.js
*
*******************************************************************************/


/*******************************************************************************
* CONSTRUCTOR
*******************************************************************************/
function Menu(args)
{
	/* Empty Constructor */
	if (! args)
	{
		args = [];
	}

	this._init(args);		
	
}

/*******************************************************************************
* EXTEND
*******************************************************************************/
Menu.extendClass(SubMenu);

/*******************************************************************************
*	INIT
*******************************************************************************/
Menu.prototype._init = function(menuArgs)
{
	// Create the container element which holds the menu;
	//document.writeln('<div id="bitbase_menu" style="background-color:#FFFF00;"></div>');
	
	// Arguments to pass to the base class
	var subMenuArgs = [];
	
	this._layout = menuArgs['LAYOUT'] || 'TOP_MENU';

		
		switch (this._layout)
		{
			case 'TOP_MENU':
				/***********************************************************************
				*	TOP_LAYOUT
				*
				*		menu1 	  menu2		 menu3
				*					    sub2_1
				*						  sub2_2
				*						  sub2_3 -> sub_2_3_1
				*									      sub_2_3_2
				***********************************************************************/
				subMenuArgs['LAYOUT'] 		= 'TOP_MENU';
				subMenuArgs['DIRECTION'] 	= 'HORIZONTAL';
				break;
			
			case 'LEFT_MENU':
				/***********************************************************************
				*	LEFT_LAYOUT
				*
				*		menu1
				*		menu2	-> sub2_1
				*		menu3		 sub2_2 -> sub2_2_1
				*											 sub2_2_2
				***********************************************************************/			
				//subMenuArgs['LAYOUT'] 		= 'LEFT_MENU';
				subMenuArgs['DIRECTION'] 	= 'VERTICAL';
				break;
				
			case 'COLLAPSE_MENU':
				//alert("NOT YET SUPPORTED");
				subMenuArgs['DIRECTION'] 	= 'VERTICAL';
				break;
		}


	// Init the Menu according to the base class
	Menu.superclass._init.call(this, subMenuArgs);	
	
	// Overwrite the base class' hidden property
	//this._show();
	
	// Overwrite the base class' onmouseout event.
	
	// CHANGE
	//var self = this;
	//this._node.onmouseout = function(e) {  self._menuMouseOut(e); }
}

/*******************************************************************************
* PUBLIC METHODS
*******************************************************************************/

	/*****************************************************************************
	*
	*	toString() : string [ overwritten ]
	*
	*****************************************************************************/
	Menu.prototype.toString = function()
	{
		return "[Menu " + this.id + "]";
	}
	
	
	Menu.prototype.paint = function()
	{
		//alert("OBSOLETE Menu.prototype.paint");
		document.writeln('<div id="bitbase_menu" style="background-color:#FFFF00;"></div>');		
		
		if (this._getLayout() == 'COLLAPSE_MENU')
		{
			this._paint();
		}
		else
		{
			this._paint();
			this._show();
			
			// Register Event Handler
			var self = this;
			this._node.onmouseout = function(e) {  self._menuMouseOut(e); }		
		}
	}

/*******************************************************************************
* PRIVATE METHODS
*******************************************************************************/

	/*****************************************************************************
	*
	*	_hideAll() : void [ overwritten ]
	*
	*	overwrites the base class' _hideAll method: do not hide the main menu!
	*
	*****************************************************************************/
	Menu.prototype._hideAll = function()
	{
		//alert("OBSOLETE Menu.prototype._hideAll");
		for (var i = 0; i < this._getMenuItemsCount(); i++)
		{
			if (this._menuItems[i]._subMenu)
			{
				this._menuItems[i]._subMenu._hideAll();
			}
		}	
	}

	/*****************************************************************************
	*
	*	_getLevel() : int [ overwritten ]
	*
	*	return always 0, which means root level
	*
	*****************************************************************************/
	Menu.prototype._getLevel = function()
	{
		return 0;
	}

	/*****************************************************************************
	*
	*	_getLevel() : Menu [ overwritten ]
	*
	*	return always this
	*
	*****************************************************************************/
	Menu.prototype._getRootMenu = function()
	{
		return this;
	}
	
	Menu.prototype._getLayout = function()
	{
		return this._layout;
	}

/*******************************************************************************
*	PRIVATE EVENT HANDLERS
*******************************************************************************/

	/*****************************************************************************
	*
	*	_menuMouseOut() : void
	*
	*	gets called when the mouse leaves the base div area
	*
	*****************************************************************************/
	Menu.prototype._menuMouseOut = function(e)
	{
		//alert("OBSOLETE Menu.prototype._menuMouseOut");
		if (!e) var e = window.event;
	
		// need to check where the mouse moves to, because of event 
		// bubbling/propagation
		var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
		
		if (! reltg.bitbaseMenuItem)
		{
			this._hideAll();
		}
	}



