/*
     Initialize and render the MenuBar when its elements are ready 
     to be scripted.
*/	

InitMenu = function() {
	
	
	YAHOO.util.Event.onContentReady("menu_bar", function () {
        try {
		
	    /*
	         Instantiate a Menu.  The first argument passed to the 
	         constructor is the id of the element in the DOM that represents 
	         the Menu instance.
	    */	    
	    oMenuBar = new YAHOO.widget.MenuBar("menu_bar", { 
	                                                autosubmenudisplay: true, 
	                                                hidedelay: 750, 
	                                                lazyload: true,
	                                                minscrollheight: (window.innerHeight - 25)
	     });
	    
	    
	    /*
	         Call the "render" method with no arguments since the markup for 
	         this Menu instance already exists in the DOM.
	    */

	  
	    oMenuBar.render();
	   
		positionMainItems();
        } catch(e) {}
	            
	});

	
}

positionMainItems = function(){    	  
	try {		
		var iWidth 	= 0;//will contain the total width of all main menu items
		var aWidth 	= 999;
		var iFills	= $$('#menu_bar li.li_fill');//collection of list items with class li_fill
		
		//loop through main menu items to get the total width
		$$('#menu_bar li.yuimenubaritem').each(function(obj){	
			var obj = $(obj);
			iWidth += obj.getWidth();
		}); 
		
		//now calculate the new width of the 'fill' list items
		var nWidth = parseInt((aWidth - iWidth) / iFills.length);
		
		//loop through 'fill' list items an set new width	
		iFills.each(function(obj){
			var obj = $(obj);    		
			obj.setStyle({
				width: nWidth + 'px'
			});
		}); 
	} catch(e) {} 	
}