

function menu(id,level,nextlevel) {	
	//Nascondo tutti i figli prima di visualizzarne di nuovi		
	hiddenChild(id,level,nextlevel);		
}

function hiddenChild(id,level,nextlevel) {	
	//Inizializzo	
	fou = document.getElementById('fourth');	
	tir = document.getElementById('third');	
	sec = document.getElementById('second');	
	fir = document.getElementById('first');	
	if(nextlevel=='fourth') {
		if(fou!=null && fou.style.display=='block') {			
			$('#fourth').find("a").removeClass('selezionato');									
			$('#fourth').fadeOut(500,function(){
				$("#fourth").find("span").hide();
				showChild(id,level,nextlevel);
			});		
		}
		else {
			showChild(id,level,nextlevel);
		}
	}
	if(nextlevel=='third') {
		if(fou!=null && fou.style.display=='block') {
			$('#fourth').find("a").removeClass('selezionato');
			$('#fourth').fadeOut(500,function(){
				$("#fourth").find("span").hide();
				if(tir!= null && tir.style.display=='block') {
					$('#third').find("a").removeClass('selezionato');
					$('#third').fadeOut(1000,function(){
						$("#third").find("span").hide();
						showChild(id,level,nextlevel);
					});		
				}
			});		
		}
		else if(tir!= null && tir.style.display=='block') {
			$('#third').find("a").removeClass('selezionato');
			$('#third').fadeOut(500,function(){
				$("#third").find("span").hide();
				showChild(id,level,nextlevel);
			});		
		}
		else {
			showChild(id,level,nextlevel);
		}
	}
	
	if(nextlevel=='second') {
		if(fou!=null && fou.style.display=='block') {
			$('#fourth').find("a").removeClass('selezionato');
			$('#fourth').fadeOut(500,function(){
				$("#fourth").find("span").hide();
				if(tir!= null && tir.style.display=='block') {
					$('#third').find("a").removeClass('selezionato');
					$('#third').fadeOut(500,function(){
						$("#third").find("span").hide();
						if(sec!=null && sec.style.display=='block') {
							$('#second').find("a").removeClass('selezionato');
							$('#second').fadeOut(500,function(){
								$("#second").find("span").hide();
								showChild(id,level,nextlevel);
							});		
						}
					});		
				}
			});		
		}
		else if(tir!= null && tir.style.display=='block') {
			$('#third').find("a").removeClass('selezionato');
			$('#third').fadeOut(500,function(){
				$("#third").find("span").hide();
				if(sec!=null && sec.style.display=='block') {
					$('#second').find("a").removeClass('selezionato');
					$('#second').fadeOut(500,function(){
						$("#second").find("span").hide();
						showChild(id,level,nextlevel);
					});		
				}
			});		
		}
		else if(sec!=null && sec.style.display=='block') {
			$('#second').find("a").removeClass('selezionato');
			$('#second').fadeOut(500,function(){
				$("#second").find("span").hide();
				showChild(id,level,nextlevel);
			});		
		}
		else {
			showChild(id,level,nextlevel);
		}
	}
	
	if(nextlevel=='first') { 
		if(fou!=null && fou.style.display=='block') {
			$('#fourth').find("a").removeClass('selezionato');
			$('#fourth').fadeOut(500,function(){
				$("#fourth").find("span").hide();
				if(tir!= null && tir.style.display=='block') {
					$('#third').find("a").removeClass('selezionato');
					$('#third').fadeOut(500,function(){
						$("#third").find("span").hide();
						if(sec!=null && sec.style.display=='block') {
							$('#second').find("a").removeClass('selezionato');
							$('#second').fadeOut(500,function(){
								$("#second").find("span").hide();
								if(fir!=null && fir.style.display=='block') {
									$('#first').find("a").removeClass('selezionato');
									$('#first').fadeOut(500,function(){
										$("#first").find("span").hide();
										showChild(id,level,nextlevel);
									});		
								}
							});		
						}
					});		
				}
			});		
		}
		else if(tir!= null && tir.style.display=='block') {
			$('#third').find("a").removeClass('selezionato');
			$('#third').fadeOut(500,function(){
				$("#third").find("span").hide();
				if(sec!=null && sec.style.display=='block') {
					$('#second').find("a").removeClass('selezionato');
					$('#second').fadeOut(500,function(){
						$("#second").find("span").hide();
						if(fir!=null && fir.style.display=='block') {
							$('#first').find("a").removeClass('selezionato');
							$('#first').fadeOut(500,function(){
								$("#first").find("span").hide();
								showChild(id,level,nextlevel);
							});		
						}
					});		
				}
			});		
		}
		else if(sec!=null && sec.style.display=='block') {
			$('#second').find("a").removeClass('selezionato');
			$('#second').fadeOut(500,function(){
				$("#second").find("span").hide();
				if(fir!=null && fir.style.display=='block') {
					$('#first').find("a").removeClass('selezionato');
					$('#first').fadeOut(500,function(){
						$("#first").find("span").hide();
						showChild(id,level,nextlevel);
					});		
				}
			});		
		}
		else if(fir!=null && fir.style.display=='block') {
			$('#first').find("a").removeClass('selezionato');
			$('#first').fadeOut(500,function(){
				$("#first").find("span").hide();
				showChild(id,level,nextlevel);
			});		
		}
		else {
			showChild(id,level,nextlevel);
		}
	}				
}

function showChild(id,level,nextlevel) {	
	if(level!='') {
		$('#'+level).find("a").removeClass('selezionato');
		$('#'+id).addClass('selezionato');		
	}
	if(level!='') {	
		//Mostra tutti gli span selezionati
		$("#"+nextlevel).find("#"+id).show();
		
		//Mostra il livello selezionato che contiene gli span
		$('#'+nextlevel).fadeIn(500,function(){});		
	}
	else {
		
		//Mostra tutti gli span selezionati			
		$("#"+nextlevel).find("#"+id).show();
		
		//Mostra il livello selezionato che contiene gli span
		$('#'+nextlevel).fadeIn(500,function(){});		
	}
}

function accendiLink(idName) {	
	$('#top_prodotti').removeClass('attivo');
	$('#top_azienda').removeClass('attivo');
	$('#top_normativa').removeClass('attivo');
	$('#top_download').removeClass('attivo');
	$('#top_lattoneria').removeClass('attivo');
	$('#'+idName).addClass('attivo');
	
}


