/**
* @version		$Id: index.js 14401 2010-01-26 14:10:00Z louis $
* @copyright	Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

/**
 * Joomla! 1.5 Admininstrator index template behvaior
 *
 * @package		Joomla
 * @since		1.5
 * @version  	1.0
 */

 
/**
* @version      $Id: menu.js 14401 2010-01-26 14:10:00Z louis $
* @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
* @license      GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

/**
 * JMenu javascript behavior
 *
 * @package     Joomla
 * @since       1.5
 * @version     1.0
 */
 
var XJMenu = function(el){
	    var elements = el.getElementsByTagName('li');
        var nested = null;
        for (var i=0; i<elements.length; i++)
        {
            var element = elements[i];
			if(element.className != 'separator'){
				element.className ='node';
				element.onmouseover = function(){ this.className = 'node hover'; };
				element.onmouseout = function(){ this.className = 'node';};
			}			

            //find nested UL
			nested = element.firstChild;
			while(nested && nested.nodeName.toUpperCase() != "UL"){
				nested = nested.nextSibling;
			}
            if(!nested) {
                continue;
            }

            //declare width
            var offsetWidth  = 0;

            //find longest child
            for (k=0; k < nested.childNodes.length; k++) {
                var node  = nested.childNodes[k];
				//alert(node.nodeName);
				//return;
                if (node.nodeName.toUpperCase() == "LI")
                    offsetWidth = (offsetWidth >= node.offsetWidth) ? offsetWidth :  node.offsetWidth;
            }

            //match longest child
            for (l=0; l < nested.childNodes.length; l++) {
                var node = nested.childNodes[l];
                if (node.nodeName.toUpperCase() == "LI") {
                	node.style.width = (offsetWidth > 200)? offsetWidth+'px' : "200px";
                }
            }
			//alert(offsetWidth);
            //nested.style.width = offsetWidth+'px';
            nested.style.width = (offsetWidth > 200)? offsetWidth+'px' : "200px";
        }
};

/**
 * 
 * @param idmenu id do elemento HTML contendo os itens d omenu
 * @return
 */
XJMenu.parse = function(idmenu){
	var jmenu 	= null;
	
	var element = document.getElementById(idmenu);
	if(!element.className.indexOf('disabled') >=0) {
		jmenu = new XJMenu(element);
	}
	delete(jmenu);
};


