//Creazione di un array per ogni menu;
//il nome dell'array deve essere "arMenu" + numero menu
//Ogni Elemento dell'array e composto da:
//- Testo del link; -href del link; -Flag (0 per nessun sottomenu, 1 per link con sottomenu)
//-finestra (3 per aprire una finestra normale senza barra indirizzi ecc., 2 per aprire un documento nella stessa finestra; 1 per aprire una finestra con dimensioni finestraW e finestraH, 0 per aprire una finestra normale);
//-finestraW (largezza della finestra aperta se il campo finestra è 1; 
//-finestraH (altezza della finestra aperta se il campo finestra è 1;
arMenu1 = new Array(
"&gt;Comuni","Home.asp?pg=regione",0,2,0,0,
"&gt;Alloggi","Home.asp?pg=alloggi",0,2,0,0,
"&gt;Aziende","Home.asp?pg=aziende",0,2,0,0,
"&gt;Calcio","Home.asp?pg=calcio",0,2,0,0,
"&gt;Mercatino","Home.asp?pg=mercatino",0,2,0,0,
"&gt;Album fotografico","Home.asp?pg=albumfoto",0,2,0,0,
"&gt;Siciliani nel mondo","Home.asp?pg=emigrati",0,2,0,0,
"&gt;Chiese e Parrocchie","Home.asp?pg=regione",0,2,0,0
)
arMenu2 = new Array(
"&gt;Segnalazione siti","../motore/nwSegnalazione.asp",0,1,670,screen.availHeight,
"&gt;Inserimento azienda","../aziende/nwAzienda.asp",0,1,670,screen.availHeight,
"&gt;Inserimento alloggio","../alloggi/nwAlloggio.asp",0,1,670,screen.availHeight,
"&gt;Messaggi dagli emigrati","../emigrati/nwMessaggio.asp",0,1,670,screen.availHeight,
"&gt;Inserimento mercatino","../mercatino/nwAnnuncio.asp",0,1,670,screen.availHeight,
"&gt;Inviaci una foto","../albumfoto/nwAlbumFoto.html",0,1,670,screen.availHeight
)
arMenu3 = new Array(
"&gt;Chi siamo","Home.asp?pg=chisiamo",0,2,0,0,
"&gt;Progetti","Home.asp?pg=chisiamo",0,2,0,0,
"&gt;Contattaci","Home.asp?pg=chisiamo",0,2,0,0
)


//Browser Utilizzato
NS4=(document.layers) ? true : false;
IE4=(document.all)?true:false;
ver4 = (NS4 || IE4) ? true : false;

function popUp(){return};
function popDown(){return};
areCreated=false;
if (!ver4) event=null;

//Impostazione parametri dei menu
if (ver4) {
if (NS4)
   LarghezzaMenu = 148;
else
   LarghezzaMenu = 133;
secondsVisible = 0.2;
ColoreLink = "#000000";
LinkHover = "#FFFFFF";
if (NS4)
   DimensioneLink = "8pt";
else
   DimensioneLink = "7pt";
LinkWeight = "bold";
LinkStyle = "normal";
LinkFontFamily = "Verdana";
ColoreCella = "#BFC7EF";
if (NS4)
   ColoreCellaAttiva = "#FFFFFF";
else
   ColoreCellaAttiva = "#003399";
DistanzaLinee = "normal";
DimensioneBordoCella = 1;
ColoreBordoCella = "blue"
StileBordoCella = "outset";
imgSrc = "immagine.gif";
imgSiz = 7;
}

//Creazione dei menu
mSecsVis = secondsVisible*1000;

semi = ";";
styleStr = "<STYLE TYPE='text/css'>"
styleStr += ".items {"
styleStr += "width:" + LarghezzaMenu + semi
styleStr += "color:"+ ColoreLink + semi
styleStr += "font-size:"+ DimensioneLink + semi
styleStr += "font-weight:"+ LinkWeight + semi
styleStr += "font-style:"+ LinkStyle + semi
styleStr += "font-family:"+ LinkFontFamily + semi
styleStr += "border-width:" + DimensioneBordoCella + semi
styleStr += "border-color:" + ColoreBordoCella + semi
styleStr += "border-style:" + StileBordoCella + semi
styleStr += "line-height:" + DistanzaLinee + semi
styleStr += "}"
styleStr += "</STYLE>";
 
document.write(styleStr);

//Immagine per indicare la presenza di un sottomenu
imgStr = "<IMG SRC=" + imgSrc + " WIDTH=" + imgSiz + " HEIGHT=" + imgSiz +" BORDER=0 VSPACE=2 ALIGN=RIGHT>"

topCount = 1;
areCreated = false;
isOverMenu = false;
currentMenu = null;
allTimer = null;

function menuSetup(hasParent,lastItem,openCont,openItem) {

	this.menuOver = menuOver;
	this.menuOut = menuOut;

	this.onmouseover = this.menuOver;
	this.onmouseout = this.menuOut;

	this.showIt = showIt;

	this.hideTree = hideTree
	this.hideParents = hideParents;
	this.hideChildren = hideChildren;
	this.hideTop = hideTop;
	
	this.hasChildVisible = false;
	this.isOn = false;
	
	this.hideTimer = null;

	if (hasParent) {
		this.hasParent = true;
		this.parentMenu = openCont;
		this.parentItem = openItem;
		this.parentItem.child = this;
	}
	else {
		this.hasParent = false;
		this.hideSelf = hideSelf;
	}

	if (NS4) {
		this.fullHeight = lastItem.top + lastItem.document.height;
		this.clip.bottom = this.fullHeight;
	}
	else {
	    this.fullHeight = lastItem.style.pixelTop + lastItem.offsetHeight;
		this.showIt(false);
		this.onselectstart = cancelSelect;
	}
}

function itemSetup(arrayPointer,whichArray) {

	this.itemOver = itemOver;
	this.itemOut = itemOut;
	this.onmouseover = this.itemOver;
	this.onmouseout = this.itemOut;

	this.dispText = whichArray[arrayPointer];
	this.linkText = whichArray[arrayPointer + 1];
	this.hasMore = whichArray[arrayPointer + 2];
   //se questo campo è uno bisogna aprire una finestra personalizzata con le dimensioni
   //prese dai due campi finestraW e finestraH
	this.finestra = whichArray[arrayPointer + 3];
	this.finestraW = whichArray[arrayPointer + 4];
    this.finestraH = whichArray[arrayPointer + 5];
	
	if (this.linkText.length > 0) {
		this.linkIt = linkIt;
		if (NS4) {
			this.onfocus = this.linkIt;
		}
		else {
			this.onclick = this.linkIt;
			this.style.cursor = "hand";
		}
	}
      
	if (this.hasMore) {
		htmStr = imgStr + this.dispText;
	}
	else {
		htmStr = this.dispText;
	}

	if (NS4) {
		layStr = "<SPAN CLASS=items>" + htmStr+ "</SPAN>";
		this.document.write(layStr);
		this.document.close();

		this.bgColor = ColoreCella;
		this.clip.right = LarghezzaMenu;
		this.visibility = "inherit";
		this.container = this.parentLayer;

		if (arrayPointer == 0) {
			this.top = 0;
		}
		else {
			this.top = this.prevItem.top + this.prevItem.document.height - DimensioneBordoCella;
		}
		this.left = 0;
	}
	else {
		this.className = "items";
		this.style.padding = 3;
		this.innerHTML = htmStr;

		this.style.backgroundColor = ColoreCella; 
		this.container = this.offsetParent;

		if (arrayPointer == 0) {
			this.style.pixelTop = 0;
		}
		else {
			this.style.pixelTop = this.prevItem.style.pixelTop + this.prevItem.offsetHeight - DimensioneBordoCella;
		}
		this.style.pixelLeft = 0;
	}
}

function makeElement(whichEl,whichContainer) {
 if (arguments.length==1)
  whichContainer = (NS4) ? window: document.body;
if (NS4) {
  if (arguments.length==1){
   eval(whichEl + "= new Layer(LarghezzaMenu )");
  }
  else {
  eval(whichEl + "= new Layer(LarghezzaMenu, whichContainer )");
  }
 }
 else {
  elStr = "<DIV ID=" + whichEl + " STYLE='position:absolute;left:0;top:0'></DIV>";
  whichContainer.insertAdjacentHTML("BeforeEnd",elStr);
 }

 return eval(whichEl);
}


function makeTop() {
	while(eval("window.arMenu" + topCount)) {
		topArray = eval("arMenu" + topCount);
		topName = "elMenu" + topCount;

		topMenu = makeElement(topName);
    	topMenu.setup = menuSetup;

		topItemCount = 0;
		for (i=0; i<topArray.length; i+=6) {
			topItemCount++;
			topItemName = "item" + topCount + "_" + topItemCount;
			topItem = makeElement(topItemName,topMenu);

			if (topItemCount >1)
				topItem.prevItem = eval("item" + topCount + "_" + (topItemCount-1));
			topItem.setup = itemSetup;
			topItem.setup(i,topArray);
		}
		topMenu.setup(false,topItem);
		topCount++
	}
	areCreated = true;
}

function linkIt() {
    var w
    //finestra con le dimensioni passate
	if (this.finestra==1){
		w=window.open(this.linkText,'nuova','toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars=1,screenX=0,screenY=0,left=0,top=0');
        w.resizeTo(this.finestraW,this.finestraH);
    }
	else{
	    if (this.finestra==2)
          //nuovo documento nella stessa finestra
   		   window.document.location=this.linkText;
	    else
  	       if (this.finestra==3)
              //finestra normale senza barraindirizzi ecc.
   		       window.open(this.linkText,'nuova','toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars=1,screenX=0,screenY=0,left=0,top=0');
	       else
		      //finestra normale
               window.open(this.linkText,'nuovafinestra');
    }
}

function showIt(on) {
	if (NS4) {this.visibility = (on) ? "show" : "hide"}
		else {this.style.visibility = (on) ? "visible" : "hidden"}
}

function popUp(menuName,e,xPos,yPos){
	if (!areCreated) return;
	hideAll();
	currentMenu = eval(menuName);
   //Posizionamento menu
	if (NS4)
		{screen_w = window.innerWidth;}
	else
		{screen_w = document.body.clientWidth;}
	if (screen_w > 596)
		{left_offset = (screen_w - 596)/2;}
	else
		{
		left_offset = 0;
		}
    if (NS4)
	    {
	    currentMenu.left = xPos + left_offset;
	    currentMenu.top = yPos;
		}
	else
	    { 
	    currentMenu.style.pixelLeft = xPos + left_offset;
	    currentMenu.style.pixelTop = yPos;
		}
    currentMenu.isOn = true;
	currentMenu.showIt(true);
}

function popDown(menuName){ 
	if (!areCreated) return;
	whichEl = eval(menuName);
	whichEl.isOn = false;
	whichEl.hideTop();
}

function menuOver() {
	this.isOn = true;
	isOverMenu = true;
	currentMenu = this;
	if (this.hideTimer) clearTimeout(this.hideTimer);
}

function menuOut() {
	if (IE4 && event.srcElement.contains(event.toElement)) return;
	this.isOn = false;
	isOverMenu = false;
	if (IE4) allTimer = setTimeout("currentMenu.hideTree()",10); 
}

function itemOver(){
	if (IE4 && event.srcElement.tagName == "IMG") return;

	if (NS4) {
		this.bgColor = ColoreCellaAttiva;
	}
	else {
		this.style.backgroundColor = ColoreCellaAttiva;
		this.style.color = LinkHover;
	}
	
	if (this.container.hasChildVisible) {
		this.container.hideChildren(this);
	}            

	if(this.hasMore) {
		this.container.hasChildVisible = true;
		this.container.visibleChild = this.child;
		this.child.showIt(true);
	}
}


function itemOut() {
    if (IE4 && (event.srcElement.contains(event.toElement)
     || (event.fromElement.tagName=="IMG" && event.toElement.contains(event.fromElement))))
        return;

	if (NS4) {
		this.bgColor = ColoreCella;
		if (!isOverMenu) {
			allTimer = setTimeout("currentMenu.hideTree()",10);
		}
	}
	else {
		this.style.backgroundColor = ColoreCella;
		this.style.color = ColoreLink;
	}
}

function hideAll() {
	for(i=1; i<topCount; i++) {
		temp = eval("elMenu" + i);
		temp.isOn = false;
		if (temp.hasChildVisible) temp.hideChildren();
		temp.showIt(false);
	}	
}

function hideTree() { 
	allTimer = null;
	if (isOverMenu) return;
	if (this.hasChildVisible) {
		this.hideChildren();
	}
	this.hideParents();
}

function hideChildren(item) {
	if (this.visibleChild.hasChildVisible) {
		this.visibleChild.visibleChild.showIt(false);
		this.visibleChild.hasChildVisible = false;
	}

	if (!this.isOn || !item.hasMore || this.visibleChild != this.child) {
		this.visibleChild.showIt(false);
		this.hasChildVisible = false;
	}
}

function hideParents() {     

	if (this.hasParent) {
		this.showIt(false);
		if (this.parentMenu.hasParent) {
			this.parentMenu.isOn = false;		
			this.parentMenu.showIt(false);
			this.parentMenu.parentMenu.isOn = false;
			whichEl = this.parentMenu.parentMenu
		}
		else {
			this.parentMenu.isOn = false;
			whichEl = this.parentMenu;
		}
	}
	else {
		whichEl = this;
	}

	whichEl.hideTop();
}

function hideTop() {
	whichEl = this;
	this.hideTimer = setTimeout("whichEl.hideSelf()",mSecsVis);
}

function hideSelf() {
	this.hideTimer = null;
	if (!this.isOn && !isOverMenu) { 
		this.showIt(false);
	}
}

function cancelSelect(){return false}

window.onload = makeTop;
