/* CONFIG */
var menuNavigazione = "menuNavigazione";
var menuTab = "menuTab";

/* SCRIPT */
function closeSub(menu) {
	for (var i=0; i<menu.childNodes.length; i++)
		if (menu.childNodes[i].nodeName.toLowerCase()=="li") {
			li = menu.childNodes[i];
			li.onmouseover = li.onactivate = li.onfocus = function() { if (this.subMenu) this.subMenu.className = this.subMenu.className.replace(/subMenu-off/g,"subMenu-on") };
			li.onmouseout = li.ondeactivate = li.onblur = function() { if (this.subMenu) closeSub(this.subMenu) };
			for (j=0; j<li.childNodes.length; j++)
				if (li.childNodes[j].nodeName.toLowerCase()=="ul" || li.childNodes[j].nodeName.toLowerCase()=="ol") closeSub(li.subMenu = li.childNodes[j]);
		}
	menu.className = menu.className.replace(/\s?subMenu-on/g,"")+" subMenu-off";
}

function menuChange () { 

	var ul=this.parentNode;
	var tag_li_=ul.getElementsByTagName('li');
	var item=0;
	for (k=0; k<tag_li_.length; k++) {
		if ( tag_li_[k] != this )
			tag_li_[k].className = "voceOff";
		else {
			tag_li_[k].className = "voceCorrente" ;
			item = k;
		}
	}
	n_el=0;
	var sibling = ul.nextSibling ;
	while ( sibling ) {
		if (sibling.className=="tab_content") {
			if ( n_el!= item )
				sibling.style.display= "none";
			else {
				sibling.style.display = "block";
			}
			n_el++;
		}
		sibling = sibling.nextSibling;
	}
/*
	var ul=this.parentNode;

	var childs = ul.childNodes;
	var item=0;
	for (var k=0; k < childs.length; k++) {
		if ( childs[k].nodeName.toLowerCase()=="li") {
			if ( childs[k] != this ) {
				childs[k].className = "voceOff";
				item++;
			}
			else {
				childs[k].className = "voceCorrente" ;
				item = k;
			}
		}
	}

	n_el=0;
	var sibling = ul.nextSibling ;
	while ( sibling ) {
		if (sibling.className=="tab_content") {
			if ( n_el!= item )
				sibling.style.display= "none";
			else {
				sibling.style.display = "block";
			}
			n_el++;
		}
		sibling = sibling.nextSibling;
	}
*/
}

/* ON LOAD */
window.onload = function(e) {

	var tags_ = document.getElementsByTagName('ul');
	if ( tags_ ) {

		for( var i = 0; i < tags_.length; i++) {

			if (tags_[i].className==menuNavigazione)
				closeSub( tags_[i] );
			else if ( tags_[i].className == menuTab ) {
				
				var childs = tags_[i].childNodes;
				for (var k=0; k < childs.length; k++) {
					var child = childs[k];
					if ( child.nodeName.toLowerCase()=="li") {
						child.onclick = menuChange ;
					}
				}

			}

		}

	}

}

/*
$(document).ready(function() {

	$("ul").each(function() {
			if (this.className==menuNavigazione)
				closeSub(this);
			else if ( this.className==menuTab ) {
	
				for (var i=0; i<this.childNodes.length; i++) {
					var c = this.childNodes[i];
					if ( c.nodeName.toLowerCase()=="li") {
						c.onclick = menuChange ;
						if ( c.className == "voceCorrente") c.onclick() ;
					}
				}

			}
	});



});

*/
