// costruttore
function menu(MenuLeft,MenuTop,MenuWidth,MenuBackground,SelBackground,VoceHeight,FontFace,FontSize,FontColor,voce,hlink) {
	this.MenuLeft = MenuLeft;
	this.MenuTop = MenuTop;
	this.MenuWidth = MenuWidth;
	this.MenuBackground = MenuBackground;
	this.SelBackground = SelBackground;
	this.VoceHeight = VoceHeight;
	this.FontFace = FontFace;
	this.FontSize = FontSize;
	this.FontColor = FontColor;
	this.voce = voce;
	this.hlink = hlink;
	this.cursorSupport = cursorSupport;
	this.mostravoce = mostravoce;
	this.mostrasottovoce = mostrasottovoce;
	this.selvoce = selvoce;
	this.crea = crea;
}

function cursorSupport() {
	var browser = navigator.userAgent.toLowerCase();
	var isMicrosoft;
	version = parseFloat(navigator.appVersion);
	
	if (browser.indexOf('msie')) {
		var tmp = navigator.appVersion.split('MSIE');
		version = parseFloat(tmp[1]);
		isMicrosoft = true;
	} else {
		isMicrosoft = false;
	}
	if (isMicrosoft && version >= 6) {
		return true;
	} 
	return false;
}

function crea() {
	var more,tmp,stringa,ref;
	// Menu principale
	document.writeln("<div class=\"menu\" id=\"principale\" style=\"width:"+this.MenuWidth+"px;background:"+this.MenuBackground+";position:absolute;left:"+this.MenuLeft+"px;top:"+this.MenuTop+"px\">");
	for (i = 0;i < this.voce.length;i++) {
		tmp = this.voce[i];
		if (tmp.constructor == Array && tmp.length > 1) {
			more = 'visible';
		} else {
			more = 'hidden';
		}
		stringa = this.voce[i][0];
		ref = this.hlink[i][0];
		document.writeln("<div id=\"voce"+i+"\" style=\"height:"+this.VoceHeight+"px\" onMouseOver=\"mostravoce("+i+",'visible')\" onMouseOut=\"mostravoce("+i+",'hidden')\" onClick=\"window.location.href='"+ref+"'\">");
		document.writeln("<table cellpadding='2' cellspacing='0' border='0'><tr><td width='97%'>");
		document.writeln("<font face='"+this.FontFace+"' size='"+this.FontSize+"' color='"+this.FontColor+"'>"+stringa+"</font>");
		document.writeln("</td><td width='3%' align='center'><div  id=\"fvoce"+i+"\" style='visibility:"+more+"'><font face='"+this.FontFace+"' size='"+this.FontSize+"' color='"+this.FontColor+"'>></font></div></td></tr></table>");
		document.writeln("</div>");
	}
	document.writeln("</div>");
	
	// Sottomenu
	for (i = 0;i < this.voce.length;i++) {
		var tmp_1 = this.voce[i];
		var TopSottomenu = this.MenuTop + (this.VoceHeight * i);
		document.writeln("<div class=\"menu\" id='voce"+i+"0' style='background:"+this.MenuBackground+";width:"+this.MenuWidth+"px;position:absolute;left:"+((this.MenuWidth + this.MenuLeft) - 2)+"px;top:"+TopSottomenu+";visibility:hidden' onMouseOver=\"mostravoce("+i+",'visible')\" onMouseOut=\"mostravoce("+i+",'hidden')\">");
		for (x = 1;x < tmp_1.length;x ++) {
			tmp = this.voce[i][x];
			if (tmp.constructor == Array && tmp.length > 1) {
				more = 'visible';
				stringa = this.voce[i][x][0];
				ref = this.hlink[i][x][0];
			} else {
				more = 'hidden';
				stringa = this.voce[i][x];
				ref = this.hlink[i][x];
			}
			document.writeln("<div id=\"voce"+i.toString()+x.toString()+"\" style=\"height:"+this.VoceHeight+"px\" onMouseOver=\"mostrasottovoce("+i+","+x+",'visible')\" onMouseOut=\"mostrasottovoce("+i+","+x+",'hidden')\" onClick=\"window.location.href='"+ref+"'\">");
			document.writeln("<table cellpadding='2' cellspacing='0' border='0'><tr><td width='97%'>");
			document.writeln("<font face='"+this.FontFace+"' size='"+this.FontSize+"' color='"+this.FontColor+"'>"+stringa+"</font>");
			document.writeln("</td><td width='3%' align='center'><div id=\"fvoce"+i.toString()+x.toString()+"\" style=\"visibility:"+more+"\"><font face='"+this.FontFace+"' size='"+this.FontSize+"' color='"+this.FontColor+"'>></font></div></td></tr></table>");
			document.writeln("</div>");
		}
		document.writeln("</div>"); 
	} 
	
	// Sotto-sottomenu
	for (i = 0;i < this.voce.length;i++) {
		var tmp_1 = this.voce[i];
		for (x = 1;x < tmp_1.length;x ++) {
			var tmp_2 = this.voce[i][x];
			if (tmp_2.constructor == Array && tmp_2.length > 1) {
				var TopSottomenu = this.MenuTop + (this.VoceHeight * x);
				document.writeln("<div class=\"menu\" id=\"voce"+i.toString()+x.toString()+"0\" style=\"background:"+this.MenuBackground+";width:"+this.MenuWidth+"px;position:absolute;left:"+((this.MenuWidth * 2) - 2)+"px;top:"+TopSottomenu+";visibility:hidden\" onMouseOver=\"javascript:mostravoce("+i+",'visible');mostrasottovoce("+i+","+x+",'visible');\" onMouseOut=\"javascript:mostravoce("+i+",'hidden');mostrasottovoce("+i+","+x+",'hidden');\">");
				for (y = 1;y < tmp_2.length;y++) {
					document.writeln("<div id=\"voce"+i.toString()+x.toString()+y.toString()+"\" style=\"height:"+this.VoceHeight+"px\" onMouseOver=\"selvoce("+i+","+x+","+y+",'visible')\" onMouseOut=\"selvoce("+i+","+x+","+y+",'hidden')\" onClick=\"window.location.href='"+this.hlink[i][x][y]+"'\">");
					document.writeln("<table cellpadding='2' cellspacing='0' border='0'><tr><td>");
					document.writeln("<font face='"+this.FontFace+"' size='"+this.FontSize+"' color='"+this.FontColor+"'>"+this.voce[i][x][y]+"</font>");
					document.writeln("</td></tr></table>");
					document.writeln("</div>");
				}
				document.writeln("</div>"); 
			}
		}
	}
}

function mostravoce(which,state) {
	var v = this.voce[which];
	var elmain,elsotto;

	if (document.all) {
		elmain = document.all['voce'+which+'0'];
		elsotto = document.all['voce'+which];
	} else {
		elmain = document.getElementById('voce'+which+'0');
		elsotto = document.getElementById('voce'+which);
	}
	if (v.constructor == Array && v.length > 1) {
		elmain.style.visibility = state;
		if (this.cursorSupport()) elsotto.style.cursor = 'arrow';
	} else {
		if (this.cursorSupport()) elsotto.style.cursor = 'hand';
	}
	if (state == 'visible') {
		elsotto.style.background = this.SelBackground;
	} else {
		elsotto.style.background = this.MenuBackground;
	}
	window.status = v[0];
}

function mostrasottovoce(whichi,whichx,state) {
	var v = this.voce[whichi][whichx];
	var elmain,elsotto;
	if (document.all) {
		elmain = document.all['voce'+whichi.toString()+whichx.toString()+'0'];
		elsotto = document.all['voce'+whichi.toString()+whichx.toString()];
	} else {
		elmain = document.getElementById('voce'+whichi.toString()+whichx.toString()+'0');
		elsotto = document.getElementById('voce'+whichi.toString()+whichx.toString());
	}
	
	if (v.constructor == Array && v.length > 1) {
		elmain.style.visibility = state;
		if (this.cursorSupport()) elsotto.style.cursor = 'arrow';
	} else {
		if (this.cursorSupport()) elsotto.style.cursor = 'hand';
	}
	if (state == 'visible') {
		elsotto.style.background = this.SelBackground;
	} else {
		elsotto.style.background = this.MenuBackground;
	}
	window.status = v[0];
}

function selvoce(whichi,whichx,whichy,state) {
	var v = this.voce[whichi][whichx][whichy];
	var elmain,elsotto;
	if (document.all) {
		elsotto = document.all['voce'+whichi.toString()+whichx.toString()+whichy.toString()];
	} else {
		elsotto = document.getElementById('voce'+whichi.toString()+whichx.toString()+whichy.toString());
	}
	if (this.cursorSupport()) elsotto.style.cursor = 'hand';
	if (state == 'visible') {
		elsotto.style.background = this.SelBackground;
	} else {
		elsotto.style.background = this.MenuBackground;
	}
	window.status = v[0];
}

