Function.prototype.setScope = function(scope) {
	var f = this;
	return function() {
		f.apply(scope);
	}
}

document.getElementsByClassName = function(searchClass,tag,node){
	var p = function(){
		if([].push)return function(a,b){a.push(b)};
		return function(a,b){a[a.length]=b}
	}();

	node = node || document;
	tag = tag || '*';

	if(document.evaluate){
		var xpr = document.evaluate([".//",tag,"[contains(concat(' ',@class,' '),' ",searchClass," ')]"].join(''),node, null, 0, null),
		t = true,
		els = new Array();
		while(t=xpr.iterateNext()){
			p(els,t);
		}
		return els;
	}


	var els = node.getElementsByTagName(tag),
	pattern = new RegExp(["(^|\\s)",searchClass,"(\\s|$)"].join('')), 
	ce = new Array();

	for (var i = 0, max = els.length; i < max; i++) {
		if(pattern.test(els[i].className))
			p(ce,els[i]);
	}
	return ce;
}

function init_js_menu(){

var voceMenu=function(list_item){
	this.voce=list_item;
	this.classe=this.voce.className;
	this.sottomenu=document.getElementById('js_sottomenu_'+this.voce.getAttribute('rel'));
	this.selected=false;
	//alert(this.voce.getAttribute('rel'));

	this.evidenziaOn=(function(){
		return this.voce.className=this.classe+' hover';
	}).setScope(this);

	this.evidenziaOff=(function(){
		return this.voce.className=this.classe;
	}).setScope(this);

	this.voce.onmouseover=(function(){
		this.sottomenu.style.display='block';
		this.evidenziaOn();
	}).setScope(this);
	this.voce.onmouseout=(function(){
		this.sottomenu.style.display='none';
		this.evidenziaOff();
	}).setScope(this);

	this.sottomenu.onmouseover=(function(){
		this.sottomenu.style.display='block';
		this.evidenziaOn();
	}).setScope(this);
	this.sottomenu.onmouseout=(function(){
		this.sottomenu.style.display='none';
		this.evidenziaOff();
	}).setScope(this);
};



var JS_MENUS = document.getElementsByClassName('menu_principale');
for(var c = 0; c < JS_MENUS.length ; c++){
	JS_MENU = JS_MENUS[c];
	var voci_principali = JS_MENU.getElementsByTagName('li');
	for(var i=0;i<voci_principali.length;i++){
	if(voci_principali[i].className.indexOf('voce-principale')>=0){
		if(voci_principali[i].getElementsByTagName('A')[0]) {
			null;
		} else {
			new voceMenu(voci_principali[i]);
		}
	}
}
}
//var JS_MENU=document.getElementById('menu_principale');
//var voci_principali = JS_MENU.getElementsByTagName('li');

/*
for(var i=0;i<voci_principali.length;i++){
	if(voci_principali[i].className.indexOf('voce-principale')>=0){
		if(voci_principali[i].getElementsByTagName('A')[0]) {
			null;
		} else {
			new voceMenu(voci_principali[i]);
		}
	}
}
*/

}