var menus = 0;
var arrayMenu=Array();
var currentMenu =null;
var selectedMenu = 0;
var clicked = false;
var intervallo;
var principale=null;
var secondario=null;
var menuSecondarioAttivo=null;
var iniziato=false;
///
var trasparente=null;

function inizializza(){
	menuitem1 = new menuObj(4,1,"hidden");
	menuitem2 = new menuObj(4,2,"hidden");
	menuitem3 = new menuObj(4,3,"hidden");
	menuitem4 = new menuObj(4,4,"hidden");
	////
	trasparente=findObj('trasparente');
	
	
}
function selIniziale(p,s){
	inizializza();
	///
	if (p){
	principale=findObj(p);
	principale.className="caller_acceso";
		
	if(s){
		secondario=findObj(s);
		secondario.className="menuitem_on";
		menuSecondarioAttivo=secondario.parentNode;
		var toShow=arrayMenu[s.substr(1,1)-1];
		//showMenu(toShow);
	}
	
	
	
	};
	iniziato=true;
	
}
function menuObj(allitems,thisitem,startstate){ 
  var callname= "menubaritem"+thisitem;
  var divname="menu"+thisitem;  
  this.numberofmenuitems = allitems;
  this.caller = findObj(callname);
  this.thediv = findObj(divname);
  this.thedivname = divname;
  if(this.thediv!=null){
	  this.thediv.style.visibility = startstate;
	  this.thediv.style.display = 'none';
  }
  
  menus++;
  arrayMenu.push(this);
}

function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}




function showTrasparente(){
	trasparente.style.visibility="visible";
	trasparente.style.display="block";	
}
function hideTrasparente(){
	trasparente.style.visibility="hidden";
	trasparente.style.display="none";
}


function showMenu(theobj){
	
	
	for (var i=1; i<= theobj.numberofmenuitems; i++){
  	 	 var shutdiv =eval( "menuitem"+i+".thediv");
		 if(shutdiv!=null){
			 shutdiv.style.visibility="hidden";
		 	shutdiv.style.display="none";
		 }
  	 	 
		 var othercallers =eval( "menuitem"+i+".caller");
		 if(othercallers!=principale){
			 othercallers.className="caller_spento";
		 }
		
 	 }
	 if(theobj.thediv!=null){
		  theobj.thediv.style.visibility="visible";	
	  theobj.thediv.style.display="block";	
	 theobj.caller.className="caller_acceso";	
	 }
	
		 
	
	 
 		 currentMenu=theobj;
	/////
	
	
	stopCounting()
	
	
	/**/

	}
	
	
	
function hideSingle(){
	
	if(currentMenu!=null){
		var shutdiv =currentMenu.thediv;
		if(shutdiv!=null){
			shutdiv.style.visibility="hidden";
			shutdiv.style.display="none";
		}
  		
		var othercallers =currentMenu.caller;	
				
			if(othercallers!=principale){
			 othercallers.className="caller_spento";
			 currentMenu=null;
			 }
			 
	}
			// riaccendiSecondario();
	
			hideTrasparente();
			clearInterval(intervallo);
}
function riaccendiSecondario(){
	if(menuSecondarioAttivo!=null){
		
		menuSecondarioAttivo.style.visibility="visible";
		menuSecondarioAttivo.style.display="block";	
	}
}
function hideMe(){
	clearInterval(intervallo);
	intervallo=setInterval(hideSingle,500,0);
}
function stopCounting(){
	clearInterval(intervallo);
}



