var menus = 0;
var arrayMenu=Array();
var currentMenu = null;
var selectedMenu = 0;
var clicked = false;
var intervallo;
var principale=null;
var secondario=null;

///
function selIniziale(p,s){
	if (p){
	principale=findObj(p);
	if (p=="menubaritem5"){
	principale.className="caller_acceso2";
	} else {
	principale.className="caller_acceso";
	}
	if(s){
		secondario=findObj(s);
		secondario.className="menuitem_on";
	}
	};
}
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;
  this.thediv.style.visibility = startstate;
  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 nothing(){
	// dummy function providing a dead link
	// replace with real links
	}

function showMenu(theobj){
	for (var i=1; i<= theobj.numberofmenuitems; i++){
  	 	 var shutdiv =eval( "menuitem"+i+".thediv");
  	 	 shutdiv.style.visibility="hidden";
		 var othercallers =eval( "menuitem"+i+".caller");
		 if(othercallers!=principale){
			 othercallers.className="caller_spento";
		 }
 	 }
 	 theobj.thediv.style.visibility="visible";	
	 theobj.caller.className="caller_acceso";	

	/////

	currentMenu=theobj;
	stopCounting()
	}

function doMenuChoice(m,n) // click a menu item
	{
	clearInterval(intervallo);
	alert("You chose menu "+m+" item "+n);
	//hideAll(0)
	//return false;
	}

function hideSingle(n){
			var shutdiv =currentMenu.thediv;
  			shutdiv.style.visibility="hidden";
		 	var othercallers =currentMenu.caller;	
			if(othercallers!=principale){
			 othercallers.className="caller_spento";
			 currentMenu=null;
			 }
			clearInterval(intervallo);
}

function hideMe(){
	intervallo=setInterval(hideSingle,2000,0);
}

function stopCounting(){
	clearInterval(intervallo);
}

function hideAll(m) {
	//alert('hideAll  '+m);
	var indexarr=m-1;
	for (var i=0; i< menus; i++){
		if(indexarr!=i){
			var shutdiv =	arrayMenu[i].thediv;
  			shutdiv.style.visibility="hidden";
		 	var othercallers =arrayMenu[i].caller;	
			//othercallers.className="caller_spento";
		if(othercallers!=principale){
			 othercallers.className="caller_spento";
			 currentMenu=null;
		 }
		}	
	}

	clearInterval(intervallo);
}
