var load_method = (window.ie ? 'load' : 'domready');

window.addEvent('avvia_menu', function(){
//---------------------------------------------------------
if(HB_DEBUG) alert('inizializzo il menù');
/*
// VARIABILI PER I LIVELLI
var MIN_LEVEL=HB_MIN_LEVEL;		//primo livello
var MAX_LEVEL=HB_MAX_LEVEL;		//ultimo livello
var home_position=HB_HOME;		//true se siamo in home page di sezione

var CHECK_BACK=true;			// se attiva, fa il controllo del sottomenù padre;

////////////////////////////////////////////////////////////////////////////////////////////////////
//
// oggetto che gestisce lo SCORRIMENTO VERTICALE dei livelli
// sono 4 (QUATTRO) livelli, quindi fisso staticamente tutte le caratteristiche
//
////////////////////////////////////////////////////////////////////////////////////////////////////

// FLAG e VARIABILI dell'oggetto
var vertTransitionObj = new Class({

initialize: function(){
	
	// flag e variabili dell'oggetto
	this.frontal=$('scorri_menu_vert');			// div forntale
	this.scroller=$('scroller_box');			// div contenuti
	this.status=MIN_LEVEL;							// stato (iniziale) del div frontale
	this.vertical_gap=28;					// scarto tra una posizione verticale e l'altro

	// Transizione BOX FRONTALE
	this.fx=new Fx.Styles(this.frontal, {wait: false});
	this.fx.options.duration=800;
	this.fx.options.transition=Fx.Transitions.Expo.easeOut;
//	this.fx.options.transition=Fx.Transitions.Elastic.easeOut;
//	this.fx.options.transition=Fx.Transitions.Cubic.easeOut;
}

});

// METODI
vertTransitionObj.implement({

	// MUOVI DESTRA
	moveRight: function(){
		if(this.status!=MAX_LEVEL){
			CHECK_BACK=false;
			this.status++;
			this.fx.start({'top': 8+(-1)*(this.status-1)*this.vertical_gap,'left': 0});
		}
	},

	// MUOVI DESTRA
	goRight: function(){
		//alert('vado avanti');
		if(this.status!=MAX_LEVEL){
			this.status++;
			this.frontal.style.top=(8+(-1)*(this.status-1)*this.vertical_gap)+'px';
		}
	},

	// MUOVI SINISTRA
	moveLeft: function(){
		if(this.status!=MIN_LEVEL){
			if (this.status!=2) this.checkParent(sezione,cliccato);
			this.status--;
			this.fx.start({'top': 8+(-1)*this.vertical_gap*(this.status-1),'left': 0});
			if(this.status<=2) CHECK_BACK=false;		//variabile ausiliara: devo controllare le sottovoci padre? SI o NO
			// se torno nella prima posizione allora disattivo il bottone BACK del menù
		}
	},

	checkParent: function(liv,click){
		if((!home_position)&&(CHECK_BACK)){
			//alert('chekko! '+liv+' '+ click);
			found=false;
			var no_link=0;
			var menu_to_appear=0;
			var liv_to_appear=0;
			while((!found)&&(liv>1)){
				//alert('guardo div di nome livello_'+liv+' cliccato dal "enza link n°"'+click);
				ID='livello_'+liv;
				arrayUL=$(ID).getElementsByTagName('ul');
				//alert(arrayUL.length);
				for(u=0;u<arrayUL.length;u++){
					//alert(' controllo '+arrayUL[u].innerHTML);
					arrayLI=arrayUL[u].getElementsByTagName('li');
					for(l=0;l<arrayLI.length;l++){
						if(arrayLI[l].firstChild.tagName!='A'){
							no_link++;
							//alert('trovato uno: '+arrayLI[l].innerHTML);
							if(no_link==click) {
								to_appear=u;
								liv_to_appear=liv-1;
								//alert('EUREKA!');
								//alert(liv);
								tuttiUL[liv_to_appear].hideAll();
								tuttiUL[liv_to_appear].show(to_appear);
							}
						}
					}
				}
				found=true;
			}
		}
	}

});

//////////////////////////////////////////////////
// OGGETTO CHE GESTISCE I LISTITEM
//////////////////////////////////////////////////

// FLAG e VARIABILI dell'oggetto
var itemOject = new Class({

initialize: function(list_item){
	this.link=list_item.getFirst;
	this.scorri=(list_item.firstChild.tagName=='A')?'NO':'SI';
	this.div_ID=list_item.parentNode.parentNode.id;
	var temp=this.div_ID.split('_');
	this.livello=temp[1];
	this.mostra_num=0;
	this.elemento=list_item;
	// quando creo l'oggetto imposto lo stile cursor:pointer
	this.elemento.style.cursor='pointer';
}

});

// METODI
itemOject.implement({

	// MUOVI DESTRA
	debug: function(){
		$('debug').innerHTML+='livello: '+this.livello+', nome_div:'+this.div_ID+', scorre ?:'+this.scorri+' mostra quale ?:'+this.mostra_num+'<br/>';
		//$('debug').innerHTML+=this.link+'<br/>';
	}
});

//////////////////////////////////////////////////////////////
// OGGETTO CHE GESTISCE I LIVELLI
// USATO POI PER FARE SCOMPARIRE O APPARIRE UN SOTTOMENU
//////////////////////////////////////////////////////////////
var livelloOject = new Class({

initialize: function(num){
	this.nascosto='NO';
	this.ID='livello_'+num;
	this.UL=$(this.ID).getElementsByTagName('ul');
	this.num_sottomenu=this.UL.length;
}

});

// METODI
livelloOject.implement({
	
// nasconde tutti i sottomenù di un livello
	hideAll: function(){
		for(i=0;i<this.UL.length;i++){
			this.UL[i].style.display='none';
		}
	},
// mostra un determinato sottomenù passato come argomento
	show: function(one){
		this.hideAll();
		for(i=0;i<this.UL.length;i++){
			if(i==one)
			this.UL[i].style.display='block';
		}
	},

	// DEGUB
	debug: function(){
		$('debug').innerHTML+=this.UL.length+'<br/>';
	}
});

//
////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////
//
// ASSEGNO AD OGNI VOCE DEL MENU', LE OPERAZIONI DA ESEGUIRE
//
// CREO UN OGGETTO iltemObject per ogni voce dei vari menù
// creo e inserisco in un array di oggetti per la sola comodità di
// scorrerlo e assegnargli delle proprietà


var tuttiLI=new Array();
li=$$('#scorri_menu_vert li');
li.each(function(element){
	tuttiLI.push(new itemOject(element));
	element.addEvent('mouseover',function(){
		if (element.getProperty('class')!='selected') this.style.color='#4F2728';
		//alert(element.getProperty('class')!='selected');
	});

	element.addEvent('mouseout',function(){
		if (element.getProperty('class')!='selected') this.style.color='white';
	});

});


li_a=$$('#scorri_menu_vert a');
li_a.each(function(element){

	element.addEvent('mouseenter',function(){
		if(this.getParent().getProperty('class')!='selected') this.style.color='#4F2728';
	});

	element.addEvent('mouseleave',function(){
		if(this.getParent().getProperty('class')!='selected') this.style.color='white';
	});
});

// CREO UN OGGETTO livelloOject per ogni voce dei vari menù
// creo e inserisco in un array di oggetti per la sola comodità di
// scorrerlo e assegnargli delle proprietà
var tuttiUL=Array();
for(i=MIN_LEVEL;i<=MAX_LEVEL;i++){
	tuttiUL.push(new livelloOject(i));
}

// ciclo che mi serve per definire quale menù deve mostrare una voce senza link
lev=1;
quanti=0;
tuttiLI.each(function(element){
	if (lev==element.livello){
		if(element.scorri=='SI'){
			quanti++;
			element.mostra_num=quanti;
		}
	} else {
		lev++;
		quanti=0;
	}
});


// ASSEGNO LE AZIONI AL CLICK delle voci senza link
// essendo i livelli e i sottomenù contenuti in array, devo ricordarmi che gli indici vanno decrementati di 1
tuttiLI.each(function(element){
	if(element.scorri=='SI'){
		element.elemento.addEvent('click',function(){
			num_lev=element.livello;
			num_men=element.mostra_num;		// elemento.livello indica l'elemento corrente, quindi dovendo indicare il prossimo livello, non lo decremento
			num_lev++;						// a fini di debug
			num_men--;						// questo valore è da decrementare (indici array)
			//alert('mostro il menù '+element.mostra_num+' del sottomenù '+num);
			//alert(element.livello+' '+num_men);
			tuttiUL[element.livello].hideAll();
			tuttiUL[element.livello].show(num_men);
			menuScorVert.moveRight();
			//$('debug').innerHTML='mostro livello '+(num_lev)+' e mostro il sottomenu '+element.mostra_num;
		});
	}
});

// inizializzo l'oggetto che muove a destra e a sinistra
var menuScorVert = new vertTransitionObj();

//
//////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////
// ASSEGNO LE PRORPIETA' DI SCORRIMENTO AL BOTTONE CHE
// FA TORNARE INDIETRO IL MENU
//
//////////////////////////////////////////////////////////////
/*
back_buttons=$$('#scorri_menu_vert img');
back_buttons.each(function(element){
	element.addEvent('click',function(){
		menuScorVert.moveLeft();
	});
	element.addEvent('mouseenter',function(){
		element.src=HB_PATH+'images/menu_back_on.gif';
	});
	element.addEvent('mouseleave',function(){
		element.src=HB_PATH+'images/menu_back_off.gif';
	});
});
*/ 
	/*
if($('ico_back')){
	$('ico_back').addEvent('click',function(e){
		e=new Event(e).stop();
		menuScorVert.moveLeft();
	});
}
//
//////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////////////////////////////
//
//      INIZIALIZZAZIONE MENU QUANDO NON SIAMO IN HOME DI SEZIONE
//
// SE NON SONO IN HOME PAGE DI SEZIONE, DEVO INZIALIZZARE IL MENU' ALLA POSIZIONE CORRENTE
//
//////////////////////////////////////////////////////////////////////////////////////////


var sezione=HB_MENU_LIVELLO-1;		//numero che mi dice in quale sezione siamo
var sottomenu=HB_MENU_PADRE-1;		//numero che mi dice quale padre lo ha aperto
var cliccato=HB_MENU_PADRE;

// questo ciclo mi mostra il sottomenù dove appare il link relativo alla pagina
// N.B. !!!!!
// ho aggiunto la condizione su "sottomenu" perchè ci sono casi in cui abbiamo
// il menù al primo livello e non siamo nella home page di sezione
if((!home_position)&&(sottomenu!=-1)){
	tuttiUL[sezione].hideAll();
	tuttiUL[sezione].show(sottomenu);
	//alert('sottomeù: '+sottomenu+' -- sezione: '+sezione);
	for(i=0;i<sezione;i++){
		menuScorVert.goRight();
	}
}
FINE COMMENTO 17/10/2008

*/
//
//////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////
//
// EVENTI PER IL MENU'
//
//////////////////////////////////////////////////////////////////////////////////////////

var heightMenuChange = new Fx.Style('menu', 'height', {
	duration:1000,
	wait: false,
	transition: Fx.Transitions.Expo.easeOut
	});

window.addEvent('mostra_menu',function(){
	if(home_position) heightMenuChange.start(28);
});

//////////////////////////////////////////////////////////////////////////////////////////
//
// Evidenziazione del percorso fatto
//
//////////////////////////////////////////////////////////////////////////////////////////
/*
livello=0;

//alert(window.location);
tuttiLI.each(function(element){
	if (element.scorri=='NO'){
		//alert(element.elemento.getElement('a').getProperty('href'));
		if(window.location==element.elemento.getElement('a').getProperty('href')){
			element.elemento.setProperty('class','selected');
			element.elemento.getElement('a').setProperty('href','#');
			livello=element.livello;
		}
	}
});

while(livello>1){
	posizione_sottomenu=-1;
	array_sottomenu=tuttiUL[livello-1].UL;
	for(i=0;i<array_sottomenu.length;i++){
		//if (array_sottomenu[i].getElements('li[class=selected]')!='')
		LiElement=array_sottomenu[i].getElementsByTagName('li');
		for(key=0;key<LiElement.length;key++){
			if(LiElement[key].className.indexOf('selected')=='0'){
			posizione_sottomenu=i;
			//alert(posizione_sottomenu);
			//alert(LiElement[key].innerHTML+' ####### '+LiElement[key].className.indexOf('selected'));
			}
		}
	}
	up_lev=livello-1;
	i=-1;
	$('livello_'+up_lev).getElements('li').each(function(element){
		if(element.getElement('a')==null) i++;
		if(i==posizione_sottomenu) {
			element.setProperty('class','selected');
			//alert(element.innerHTML);
			i++;
		}
	});
	//alert(livello);
	//alert(--livello);
	livello--;
}
FINE COMMENTO 17/10/2008

*/


//////////////////////////////////////////////////////////////////////////////////////////
//
// MENU' DELLA LINGUA
//
//////////////////////////////////////////////////////////////////////////////////////////

var li_lingua=$$('#menu_lingua li');

li_lingua.each(function(element,value){
	element.addEvent('mouseover',function(){
		this.addClass('selected');
	});

	element.addEvent('mouseout',function(){
		this.removeClass('selected');
	});

	if(value==0){
		element.style.paddingTop='0px';
	}

	if(value==(li_lingua.length-1)){
		element.style.border='none';
	}

});

/*var x=$E('ul','menu_lingua');
x.setProperty('id', 'lingua_ul');
var H_open=x.getSize().size.y;
x.style.height='0px';
$('menu_lingua').style.zIndex='1';
var languages_fx=new Fx.Style('lingua_ul', 'height', {transition: Fx.Transitions.Expo.easeOut,duration:500,wait: false});

$('menu_lingua').addEvent('mouseover',function(){
	languages_fx.start(H_open);
});

$('menu_lingua').addEvent('mouseout',function(){
	languages_fx.start(0);
});
*/

//Menu verticale sport

if($('menu_verticale')){




	window.menu_link=$$('.apri_sottomenu');

	menu_link.each(function(element){
		element.aperto=false;
		element.altezza=$(element.getElement('a').getProperty('rel')).getSize().size.y;
		element.fx=new Fx.Styles(element.getElement('a').getProperty('rel'),{
			duration: 300,
			transition: Fx.Transitions.linear,
			onComplete: function(){
				(function(){if(!element.aperto) element.fx.set({'height':0});}).delay(400);
			}
		});
		element.fx.set({'margin-top':0,'height':0});
		element.addEvent('click',function(){
			element.aperto=true;
			element.fx.start({'height':element.altezza});
			menu_link.each(function(other_element){
				if(other_element!=element) other_element.fireEvent('close');
			});
		});
		element.addEvent('close',function(){
			element.aperto=false;
			(function(){
				if(!element.aperto) element.fx.start({'height':0});
			}).delay(50);
		});
	});
}

//Fine menu verticale sport


//---------------------------------------------------------
});