(function(){

/*
	Class: MenuBar 
	The base class for a collection of navigation components 
*/
function MenuBar()
{
	this.contents = new window['SB']['util']['List'];
	this.htmlObj = null;
	this.spacer = null;
}

MenuBar.prototype.toString = function() { return "[SB.ui.MenuBar]"; }

//Group: Basic Methods 
/*
	Function: setConfig
	Establishes the basic setup for the MenuBar.
	
	inConfig - A configuration array (key/value)

	Configuration Array Options:
	id - the id of the div to use as a template (default:none)
	content_cl - the css class name for the content area (default:none)
	page_left_cl - the css class name for the left pager (default:none)
	page_right_cl - the css class name for the right pager (default:none)
	spacer - an element to place between MenuBarItems
*/
MenuBar.prototype.setConfig = function( inConfig )
{
	if( inConfig.id )
		this.htmlObj = YUIDom.get( inConfig.id );

	if( inConfig.spacer )
		this.spacer = inConfig.spacer;
};

/*
	Function: addItem
	A simple method to add a <MenuBarItem> into the MenuBar
*/
MenuBar.prototype.addItem = function( inItem )
{
	inItem.bar = this;
	this.contents.append( inItem ); 
	this.htmlObj.appendChild( inItem.getHtmlObj() ); 
};	

/*
	Function: removeItem 
	A simple method to remove a <MenuBarItem> from the MenuBar
*/
MenuBar.prototype.removeItem = function( inItem )
{
	this.contents.remove( inItem );
	this.htmlObj.removeChild( inItem.getHtmlObj() ); 
};	

/*
	Function: switchMenuItemView 
	Changes the currently displayed menu item (for top level). Closes previous item
*/
MenuBar.prototype.switchMenuItemView = function( inItem )
{
	if( this.currentMenuItemView )
		this.currentMenuItemView.hideSubView( null );
	
	this.currentMenuItemView = inItem;
};	



/*
	Function: removeItemsAfter 
	A simple method to remove a <MenuBarItem> from the MenuBar
*/
MenuBar.prototype.removeItemsAfter = function( inItem )
{
	var index = this.contents.find( inItem );
	if( index >= 0 )
	{
		this.contents.removeAfter( index );
		var children = YUIDom.getChildren( this.htmlObj );	

		var removeNow = false;	

		//Get rid of everything after inItem
		for( el in children )
		{
			if( removeNow )
				this.htmlObj.removeChild( children[el] ); 

			if( children[el] == inItem.getHtmlObj() )
				removeNow = true;					
		}
	}
};	

/*
	Function: removeAllItems
	A simple method to remove all <MenuBarItem> from the MenuBar
*/
MenuBar.prototype.removeAllItems = function( )
{
	while ( this.contents.size() )
	{
		this.removeItem( this.contents.get(0) );
	}	

	var arr = YUIDom.getChildren( this.htmlObj );
	for( el in arr )
	{
		this.htmlObj.removeChild( arr[el] );
	}
};	

//Group: Delegate Methods 
/*
	Function: addItemTransition 
	A stub function which is called just after <addItem> is called
*/
MenuBar.prototype.addItemTransition = function()
{
};

/*
	Function: removeItemTransition 
	A stub function which is called just after <removeItem> or <removeAllItems> is called
*/
MenuBar.prototype.removeItemTransition = function()
{
};


window['SB']['ui']['MenuBar'] = MenuBar;

})();
