/***********************
Author:Gianfranco Todini;
************************/
sfHover = function() {
	var arg=sfHover.arguments;
	menuId = arg[0];
	var sfEls = document.getElementById(menuId).getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=(this.className.length>0? " ": "") + "sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
		}
	}
}

Menu_Init = function() {
	var arg=Menu_Init.arguments;
	menuId = arg[0];
	var mcEls = document.getElementById(menuId).getElementsByTagName("A");
	for (var i=0; i<mcEls.length; i++) {
		mcEls[i].onfocus=function() {
			this.className+=(this.className.length>0? " ": "") + "sffocus"; //a:focus
			var node = this.parentNode;
			node.className+=(node.className.length>0? " ": "") + "sfhover"; //li < a:focus
			for (n=0;n<menuLevels;n++){
				node = node.parentNode.parentNode;
				if (node && node.nodeName=="LI"){
					node.className += (node.className.length>0? " ": "") + "sfhover"; //li < a:focus
					if (node.firstChild.nodeName=="A") node.firstChild.className+=(node.firstChild.className.length>0? " ": "") + "sffocus"; //a:focus
				}else{
					break;
				}
			}
		}
		mcEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp("( ?|^)sffocus\\b"), "");
			var node = this.parentNode;
			node.className=node.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
			for (n=0;n<menuLevels;n++){
				node = node.parentNode.parentNode;
				if (node && node.nodeName=="LI"){
					node.className=node.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
					if (node.firstChild.nodeName=="A") node.firstChild.className=node.firstChild.className.replace(new RegExp("( ?|^)sffocus\\b"), "");
				}else{
					break;
				}
			}
		}
	}
}


//Set this variable with the names of the menu id's separated with a comma
//like this we can have N menu's in the same page
var menuIds = "nav1,nav2";
var menuLevels = 15;

function createMenus() {
	var menus = new Array();
	menus = menuIds.split(",");
	for (i=0;i<=menus.length-1;i++) {
		if (document.getElementById(menus[i])) {
			sfHover(menus[i]);
			Menu_Init(menus[i]);
		}else{
			//alert("there is no tag called "+menus[i]);
		}
	}
}

if(window.addEventListener) window.addEventListener('load', createMenus, false); // gecko, safari, konqueror and standard
else if(document.addEventListener) document.addEventListener('load', createMenus, false); // opera 7
else if(window.attachEvent) { // win/ie
	window.attachEvent('onload', createMenus);
} else { // mac/ie5
	if(typeof window.onload == 'function') {
		var existing = onload;
		window.onload = function() {
			existing();
			createMenus();
		}
	} else {
		window.onload = function() {
			createMenus();
		}
	}
}
