var topmenu = new Array("menu_o", 
	1, "Associazione", "info/chisiamo.htm",
	2, "Attivit&agrave;", "documenti/comunicazioni.htm",
	3, "Coltivazione", "culture/galleria.htm",
	4, "Libri&nbsp;&amp;&nbsp;riviste", "books/books.htm",
	5, "Links", "misc/links1a.htm");


function Button(text, hlink) {
	var linked;
	if (hlink != null) {
		return '<td><a href="' + hlink + '" class="links">' + text + '</a></td>';
	}
	return '<th>' + text + '</th>';
}


function all_buttons(menuv, select_) {
	var cls = menuv[0];		// classe
	var zz = '<table width="650" border="0" cellpadding="0" cellspacing="2" class="' + cls + '">';
	zz += '<tr>';
	for (var i = 1; i < menuv.length; i += 3) {
		var jx = menuv[i];
		var hlink = xpath + menuv[i + 2];
		if (select_ == jx) {
			hlink = null;
		}
		zz += Button(menuv[i + 1], hlink);
	}
	zz += '</tr></table>';
	return zz;
}


function enlargeHead(headstring) {
	var xx = '<table width="1134" border="0" align="center" cellpadding="0" cellspacing="0">';
	xx += '<tr>';
	xx += '<td class="headz">&nbsp;</td>';
	xx += '<td valign="top">';
	xx += headstring;
	xx += '</td><td style="width: 67px;">&nbsp;</td></tr></table>';
	return xx;
}

function make_head(select_, path_) {
	xpath = path_;
	img_path = xpath + "images/";
	var yy = '<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0" style="height:117px; width: 1000px; background: #F7FAF2 url(' + img_path + 'fbanner_alo.jpg) no-repeat"><tr>';
	
	if (select_ == 0)
		yy += '<td width="100" valign="top"><img src="' + img_path + 'fbalo.png" width="81" height="80" style="margin: 5px 15px 0 13px"></td>';
	else {
		yy += '<td width="100" valign="top">';
		yy += '<a href="' + xpath + 'index.htm">';
		yy += '<img src="' + img_path + 'fbalo.png" alt="logo alo" title="HOME PAGE" name="ALO" width="81" height="80" border="0" style="margin: 5px 15px 0 13px">';
		yy += '</a></td>';
	}
	yy += '<td align="right" valign="top">';
	
	yy += all_buttons(topmenu, select_);
	yy +=  '</td></tr></table>';
	if (select_ == 0)
		yy = enlargeHead(yy);
	document.write(yy);
}

function make_headxx(select_, path_) {
	xpath = path_;
	img_path = xpath + "images/";
	document.write('<table width="1134" border="0" align="center" cellpadding="0" cellspacing="0">');
	document.write('<tr>');
	document.write('<td class="headz">&nbsp;</td>');
	document.write('<td valign="top" style="width: 1000px; background: #F7FAF2 url(' + img_path + 'fbanner_alo.jpg) no-repeat">');
	document.write('<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0" style="height:117px"><tr>');
	
	if (select_ == 0)
		document.write('<td width="100" valign="top"><img src="' + img_path + 'fbalo.png" width="81" height="80" style="margin: 5px 15px 0 13px"></td>');
	else {
		document.write('<td width="100" valign="top">');
		document.write('<a href="' + xpath + 'index.htm">');
		document.write('<img src="' + img_path + 'fbalo.png" alt="logo alo" title="HOME PAGE" name="ALO" width="81" height="80" border="0" style="margin: 5px 15px 0 13px">');
		document.write('</a></td>');
	}
	document.write('<td align="right" valign="top">');
	
	all_buttons(topmenu, select_);
	document.write('</td></tr></table>');
	document.write('</td><td style="width: 67px;">&nbsp;</td></tr></table>');
}


function linkIt(str, url, cls) {
	if (url == null)
		return '<b>' + str + '</b>';
	return '<a href="' + url + '" class="' + cls + '">' + str + '</a>';
}

function VerticalMenu(menuv, select_, level, second) {
	var i;
	var sel = parseInt(select_);
	var cls = menuv[0];
	var xsel = (select_.indexOf("-") < 0)? "" : select_.substr(select_.indexOf("-") + 1);

	document.write('<div class="' + cls + '">');
	for (i = 2; i < menuv.length; i += 5) {
		var jx = menuv[i];
		var hlink = menuv[i + 2];
		if (hlink == null && sel != jx)
			hlink = eval(menuv[i + 4])[4];

		if (sel == jx && xsel == "") {
			hlink = null;
		}
		document.write('<span>');
		document.write(linkIt(menuv[i + 1], hlink, cls + "X"));
		document.write('</span>');

		if (((menuv[i + 4]) && (sel == jx)) || (menuv[i + 2] == "#")) {
			var xxsel = xsel;
			if (sel != jx) xxsel = "";
			VerticalMenu(eval(menuv[i + 4]), xxsel, level + 1, true);
		}
	}
 	document.writeln('</div>');

	if (!second) {
		document.writeln('<div class = "dd">' + linkIt("Home", xpath + "index.htm", "ddX") + "</div>");
   } 
   
}

function Vertical_Menu(menuv, select_, level, second) {
	var i;
	var sel = parseInt(select_);
	var cls = menuv[0];
	if (select_ == null)
		select_ = "";
	var xsel = (select_.indexOf("-") < 0)? "" : select_.substr(select_.indexOf("-") + 1);

	for (i = 2; i < menuv.length; i += 5) {
		var jx = menuv[i];
		var hlink = menuv[i + 2];
		if (hlink == null && sel != jx)
			hlink = eval(menuv[i + 4])[4];

		if (sel == jx && xsel == "") {
			hlink = null;
		}
		var xxx = '<div>' + menuv[i + 1] + '</div>';
		if (hlink != null)
			xxx = '<a href="' + hlink + '">' + xxx + '</a>';
		document.write(xxx);

		if (((menuv[i + 4]) && (sel == jx)) || (menuv[i + 2] == "#")) {
			var xxsel = xsel;
			if (sel != jx) xxsel = "";
			Vertical_Menu(eval(menuv[i + 4]), xxsel, level + 1, true);
		}
	}   
}

function vMenu(menuv, select_) {
	if (arguments.length < 2)
		select_ = findSelectMenu(menuv);
	document.write('<div style="width:200px;">');
	VerticalMenu(menuv, select_, 0, false);
	document.write('</div>');
}

function v_Menu(menuv, select_) {
	document.write('<img src="' + xpath + 'images/fp-up.gif" alt="top" border="0" align="top">');
	if (arguments.length < 2)
		select_ = findSelectMenu(menuv);
	document.write('<div class="' + menuv[0] + '">');
	Vertical_Menu(menuv, select_, 0, false);
	document.write('</div>');
	document.writeln('<div class = "dd"><a href="' + xpath + 'index.htm">HOME</a></div>');
	document.write('<img src="' + xpath + 'images/ricciolo.gif" alt="bottom">');
}

var win_ids = new Array("mappa");

function visualizza(winid, e) {
	var win = document.getElementById(winid);
	for (var i = 0; i < win_ids.length; i++) {
		idsx = document.getElementById(win_ids[i]);
		if (idsx != null)
			nascondi(idsx);
	}
	var px = e.clientX + document.body.scrollLeft - parseInt(win.style.width) / 2;
	var py = e.clientY + document.body.scrollTop;
	var winW = window.innerWidth - 10;
	var winH = window.innerHeight;
	if (document.all) {
		winW = document.body.offsetWidth;
		winH = document.body.offsetHeight;
	}

	if (px + parseInt(win.style.width) > winW - 30) {
		px = winW - parseInt(win.style.width) -  30;
		// if (px < 0)
		// 	px = 0;
	}
	if (px < 0)
		px = 0;
	win.style.left = px + 2;
	win.style.top = py + 2;
	win.style.visibility="visible";
}


function nascondi(win) {
	win.style.visibility="hidden";
}
