// JScript source code menu Indrenhus

var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
function getRef(id) {
if (isDOM) return document.getElementById(id);
if (isIE4) return document.all[id];
if (isNS4) return document.layers[id];
}
function getSty(id) {
return (isNS4 ? getRef(id) : getRef(id).style);
} 
// Nasconde il timeout
var popTimer = 0;
// Array che mostra le voci menu evidenziate
var litNow = new Array();
function popOver(menuNum, itemNum) {
clearTimeout(popTimer);
hideAllBut(menuNum);
litNow = getTree(menuNum, itemNum);
changeCol(litNow, true);
targetNum = menu[menuNum][itemNum].target;
if (targetNum > 0) {
thisX = parseInt(menu[menuNum][0].ref.left) + parseInt(menu[menuNum][itemNum].ref.left);
thisY = parseInt(menu[menuNum][0].ref.top) + parseInt(menu[menuNum][itemNum].ref.top);
with (menu[targetNum][0].ref) {
left = parseInt(thisX + menu[targetNum][0].x);
top = parseInt(thisY + menu[targetNum][0].y);
visibility = 'visible';
      }
   }
}
function popOut(menuNum, itemNum) {
if ((menuNum == 0) && !menu[menuNum][itemNum].target)
hideAllBut(0)
else
popTimer = setTimeout('hideAllBut(0)', 500);
}
function getTree(menuNum, itemNum) {

// l'indice dell'Array  è il numero del menu. I contenuti sono vuoti (se quel menu non è genitore)
// o il numero specifica il figlio (anche per evidenziarlo)
itemArray = new Array(menu.length);

while(1) {
itemArray[menuNum] = itemNum;
// Se raggiungiamo la dimensione massima, ritorniamo.
if (menuNum == 0) return itemArray;
itemNum = menu[menuNum][0].parentItem;
menuNum = menu[menuNum][0].parentMenu;
   }
}

// Passo un array e un booleano per specificare il cambio di colore: true= colore quando si è sopra
function changeCol(changeArray, isOver) {
for (menuCount = 0; menuCount < changeArray.length; menuCount++) {
if (changeArray[menuCount]) {
newCol = isOver ? menu[menuCount][0].overCol : menu[menuCount][0].backCol;
// Cambia i colori di  div/layer background.
with (menu[menuCount][changeArray[menuCount]].ref) {
if (isNS4) bgColor = newCol;
else backgroundColor = newCol;
         }
      }
   }
}
function hideAllBut(menuNum) {
var keepMenus = getTree(menuNum, 1);
for (count = 0; count < menu.length; count++)
if (!keepMenus[count])
menu[count][0].ref.visibility = 'hidden';
changeCol(litNow, false);
}

// *** FUNZIONI CHE COSTRUISCONO IL MENU ***

function Menu(isVert, popInd, x, y, width, overCol, backCol, borderClass, textClass) {
// TRUE=menu VERTICALE, FALSE=menu ORIZZONTALE
this.isVert = isVert;
// L'indicatore popout usato (qualora ci fosse) per questo menu
this.popInd = popInd
// Settaggi posizione e misura.
this.x = x;
this.y = y;
this.width = width;
// Colori di menu e voci
this.overCol = overCol;
this.backCol = backCol;
//Classe del foglio di stile usato per i bordi delle voci e il loro testo
this.borderClass = borderClass;
this.textClass = textClass;
//Menu genitore e il numero dellevoci, indicizzato più tardi
this.parentMenu = null;
this.parentItem = null;
// Riferimento  alle proprietà dello stile dell'oggetto (inizializzato più avanti)
this.ref = null;
}

function Item(text, href, frame, length, spacing, target) {
this.text = text;
this.href = href;
this.frame = frame;
this.length = length;
this.spacing = spacing;
this.target = target;
// Riferimento  alle proprietà dello stile dell'oggetto (inizializzato più avanti)
this.ref = null;
}

function writeMenus() {
if (!isDOM && !isIE4 && !isNS4) return;

for (currMenu = 0; currMenu < menu.length; currMenu++) with (menu[currMenu][0]) {
// Variabile per trattenere l'HTML per le voci e le posizioni della voce successiva
var str = '', itemX = 0, itemY = 0;

// Ricordare che le voci menu partono da 1 nell'array (0 è l'oggetto menu stesso)
for (currItem = 1; currItem < menu[currMenu].length; currItem++) with (menu[currMenu][currItem]) {
var itemID = 'menu' + currMenu + 'item' + currItem;

// Altezza e larghezza delle voci menu - NB dipendono dall'orientamento (verticale o  orizzontale)
var w = (isVert ? width : length);
var h = (isVert ? length : width);

// Crea una stringa DIV o LAYER con le sue prorietà o stili
// Per IE4 il width dovrebbe essere almeno 3 per funzionare bene
if (isDOM || isIE4) {
str += '<div id="' + itemID + '" style="position: absolute; left: ' + itemX + '; top: ' + itemY + '; width: ' + w + '; height: ' + h + '; visibility: inherit; ';
if (backCol) str += 'background: ' + backCol + '; ';
str += '" ';
}
if (isNS4) {
str += '<layer id="' + itemID + '" left="' + itemX + '" top="' + itemY + '" width="' +  w + '" height="' + h + '" visibility="inherit" ';
if (backCol) str += 'bgcolor="' + backCol + '" ';
}
if (borderClass) str += 'class="' + borderClass + '" ';

// funzione mouseover 
str += 'onMouseOver="popOver(' + currMenu + ',' + currItem + ')" onMouseOut="popOut(' + currMenu + ',' + currItem + ')">';

//Aggiunge il contenuto delle voci (default: Tabella con i link all'interno)
//Per IE6/NS6 si aggiunge un padding se c'è un bordo per emulare i padding dei layer di NS4
// Se è specificato un collegamento viene aggiunto inoltre il tag <A>

str += '<table width="' + (w - 8) + '" border="0" cellspacing="0" cellpadding="' + (!isNS4 && borderClass ? 3 : 0) + '"><tr><td align="left" height="' + (h - 7) + '">' + '<a class="' + textClass + '" href="' + href + '"' + (frame ? ' target="' + frame + '">' : '>') + text + '</a></td>';
if (target > 0) {

// definisce i link genitori di questa voce
menu[target][0].parentMenu = currMenu;
menu[target][0].parentItem = currItem;

// Aggiunge un indicatore di popout
if (popInd) str += '<td class="' + textClass + '" align="right">' + popInd + '</td>';
}
str += '</tr></table>' + (isNS4 ? '</layer>' : '</div>');
if (isVert) itemY += length + spacing;
else itemX += length + spacing;
}
if (isDOM) {
var newDiv = document.createElement('div');
document.getElementsByTagName('body').item(0).appendChild(newDiv);
newDiv.innerHTML = str;
ref = newDiv.style;
ref.position = 'absolute';
ref.visibility = 'hidden';
}

// Se uso IE4 inserisco un tag DIV alla fine di BODY
if (isIE4) {
document.body.insertAdjacentHTML('beforeEnd', '<div id="menu' + currMenu + 'div" ' + 'style="position: absolute; visibility: hidden">' + str + '</div>');
ref = getSty('menu' + currMenu + 'div');
}

// In NS4, crea una relazione a un nuovo layer e vi scrive le voci
if (isNS4) {
ref = new Layer(0);
ref.document.write(str);
ref.document.close();
}

for (currItem = 1; currItem < menu[currMenu].length; currItem++) {
itemName = 'menu' + currMenu + 'item' + currItem;
if (isDOM || isIE4) menu[currMenu][currItem].ref = getSty(itemName);
if (isNS4) menu[currMenu][currItem].ref = ref.document[itemName];
   }
}
with(menu[0][0]) {
ref.left = x;
ref.top = y;
ref.visibility = 'visible';
   }
}

//  *** PARTE MODIFICABILE/EDITABILE DEL MENU ***
//
// menu[menuNumber][0] = new Menu(Vertical menu? (true/false), 'popout indicator', left, top,
// width, 'mouseover colour', 'background colour', 'border stylesheet', 'text stylesheet');
//
// Left e Top sono calcolate direttamente e si riferiscono all'angolo in ALTO e SINISTRA del genitore
// Per il menu radice si riferiscono all'angolo in ALTO e SINISTRA della pagina
//
// menu[menuNumber][itemNumber] = new Item('Testo', 'URL', 'target frame', (lunghezza/altezza del menu),
//  spazio dal menu a fianco, numero di voci menu che escono(POPOUT);
//
// Se non si vogliono menu in uscita (POPOUT), lasciare 0
// Se non si usano frame, lasciare vuota la stringa, altrimenti mettere ad esempio '_self'
//

var menu = new Array();

// Colori di default che vengono passati alla maggior parte dei costruttori menu
var defOver = '#000000', defBack = '#000000';

// 'length' di Default  delle voci menu - item HEIGTH se il menu è VERTICALE, WIDTH se è  ORIZZONTALE.
var defLength = 22;

// Menu 0 :è il menù radice da cui parte tutto il resto
menu[0] = new Array();
// Menù verticale 

// ***  ROOT MENU ***  è posizionato a  (10, 200) ed è  130px di larghezza(in questo caso)
menu[0][0] = new Menu(false, '', 0, 150, 18, '#000000', '#000000', 'itemBorder', 'itemText');
//
// La 'length' di ciascuna di queste voci è 20, e c'è uno spazio di 3 dalla voce successiva
//   
//  # significa che non c'è un link 
menu[0][1] = new Item('<IMG src="Images/_TagR.gif" border="0" align="absmiddle"> La Guinea-Bissau', '#', '_self', 154, 0, 1);
menu[0][2] = new Item('<IMG src="Images/_TagR.gif" border="0" align="absmiddle"> La Clinica Bor','#','_self',144,0,2);
menu[0][3] = new Item('<IMG src="Images/_TagR.gif" border="0" align="absmiddle"> La storia della Clinica', '#', '_self', 164, 0, 3);
menu[0][4] = new Item('<IMG src="Images/_TagR.gif" border="0" align="absmiddle"> Il Centro Artistico', '#', '_self', 154, 0, 4);
menu[0][5] = new Item('<IMG src="Images/_TagR.gif" border="0" align="absmiddle"> Le News', '#', '_self', 156, 0, 5);

//Guinea menu
menu[1] = new Array();
menu[1][0] = new Menu(true, '', 0, 26, 154, defOver, defBack, 'itemBorder', 'itemText');
menu[1][1] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> Africa, Guinea-Bissau', 'GuineaBissau.asp','_self',defLength,0,0);
menu[1][2] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> Foto del paese', 'Paese.asp','_self',defLength,0,0);
menu[1][3] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> Foto della guerra', 'Guerra.asp','_self',defLength,0,0);
menu[1][4] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> Ricostruzione', 'Ricostruzione.asp','_self',defLength,0,0);

// Clinica menu
menu[2] = new Array();
menu[2][0] = new Menu(true, '', 0, 26, 144, defOver, defBack, 'itemBorder', 'itemText');
menu[2][1] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> La Clinica Bor', 'Clinica.asp','_self',defLength,0,0);
menu[2][2] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> Il progetto', 'Progetto.asp','_self',defLength,0,0);
menu[2][3] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> Idee per aiutarci', 'Aiuto.asp','_self',defLength,0,0);

// Storia Clinica menu
menu[3] = new Array();
menu[3][0] = new Menu(true, '', 0, 26, 164, defOver, defBack, 'itemBorder', 'itemText');
menu[3][1] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> Il fondatore', 'Fondatore.asp', '_self', defLength, 0, 0);
menu[3][2] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> La sua storia', 'Storia.asp', '_self', defLength, 0, 0);
menu[3][3] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> Rifarei la stessa strada', 'StessaStrada.asp', '_self', defLength, 0, 0);

// Centro Artistico Giovanile menu
menu[4] = new Array();
menu[4][0] = new Menu(true, '', 0, 26, 154, defOver, defBack, 'itemBorder', 'itemText');
menu[4][1] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> Centro Artistico Giovanile', 'Centro.asp', '_self', defLength, 0, 0);
menu[4][2] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> Mamma Clara', 'MammaClara.asp', '_self', defLength, 0, 0);
menu[4][3] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> Il Centro oggi', 'Oggi.asp', '_self', defLength, 0, 0);
menu[4][4] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> Studenti in Italia', 'Studenti.asp', '_self', defLength, 0, 0);

// CNews menu
menu[5] = new Array();
menu[5][0] = new Menu(true, '', 0, 26, 156, defOver, defBack, 'itemBorder', 'itemText');
menu[5][1] = new Item('<IMG src="Images/_TagY.gif" border="0" align="absmiddle"> Lettera di Natale', 'Lettera.asp', '_self', defLength, 0, 0);



// *** CODICE OPZIONALE ***

// Queste 2 linee trattano il bug del dimensionamento della finestra in NS4 (dove c'è <BODY onresize=...>)
// Se si usa NS4 senza questa funzione al cambio di dimensione della finestra sparisce il menu

var popOldWidth = window.innerWidth;
nsResizeHandler = new Function('if (popOldWidth != window.innerWidth) location.reload()');


//funzione che  nasconde i menu quando si clicca!!
 if (isNS4) document.captureEvents(Event.CLICK);
   document.onclick = clickHandle;

 function clickHandle(evt)
 {
   if (isNS4) document.routeEvent(evt);
   hideAllBut(0);
 }


// This is just the moving command for the example.

//function moveRoot()
//{
// with(menu[0][0].ref) left = ((parseInt(left) < 100) ? 100 : 5);
//}
//  End -->
