var bottoneAttivo=null;
var bottoneSottoAttivo=null;

function startmenu()
{
	i=1;
	trovato=true;
	while(trovato){		
		if (document.getElementById('menu'+i)!=null){			
			document.getElementById('menu'+i).style.display = "none";				
			document.getElementById('imgMenu'+i).src="./img/right.gif";
		}
		else{
			trovato=false;
		}
		i++;
	}	
}
function startsubmenu()
{
	i=1;
	j=1;
	trovato=true;
	while(trovato){		
		if (document.getElementById('menu'+i+'sub'+j)!=null){			
			document.getElementById('menu'+i+'sub'+j).style.display = "none";				
			document.getElementById('imgMenu'+i+'sub'+j).src="./img/right.gif";
		}
		else{
			trovato=false;
		}
		i++;
		j++;
	}	
}

function closemenufunc(menuId){
	if(document.getElementById(menuId).style.display != "none")
	{
		document.getElementById(menuId).style.display = "none";
		if (document.getElementById(menuId).innerHTML!=""){
			prova=new Effect.SlideUp(menuId);
		}
		document.getElementById('imgMenu'+menuId.substring(4,menuId.length)).src="./img/right.gif";	
	}
}
function menufuncInit(menuId,menusubId,superC,idClasse,cat)
{		
	var supCat=1;
	menuId="menu"+String(menuId);	
	if(document.getElementById(menuId).style.display == "none")
	{
		startmenu();
		this.bottoneAttivo=menuId;
		document.getElementById(menuId).style.display = "block";
		if (document.getElementById(menuId).innerHTML!=""){
			prova=new Effect.SlideDown(menuId);
		}
		document.getElementById('imgMenu'+menuId.substring(4,menuId.length)).src="./img/down.gif";
	}
	if (menusubId!=null)
	{		
		menusubId=String(menuId)+"sub"+String(menusubId);
		supCat=0;
		if(document.getElementById(menusubId).style.display == "none")
		{
			startsubmenu();
			this.bottoneSottoAttivo=menusubId;
			document.getElementById(menusubId).style.display = "block";
			if (document.getElementById(menusubId).innerHTML!=""){
				prova=new Effect.SlideDown(menusubId);
			}
			document.getElementById('imgMenu'+menusubId.substring(4,menusubId.length)).src="./img/down.gif";
		}
	}		
	if (cat==null) apriDettaglio((supCat==1)?superC:idClasse, supCat, 0, false);
}
/*
no menu
function menufuncInitB(menuId,menusubId,superC,idClasse,cat)
{		
	var supCat=1;
	menuId="menu"+String(menuId);	
	if(document.getElementById(menuId).style.display == "none")
	{
		startmenu();
		this.bottoneAttivo=menuId;
		document.getElementById(menuId).style.display = "block";
		if (document.getElementById(menuId).innerHTML!=""){
			prova=new Effect.SlideDown(menuId);
		}
		document.getElementById('imgMenu'+menuId.substring(4,menuId.length)).src="./img/down.gif";
	}
	if (menusubId!=null)
	{		
		menusubId=String(menuId)+"sub"+String(menusubId);
		supCat=0;
		if(document.getElementById(menusubId).style.display == "none")
		{
			startsubmenu();
			this.bottoneSottoAttivo=menusubId;
			document.getElementById(menusubId).style.display = "block";
			if (document.getElementById(menusubId).innerHTML!=""){
				prova=new Effect.SlideDown(menusubId);
			}
			document.getElementById('imgMenu'+menusubId.substring(4,menusubId.length)).src="./img/down.gif";
		}
	}		
	if (cat==null) apriDettaglio((supCat==1)?superC:idClasse, supCat, 0, false);
}
*/
/*function menufunc1(menuId)
{	
	if(document.getElementById(menuId).style.display == "none")
	{
		if (this.bottoneAttivo!=null){
			closemenufunc(this.bottoneAttivo);
		}
		else
		{
			startmenu();
		}		
		this.bottoneAttivo=menuId;
		document.getElementById(menuId).style.display = "block";
		if (document.getElementById(menuId).innerHTML!=""){
			prova=new Effect.SlideDown(menuId);
		}
		document.getElementById('imgMenu'+menuId.substring(4,menuId.length)).src="./img/down.gif";	
	}
	else
	{
		if (this.bottoneAttivo!=null){			
			closemenufunc(menuId);
		}else{
			startmenu();
		}
		this.bottoneAttivo=null;
	}	
}*/

function menufunc(menuId,idClasse, superCat, magia)
{	
	/*var bott="";
	if (superCat==1){
		bott=this.bottoneAttivo;
	}else{
		bott=this.bottoneSottoAttivo;
	}*/
	//alert(bott+" "+menuId);
	//alert(this.bottoneSottoAttivo);
	var closeMenu=false;
	if(document.getElementById(menuId).style.display == "none")
	{		
		/*if (bott!=null){
			closemenufunc(bott);
		}*/
		if((this.bottoneAttivo!=null)||(this.bottoneSottoAttivo!=null)){
			if((this.bottoneAttivo!=null)&&(superCat==1)) closemenufunc(this.bottoneAttivo);
			if(this.bottoneSottoAttivo!=null) closemenufunc(this.bottoneSottoAttivo);
		}
		else
		{
			if (superCat==1){
				startmenu();
			}else{
				startsubmenu();
			}				
		}				
		document.getElementById(menuId).style.display = "block";
		if (document.getElementById(menuId).innerHTML!=""){
			prova=new Effect.SlideDown(menuId);
		}
	//	alert(menuId.substring(4,menuId.length));
		document.getElementById('imgMenu'+menuId.substring(4,menuId.length)).src="./img/down.gif";	
		if (superCat==1){
			this.bottoneAttivo=menuId;
		}else{
			this.bottoneSottoAttivo=menuId;
		}
	}
	else
	{		
		if ((this.bottoneAttivo!=null)||(this.bottoneSottoAttivo!=null)){			
			if((this.bottoneAttivo!=null)&&(superCat==1))  closemenufunc(this.bottoneAttivo);
			if(this.bottoneSottoAttivo!=null) closemenufunc(this.bottoneSottoAttivo);
			closemenufunc(menuId);
		}else{
			if (superCat==1){
				startmenu();
			}else{
				startsubmenu();
			}
		}
		if (superCat==1){
			this.bottoneAttivo=null;
			closeMenu=true;
		}else{
			this.bottoneSottoAttivo=null;			
		}
	}	
	//alert(idClasse+superCat+magia);
	apriDettaglio(idClasse, superCat, magia, closeMenu);
}
/*
function menusubfunc(menuId)
{
	if(document.getElementById(menuId).style.display == "none")
	{
		if (this.bottoneSottoAttivo!=null){
			closemenufunc(this.bottoneSottoAttivo);
		}
		else
		{
			startsubmenu();
		}
		document.getElementById(menuId).style.display = "block";
		if (document.getElementById(menuId).innerHTML!=""){
			prova=new Effect.SlideDown(menuId);
		}
		document.getElementById('imgMenu'+menuId.substring(4,menuId.length)).src="./img/down.gif";
	}
	else
	{
		closemenufunc(menuId);		
	}
}*/