/**
* @version		$Id: menu.js 6402 2007-01-30 02:08:11Z louis $
* @copyright	Copyright (C) 2005 - 2007 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.
*/

function checkIEBrowser()
{
    var browserName = navigator.appName;
    var browsers = navigator.userAgent.toLowerCase();
    var index = browsers.indexOf("msie");
    if (index != -1)
    {
        var browserVersion = parseFloat(browsers.substring(index + 5, browsers.length));
        if (browserName == "Microsoft Internet Explorer" && browserVersion < 7.0)
            return true;
    }
    return false;
}
        
if (checkIEBrowser())
{
    document.write('<scr'+'ipt type="text/javascript" src="Scripts/MenuHideCombo.js"></scr'+'ipt>');
}

/**
 * JMenu javascript behavior
 *
 * @author		Johan Janssens <johan.janssens@joomla.org>
 * @package		Joomla
 * @since		1.5
 * @version     1.0
 */
var JMenu = new Class({
	initialize: function(el)
	{
		var elements = $ES('li', el);
		var nested = null
		for (var i=0; i<elements.length; i++)
		{
			var element = elements[i];

            if (checkIEBrowser())
            {
                addEventES(element)
            }
            else
            {
                element.addEvent('mouseover', function(){ this.addClass('hover'); });
			    element.addEvent('mouseout', function(){ this.removeClass('hover'); });
            }

			//find nested UL
			nested = $E('ul', element);
			if(!nested) {
				continue;
			}

			//declare width
			var offsetWidth  = 0;

			//find longest child
			for (k=0; k < nested.childNodes.length; k++) {
				var node  = nested.childNodes[k]
				if (node.nodeName == "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 == "LI") {
					$(node).setStyle('width', offsetWidth+'px');
				}
			}

			$(nested).setStyle('width', offsetWidth+'px');
		}
	}
});

//For IE6 - Background flicker fix
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}


document.menu = null
window.addEvent('load', function(){
	element = $('CatMenuTop')
	if(element != null && !element.hasClass('disabled')) {
	    if (checkIEBrowser())
	        comboArray = getAllCombo(document);
		var menu = new JMenu(element)
		document.menu = menu
	}
});


// **************************************
//LEFT NAVIGATION MENU
// **************************************

//SuckerTree Vertical Menu 1.1 (Nov 8th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["CatMenuLeftTree"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus(){
for (var i=0; i<menuids.length; i++){
  if(document.getElementById(menuids[i])!=null)
  {
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
    ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
		if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
			ultags[t].style.left=String(parseInt(ultags[t].parentNode.offsetWidth)+24)+"px" //dynamically position first level submenus to be width of main menu item
		else //else if this is a sub level submenu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.display="block"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
		for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
		ultags[t].style.visibility="visible"
		ultags[t].style.display="none"
		}
	}
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus)




