// menuLayer1.0
// --------------------
// imposta variabili di controllo avvenuto caricamento
var menuLayer = 1;

// verifica avvenuto caricamento delle librerie necessarie
// -------------------------------------------------------
if (typeof(checkBrowser)=="undefined") alert("Attenzione!\n--------------\n La libreria \"menuLayer\" necessita della libreria \"checkBrowser\".");
if (typeof(checkBrowser)=="undefined") alert("Attenzione!\n--------------\n La libreria \"menuLayer\" necessita della libreria \"system\".");

// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// Menu Layer (inizio Codice)
// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

var hasIframe = (document.all && !window.opera)?1:0; // verifica se il browser in uso supporta IFRAME

var activeLayer = "";  // ** Variabile Globale. Indica l'array dei layer attualmente visibili **
var layersToHide = ""; // ** Variabile Globale. Indica l'array dei layer da nascondere **
var tim; // ** variabile globale. Indica l'intervallo di tempo di apertura di un layer.

function add_layer(nomeLayer, parent) { // aggiunge un layer alla stringa dei layer attivi
	var old_activeLayer = activeLayer;
	var new_activeLayer = "";
	var i=0;
	while ( i<parent ) {
		i++;
		if (old_activeLayer.indexOf("^") != -1) {
			new_activeLayer += old_activeLayer.substring(0, old_activeLayer.indexOf("^")+1);
			old_activeLayer  = old_activeLayer.substring(old_activeLayer.indexOf("^")+1, old_activeLayer.length);
		};
	};
	activeLayer = new_activeLayer + nomeLayer + "^"; // aggiunge il nuovo layer alla stringa dei layer attivi
	layersToHide = old_activeLayer;
}

function hide_layers(old_layers) {
	if (old_layers != "") {
		var tmp_lay = "";
		while ( old_layers.indexOf("^") != -1 ) {
			tmp_lay = old_layers.substring(0, old_layers.indexOf("^"));
			old_layers  = old_layers.substring(old_layers.indexOf("^")+1, old_layers.length);
			layersToHide = old_layers;
			if (tmp_lay != "") 
			{
				hide_lay(tmp_lay);
				if (hasIframe)
				{
					var iframe = document.getElementById(tmp_lay + "_frame");
					if (iframe != null)
					{
						iframe.style.visibility = "hidden";
					};
				};
			};
		};
	};
}

function showLayer(nomeLayer, x, y, parent) {
	clearTimeout(tim);
	add_layer(nomeLayer, parent);
	hide_layers(layersToHide);
	show_lay(nomeLayer);
	moveLayTo(nomeLayer,x,y);
	if (hasIframe)
	{
		var iframe = document.getElementById(nomeLayer + "_frame");
		if (iframe != null)
		{
			iframe.style.visibility = "visible";
			iframe.style.left = x;
			iframe.style.top = y;
		}
	};
	paint_activeRow();
}

function paint_activeRow()
{
	if (!document.layers)
	{
	
		var levels = menu_obj.levels_string;
		while (levels != "")
		{
			/* cicla su tutti i livelli creati */
			var act_level = levels.substring( (levels.indexOf("^")+1), (levels.indexOf("|")) );
			levels = levels.substring( (act_level.length+2), levels.length );
			var act_level_row = document.getElementById(act_level + "_row");
			var act_level_cell1 = document.getElementById(act_level + "_cell1");
			var act_level_cell2 = document.getElementById(act_level + "_cell2");
			var isActiveLayer = (activeLayer.indexOf("^"+act_level) != -1) || (activeLayer.indexOf(act_level) == 0);
			if (act_level_row != null)
			{
				if ( isActiveLayer )
				{
					/* se il corr. livello è attivo, la riga è colorata */
					act_level_row.style['background'] = menu_obj.menu_on_color;
				}
				else
				{
					/* altrimenti no */
					act_level_row.style['background'] = menu_obj.menu_out_color;
				};
			};
			if (act_level_cell1 != null)
			{
				if ( isActiveLayer )
				{
					/* se il corr. livello è attivo, la riga è colorata */
					act_level_cell1.style['color']      = menu_obj.font_on_color;
				}
				else
				{
					/* altrimenti no */
					act_level_cell1.style['color']      = menu_obj.font_out_color;
				};
			};
			if (act_level_cell2 != null)
			{
				if ( isActiveLayer )
				{
					/* se il corr. livello è attivo, la riga è colorata */
					act_level_cell2.style['color']      = menu_obj.font_on_color;
				}
				else
				{
					/* altrimenti no */
					act_level_cell2.style['color']      = menu_obj.font_out_color;
				};
			};
		};
	};
}

function waitAndClear()
{
	tim = setTimeout("hideAllLayer()", 700);
};

function hideAllLayer() {
	hide_layers(activeLayer);
}

function stayVisible(parent){
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
// | Mantiene visibile il livello padre ed eventualmente
// | nasconde i livelli figli.
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
	clearTimeout(tim);
	var old_activeLayer = activeLayer;
	var new_activeLayer = "";
	var i=0;
	while ( i<=parent ) {
		i++;
		if (old_activeLayer.indexOf("^") != -1) {
			new_activeLayer += old_activeLayer.substring(0, old_activeLayer.indexOf("^")+1);
			old_activeLayer  = old_activeLayer.substring(old_activeLayer.indexOf("^")+1, old_activeLayer.length);
		};
	};
	activeLayer = new_activeLayer + "^"; // aggiunge il nuovo layer alla stringa dei layer attivi
	layersToHide = old_activeLayer;
	hide_layers(layersToHide);
	paint_activeRow();
};

var page = new Object(); // ** variabile globale. Contiene le dimensioni della pagina
	page.X = 0; 
	page.Y = 0; 

function getMenuCoords(area_width){
// ------------------------------------------------------------------------------------
// restituisce l'origine assoluta (x,y) dalla quale posizionare i livelli menù
// posto di avere un'area editabile di larghezza area_width posta al centro
// ------------------------------------------------------------------------------------
	var coords = new Object();
	coords.X=0;
	coords.Y=0;
	getPageSize();
	switch (clientBrowser()){	
		case "explorer" :		
			coords.X=((page.X-area_width)/2);		
			if (coords.X<0) coords.X=0;		
			coords.Y=0;	
		break;	
		case "netscape4.x" :		
			coords.X=((page.X-area_width)/2)-9;		
			if (coords.X<0) coords.X=0;		
			coords.Y=0;	
		break;	
		case "netscape6.x" :		
			coords.X=((page.X-area_width)/2)-1;		
			if (coords.X<0) coords.X=0;		
			coords.Y=0;	
		break;
		case "netscape7.x" :		
			coords.X=((page.X-area_width)/2);		
			if (coords.X<0) coords.X=0;		
			coords.Y=0;	
		break;	
		case "opera" :		
			coords.X=((page.X-area_width)/2);		
			if (coords.X<0) coords.X=0;		
			coords.Y=0;	
		break;	
		default :		
			coords.X=((page.X-area_width)/2);		
			if (coords.X<0) coords.X=0;		
			coords.Y=0;	
		break;
	};
	return coords;
};

/*

Inizio codice pr la costruzione di menu dinamici

*/

var menu_obj = new Object();
menu_obj.inf_string  = "";
menu_obj.html_string = "";

menu_obj.levels_string = "";        // contiene l'elenco dei livelli
menu_obj.fathers_string = "";       // per ogni livello contiene l'elenco dei livelli "padre"
menu_obj.big_fathers_string = "";   // contiene l'elenco dei livelli che non hanno padre
menu_obj.levels_align = "";         // contiene l'elenco dei livelli che non hanno padre

// impostazioni
menu_obj.font_family    = "verdana";
menu_obj.font_weight    = "normal";
menu_obj.font_size      = "12px";
menu_obj.font_out_color = "#000000";
menu_obj.font_on_color  = "#ffffff";
menu_obj.menu_out_color = "#eeeeee";
menu_obj.menu_on_color  = "#000000";
menu_obj.border_color   = "#000000";
menu_obj.hor_shift      = 0;
menu_obj.vert_shift     = 0;

menu_obj.create_level = function(level_name)
{
	// crea un nuovo menu di nome "level_name"
	menu_obj.inf_string += "#level#:^" + level_name + "|";
}

menu_obj.add_voice = function(level_name, voice_string, voice_link, new_menu_align)
{
	// aggiunge al menu "menu name" la voce "voice_string"
	if (menu_obj.inf_string.indexOf("#level#:^" + level_name + "|") != -1)
	{
		var part_0 = menu_obj.inf_string.substring( 0, menu_obj.inf_string.indexOf("#level#:^" + level_name + "|") + 8 );
		var part_1 = menu_obj.inf_string.substring(menu_obj.inf_string.indexOf("#level#:^" + level_name + "|") + 8, menu_obj.inf_string.length);
		if (part_1.indexOf("#level#:")!=-1)
		{
			part_1 = part_1.substring(0, part_1.indexOf("#level#:"));
		};
		var part_2 = menu_obj.inf_string.substring(part_0.length + part_1.length, menu_obj.inf_string.length);
		/*
		 part_1 contiene la porzione di stringa
		 che interezza il menu "level_name"
		*/
		part_1 += "#voice#:^" + voice_string + "|";
		part_1 += "#voice_link#:^" + voice_link + "|";
		menu_obj.inf_string = part_0 + part_1 + part_2;
		if (voice_link.substring(0,1)=="#")
		{
			/*
			  aggiunge la dir. di apertura
			  di un nuovo livello
			*/
			var level_align = "right";
			if (new_menu_align=="left")
			{
				level_align = "left";
			}
			menu_obj.levels_align += "#from#:^" + level_name + "|#to#^" + voice_link.substring(1,voice_link.length) + "|#dir#^" + level_align + "|";
		};
	}
	else
	{
		alert("Attenzione: il livello \"" + level_name + "\" non è stato creato!\n\nControllare.");
	};
}

menu_obj.get_levels = function()
{
	/*
	  ricava l'elenco dei livelli creati
	*/
	var tmp_str = menu_obj.inf_string;
	cond = true;
	while (cond)
	{
		if (tmp_str.indexOf("#level#:") != -1)
		{
			tmp_str = tmp_str.substr( (tmp_str.indexOf("#level#:")+8), tmp_str.length );
			menu_obj.levels_string += tmp_str.substr( 0, (tmp_str.indexOf("|")+1) );
		}
		else
		{
			cond = false;
		};
	};
}

menu_obj.get_level_string = function(act_level)
{
	/*
	  dato un livello, ricava la porzione di 
	  stringa informazioni corrispondente
	*/
	act_level = "#level#:^" + act_level + "|";
	var inf_string = menu_obj.inf_string;
	inf_string = inf_string.substring( (inf_string.indexOf(act_level) + act_level.length), inf_string.length );
	if ( inf_string.indexOf("#level#:") != -1 )
	{
		inf_string = inf_string.substring( 0, inf_string.indexOf("#level#:") );
	};
	return inf_string;
}

menu_obj.get_fathers = function()
{
	/*
	  per ogni livello ricava
	  l'elenco dei livelli padre
	*/
	menu_obj.get_levels();
	var levels = menu_obj.levels_string;
	var fathers = "";
	while (levels != "")
	{
		/* cicla su tutti i livelli creati */
		var act_level = levels.substring( (levels.indexOf("^")+1), (levels.indexOf("|")) );
		levels = levels.substring( (act_level.length+2), levels.length );
		
		/* per ogni livello ricava la porzione di stringa corrispondente */
		var act_level_string = menu_obj.get_level_string(act_level);
		
		/* cicla sui link della stringa */
		var inheritance = 0;
		while (act_level_string != "")
		{
			if ( act_level_string.indexOf("#voice_link#:") != -1 )
			{
				inheritance++;
				act_level_string = act_level_string.substring( (act_level_string.indexOf("#voice_link#:") + 13), act_level_string.length );
				var act_link = act_level_string.substring( (act_level_string.indexOf("^")+1), (act_level_string.indexOf("|")) );
				if ( act_link.substring(0,1)=="#" )
				{
					fathers += "#fatherOf#:^" + act_link.substring(1, act_link.length) + "|=^" + act_level + "|, " + inheritance;
				};
				
				act_level_string = act_level_string.substring( (act_link.length + 2), act_level_string.length );
			}
		};
		
	};
	
	/* secondo ciclo su tutti i livelli */
	var levels = menu_obj.levels_string;
	while (levels != "")
	{
		
		/* cicla su tutti i livelli creati */
		var act_level = levels.substring( (levels.indexOf("^")+1), (levels.indexOf("|")) );
		levels = levels.substring( (act_level.length+2), levels.length );
		
		if (fathers.indexOf("#fatherOf#:^" + act_level + "|") == -1)
		{
			/* il livello è un big_father */
			menu_obj.big_fathers_string += "^" + act_level + "|";
		}
		else
		{
			menu_obj.fathers_string += "#fathersOf#:^" + act_level + "|";
			/* risale l'albero genealogico */
			var cond = true;
			while (cond)
			{
				var tmp = "#fatherOf#:^" + act_level + "|=";
				if (fathers.indexOf(tmp) != -1)
				{
					var act_father = fathers.substring( (fathers.indexOf(tmp)+tmp.length), fathers.length );
					if ( act_father.indexOf("#fatherOf#:") != -1 )
					{
						act_father = act_father.substring( 0, act_father.indexOf("#fatherOf#:") );
					};
					menu_obj.fathers_string = menu_obj.fathers_string + act_father;
					act_level = act_father.substring( (act_father.indexOf("^")+1), act_father.indexOf("|") );
				}
				else
				{
					cond = false;
				};
			};
		};
		
	};		
	
}

menu_obj.family = function(big_father, level)
{
	/*
	  ricostruisce i figli di big_father
	  di grado "level"
	*/

	var tmp_fath = menu_obj.fathers_string;
	var son = "";
	var i=0;
	var result = "";
	while (tmp_fath.indexOf("^" + big_father + "|,") != -1)
	{
		son = tmp_fath.substring(0, tmp_fath.indexOf("^" + big_father + "|,"));
		son = son.substring(son.lastIndexOf("#fathersOf#:^")+13, son.length);
		// cerca, tra i figli, quello di grado "level"
		i=0;
		while (i<level && son!="")
		{
			i++;
			if (son.indexOf("^")==-1)
			{
				son=""
			}
			else
			{
				son = son.substring( 0, son.lastIndexOf("^"));
			};
		};
		if (son != "" && son.indexOf("^")==-1)
		{
			result += "^" + son;
		};
		tmp_fath = tmp_fath.substring( tmp_fath.indexOf("^" + big_father + "|,"), tmp_fath.length );
		if (tmp_fath.indexOf("#fathersOf#")==-1)
		{
			tmp_fath = "";
		}
		else
		{
			tmp_fath = tmp_fath.substring( tmp_fath.indexOf("#fathersOf#"), tmp_fath.length );
		};
	};
	return result;
}


menu_obj.build = function()
{
	/*
		processa la varie stringhe di informazione
		e crea il codice html dei menu.
	*/
	menu_obj.get_fathers();
	
	/* cicla sui grandi padri */
	var big_fathers = menu_obj.big_fathers_string;
	var sons = "";
	var i=0;
	var cond = true;
	while (big_fathers != "")
	{
		/* cicla su tutti i grandi padri */
		var act_big_father = big_fathers.substring( (big_fathers.indexOf("^")+1), (big_fathers.indexOf("|")) );
		big_fathers = big_fathers.substring( (act_big_father.length+2), big_fathers.length );
		
		// prima costruisce il livello "grande padre"
		menu_obj.father_and_son(act_big_father, -1);
		
		// poi cicla su tutti i figli (di ogni grado)
		i=0;
		cond = true;
		while (cond)
		{
			sons = menu_obj.family(act_big_father,i);
			if (sons != "")
			{
				/*
				  costruisce tutti i livelli
				  figli di grado i
				*/
				while (sons != "")
				{
					menu_obj.father_and_son( sons.substring( sons.indexOf("^")+1, sons.indexOf("|") ), i);
					sons = sons.substring( sons.indexOf("|")+1, sons.length);
				};
			}
			else
			{
				cond = false;
			};
			i++;
		};
		
	};
	document.writeln(menu_obj.html_string);
}


menu_obj.father_and_son = function(level_name, level_level)
{
	/*
	  costruisce il livello e
	  procede ricors. sui figli
	*/
	level_level++;
	var new_lev = level_level + 1;
	var line_bgcolor     = menu_obj.menu_out_color;
	var mouse_over_style = "this.style.cursor='hand'; this.style['background']='" + menu_obj.menu_on_color + "'; ";
	var mouse_out_style  = "this.style['background']='" + line_bgcolor + "'; ";
	var cell_style       = " style=\""
	+ "font-family:" + menu_obj.font_family     + "; "
	+ "font-weight:" + menu_obj.font_weight     + "; "
	+ "font-size:"   + menu_obj.font_size       + "; "
	+ "color:"       +  menu_obj.font_out_color + "; "
	+ "\" "
	+ "onmouseover=\"this.style.color='" + menu_obj.font_on_color + "';\" "
	+ "onmouseout=\"this.style.color='" + menu_obj.font_out_color + "';\" ";
	var link_style       = " style=\""
	+ "color:" + menu_obj.font_out_color + "; "
	+ "text-decoration:none; "
	+ "\" ";
	
	/* inizio livello */
	var tmp_str0 = "";
	if (hasIframe)
	{
		tmp_str0 = "<iframe id =\"" + level_name + "_frame\"></iframe>";
	};
	tmp_str0 += "\n <div id=\"" + level_name + "\" style=\"position:absolute; visibility:hidden;\">";
	if (document.layers)
	{
		tmp_str0 = "\n <layer id=\"" + level_name + "\" visibility=\"hide\" bgcolor=\"" + line_bgcolor + "\">";
	};
	var tmp_str = "\n    <table id=\"" + level_name + "_table\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"" + menu_obj.border_color + "\">"
	            + "\n    <tr>"
	            + "\n    <td>"
	            + "\n    <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"" + line_bgcolor + "\">";
	
	if (document.layers)
	{
		//tmp_str += "\n    <tr><td colspan=\"2\"><div style=\"font-size:0px\"></div></td></tr>";
	};
	
	var lev_voices = menu_obj.get_level_string(level_name);
	var show_link      = "";
	var cell           = "";
	var line_over_link = "";
	var line_out_link  = "";
	var tr_string      = "";
	while (lev_voices.indexOf("#voice#:") != -1)
	{
		// cicla sulle voci
		lev_voices = lev_voices.substring( (lev_voices.indexOf("#voice#:") + 8), lev_voices.length );
		var lev_voice = lev_voices;
		if ( lev_voice.indexOf("#voice#:") != -1 )
		{
			lev_voice = lev_voice.substring( 0, lev_voice.indexOf("#voice#:") );
		};
		var lev_voice_link = lev_voice.substring( (lev_voice.indexOf("#voice_link#:") + 14), (lev_voice.length-1) )
		lev_voice = lev_voice.substring(1, (lev_voice.indexOf("#voice_link#:")-1) );
		if (lev_voice_link.substring(0,1)=="#")
		{

			// link ad altro livello
			if (document.layers)
			{			
				show_link      = "showLayer('" + lev_voice_link.substring(1,lev_voice_link.length) + "', menu_obj.get_left('" + lev_voice_link.substring(1,lev_voice_link.length) + "'), menu_obj.get_top('" + lev_voice_link.substring(1,lev_voice_link.length) + "')," + new_lev + ")";
				cell           = "<td nowrap><span " + cell_style + "><a " + link_style + " href=\"#\" onmouseover=\"" + show_link + "\" onmouseout=\"waitAndClear()\">&nbsp;" + lev_voice + "&nbsp;</a></span></td>"
				line_over_link = mouse_over_style + show_link;
				line_out_link  = mouse_out_style + "waitAndClear()";
				tr_string      = "<tr bgcolor=\"" + line_bgcolor + "\" >";
			}
			else
			{
				show_link      = "showLayer('" + lev_voice_link.substring(1,lev_voice_link.length) + "', menu_obj.get_left('" + lev_voice_link.substring(1,lev_voice_link.length) + "'), menu_obj.get_top('" + lev_voice_link.substring(1,lev_voice_link.length) + "')," + new_lev + ")";
				cell           = "<td id=\"" + lev_voice_link.substring(1,lev_voice_link.length) + "_cell1\" nowrap " + cell_style + "><span>&nbsp;" + lev_voice + "&nbsp;</span></td>"
				line_over_link = mouse_over_style + show_link;
				line_out_link  = mouse_out_style + "waitAndClear()";
				tr_string      = "<tr id=\"" + lev_voice_link.substring(1,lev_voice_link.length) + "_row\" bgcolor=\"" + line_bgcolor + "\" onmouseover=\"" + line_over_link + "\" onmouseout=\"" + line_out_link + "\">";
			};
			if ( menu_obj.get_level_align(lev_voice_link.substring(1,lev_voice_link.length)) == "left" )
			{
				if (document.layers)
				{
					cell       = "<td nowrap colspan=\"2\"><span " + cell_style + "><a " + link_style + " href=\"#\" onmouseover=\"" + show_link + "\" onmouseout=\"waitAndClear()\">&nbsp;&#171;&nbsp;&nbsp;" + lev_voice + "&nbsp;</a></span></td>"
				}
				else
				{
					cell       = "<td id=\"" + lev_voice_link.substring(1,lev_voice_link.length) + "_cell1\" " + cell_style + " nowrap colspan=\"2\"><span>&nbsp;&#171;&nbsp;&nbsp;" + lev_voice + "&nbsp;</span></td>"
				};
				tmp_str += "\n    " + tr_string + cell + "</tr>";
			}
			else
			{
				tmp_str += "\n    " + tr_string + cell + "<td  id=\"" + lev_voice_link.substring(1,lev_voice_link.length) + "_cell2\"" + cell_style + " align=\"right\"><span>&#187;&nbsp;</span></td></tr>";
			};

		}
		else
		{

			// link
			if (document.layers)
			{
				show_link      = "stayVisible(" + level_level + ")";
				cell           = "<td nowrap colspan=\"2\"><span " + cell_style + "><a " + link_style + " href=\"" + lev_voice_link.substring(1,lev_voice_link.length) + "\" onmouseover=\"" + show_link + "\" onmouseout=\"waitAndClear()\">&nbsp;" + lev_voice + "&nbsp;</a></span></td>"
				line_out_link  = mouse_out_style + "waitAndClear()";
				line_over_link = mouse_over_style + show_link;
				tr_string      = "<tr bgcolor=\"" + line_bgcolor + "\" >";
			}
			else
			{
				show_link      = "stayVisible(" + level_level + ")";
				cell           = "<td " + cell_style + " nowrap colspan=\"2\"><span>&nbsp;" + lev_voice + "&nbsp;</span></td>"
				line_out_link  = mouse_out_style + "waitAndClear()";
				line_over_link = mouse_over_style + show_link;
/*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
				tr_string      = "<tr bgcolor=\"" + line_bgcolor + "\" onclick=\"document.location.href='" + lev_voice_link.substring(1,lev_voice_link.length) + "';\" onmouseover=\"" + line_over_link + "\" onmouseout=\"" + line_out_link + "\">";
			}
			tmp_str       += "\n    " + tr_string + cell + "</tr>";
		};
	};
	var new_lev = level_level + 1;

	/* fine livello */
	tmp_str += "\n    </table>"
	         + "\n    </td>"
	         + "\n    </tr>"
	         + "\n    </table>";
	if (document.layers)
	{
		tmp_str0 += tmp_str + "\n </layer>";
	}
	else
	{
		tmp_str0 += tmp_str + "\n </div>";
	};
	if (hasIframe)
	{
		tmp_str0 += "\n <script language=\"javascript\">"
		          + "\n var iframe = document.getElementById(\"" + level_name + "_frame\");"
		          + "\n var itable = document.getElementById(\"" + level_name + "_table\");"
		          + "\n iframe.style.border = 0; "
		          + "\n iframe.width = itable.offsetWidth;"
		          + "\n iframe.height = itable.offsetHeight;"
		          + "\n iframe.style.position = \"absolute\";"
		          + "\n iframe.style.visibility = \"hidden\"; "
				  + "\n </script>";
	};
	menu_obj.html_string += tmp_str0;
}


menu_obj.how_many_voices = function(level_name)
{
	/*
	  restituisce il numero di voci rappresentate 
	  nel livello "level_name"
	*/
	var counter = 0;
	var tmp_str = menu_obj.inf_string;
	var tmp = "#level#:^" + level_name + "|";
	if (tmp_str.indexOf(tmp) != -1)
	{
		tmp_str = tmp_str.substring( (tmp_str.indexOf(tmp) + tmp.length), tmp_str.length);
		if (tmp_str.indexOf("#level#:") != -1)
		{
			tmp_str = tmp_str.substring(0, tmp_str.indexOf("#level#:"));
		};
		while (tmp_str.indexOf("#voice#:")!=-1)
		{
			counter++;
			tmp_str = tmp_str.substring( (tmp_str.indexOf("#voice#:")+8), tmp_str.length);
		};
		return counter;
	}
	else
	{
		return 0;
	}
}

menu_obj.get_position = function(level_name, from_level_name)
{
	/*
	  restituisce l'allineamento 
	  del nuovo livello "level_name"
	*/
	var tmp;
	var tmp_str = menu_obj.levels_align;
	var level_name_width = getLayWidth(level_name);
	var from_level_name_width = getLayWidth(from_level_name);
	tmp = "#from#:^" + from_level_name + "|#to#^" + level_name + "|#dir#^";
	if (tmp_str.indexOf(tmp)!=-1)
	{
		tmp = tmp_str.substring( (tmp_str.indexOf(tmp)+tmp.length), tmp_str.length );
		tmp = tmp.substring(0, tmp.indexOf("|"));
		if (tmp == "left")
		{
			return - level_name_width + (1 - menu_obj.hor_shift);
		}
		else
		{
			return from_level_name_width - (1 - menu_obj.hor_shift);
		}
	}
	else
	{
		return 0;
	};
}


menu_obj.get_level_align = function(level_name)
{
	/*
	  restituisce l'allineamento 
	  del livello da aprire
	*/
	var tmp;
	var tmp_str = menu_obj.levels_align;
	tmp = "#to#^" + level_name + "|#dir#^";
	if (tmp_str.indexOf(tmp) != -1)
	{
		tmp = tmp_str.substring( (tmp_str.indexOf(tmp) + tmp.length) , tmp_str.length);
		tmp = tmp.substring( 0, tmp.indexOf("|") );
		return tmp;
	}
	else
	{
		return "right";
	};
	
}

menu_obj.show = function(level_name, x, y)
{
	if (menu_obj.big_fathers_string.indexOf(level_name)==-1)
	{
		alert("Errore:\n\nPuoi visualizzare direttamente\nsolo i layer di primo livello.\n\nControlla il codice");
	}
	else
	{
		showLayer(level_name, x, y, 0);
	};
}

menu_obj.get_left = function(level_name)
{
	/*
	  restituisce la coordinata x del menù
	  figlio da visualizzare
	*/
	var left = 0;
	var cond = true;
	var tmp = "#fathersOf#:^" + level_name + "|";
	var tmp_str = menu_obj.fathers_string;
	if (tmp_str.indexOf(tmp)!=-1)
	{
		tmp_str = tmp_str.substring( (tmp_str.indexOf(tmp)+tmp.length), tmp_str.length);
		if (tmp_str.indexOf("#fathersOf#:")!=-1)
		{
			tmp_str = tmp_str.substring(0, tmp_str.indexOf("#fathersOf#:"));
		};
		var lay_fath = ""
		while (tmp_str.indexOf("|,")!=-1)
		{

			lay_fath = tmp_str.substring( (tmp_str.indexOf("^") + 1), tmp_str.indexOf("|") );
			tmp_str = tmp_str.substring( (tmp_str.indexOf("|") + 1), tmp_str.length );
			left += menu_obj.get_position(level_name,lay_fath);
			level_name = lay_fath;

		};
		left += getLayLeft(lay_fath);
		return left;
	}
	else
	{
		return 0;
	};
}

menu_obj.get_top = function(level_name)
{
	/*
	  restituisce la coordinata x del menù
	  figlio da visualizzare
	*/
	var top = 0;
	var cond = true;
	var tmp = "#fathersOf#:^" + level_name + "|";
	var tmp_str = menu_obj.fathers_string;
	if (tmp_str.indexOf(tmp)!=-1)
	{
		tmp_str = tmp_str.substring( (tmp_str.indexOf(tmp)+tmp.length), tmp_str.length);
		if (tmp_str.indexOf("#fathersOf#:")!=-1)
		{
			tmp_str = tmp_str.substring(0, tmp_str.indexOf("#fathersOf#:"));
		};
		var lay_fath = ""
		var lay_in = "";
		while (tmp_str.indexOf("|,")!=-1)
		{
			lay_fath = tmp_str.substring( (tmp_str.indexOf("^") + 1), tmp_str.indexOf("|") );
			tmp_str = tmp_str.substring( (tmp_str.indexOf("|") + 1), tmp_str.length );
			lay_in = tmp_str.substring( (tmp_str.indexOf(",") + 1), tmp_str.length);
			if (lay_in.indexOf("^")!=-1)
			{
				lay_in = lay_in.substring(0,lay_in.indexOf("^"));
			}
			var inerit = parseInt(lay_in);
			top += ( ( (inerit-1) * getLayHeight(lay_fath) ) / menu_obj.how_many_voices(lay_fath) );
		};
		top += getLayTop(lay_fath)
		return top + menu_obj.vert_shift;
	}
	else
	{
		return 0;
	};
}

/*

Inizio codice pr la costruzione di menu dinamici

*/

// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// Menu Layer (fine Codice)
// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
