//================================================
//
//  Slavon.net menu v0,7b "write" lib
//
//   menu_x - x of "place_menu"
//   menu_y - y of "place_menu"
//   temp_menu - menu array by id (ex: menu[i].pid = 2)
//   index_menu - indexes between menu[] and temp_menu
//   menu_gen - menu (ID) already generated
//
//////////////////////////////////////////////////
//
//   TO DO:
//   1. menu[id].ori have 0,2 ; need 1,3
//   2. menu[id].type - horizontal, vertical
//   3. cellpadding - ok; cellspacing - need check
//   4. Optimization :)
//
//
//================================================



function write_menu_l1(ox, oy){
menu_x = ox;
menu_y = oy;
write_menu_custom(0);
}
function write_menu_other(){
}
function write_menu_custom(id){
	var temp_menu = new Array();
	var index_menu = new Array();
	var str = '';
	var vvv=0;
	var vvv1=0;
browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
var agent = navigator.userAgent;

if (agent.indexOf("Opera") > -1) {
	vvv=0;
	vvv1=0;
}
else if ((browserVer >3) && (browserName == "Microsoft Internet Explorer")) {
	vvv=21;
}
else if ((browserVer >3) &&(browserName == "Netscape")) {
	vvv=21;
}	
	

	for(i=0; i<menu_gen.length; i++)
		if (menu_gen[i] == id)
			return true;
	
	for(i=1; i<menu.length; i++)
		if (menu[i].pid == id){
			temp_menu[(temp_menu.length?temp_menu.length:0)] = menu[i];
			index_menu[(index_menu.length?index_menu.length:0)] = i;
		}
	if (temp_menu.length){
		if (menu_gen.length && menu[id].ori== 2){
			xx = menu[id].x + menu[id].w+vvv;
			yy = menu[id].y+vvv1;;
		}else{
			xx = menu_gen.length?menu[id].x:'';
			yy = menu_gen.length?(menu[id].y + menu[id].h):'';
		}
		                                                
//		alert("id" + id + "\n" + "xx:" + xx + "\n" + "yy:" + yy + "\n");

		if (!menu_gen.length){
str = '<table cellpadding=0 cellspacing=0 border=0 width="100%">';
			for(i=0; i<temp_menu.length; i++){
str += '<tr><td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();" align="right"><a href="'+ temp_menu[i].url +'"><img id="td_y_' + index_menu[i] + '" name="td_y_' + index_menu[i] + '" src="'+ (temp_menu[i].div_style?temp_menu[i].img_over:temp_menu[i].img)+'" alt="'+ temp_menu[i].text +'" border="0"></a></td></tr>';
str += '<tr><td><table cellpadding=0 cellspacing=0 border=0 width="100%"><tr><td width="100%"><img src="/img/menu/menu_line.gif" alt="" width="154" height="1" border="0"></td><td class="menu-margin" align="right"><DIV style="width:4px; height: 1px;"><SPACER type="block" width="4" height="1"></SPACER></DIV></td></tr></table></td></tr>';
			}
str += '</table>';
		}else{
			str = "<div id='a" + id + "' style='width: " + (getRef("td_" + id).offsetWidth) + "px; position: absolute; left: " + xx + "px; top: " + yy + "px; visibility: visible; z-index: 999999;'>";
str += '<table cellpadding="0" cellspacing="0" border="0" width="147">';
str += '<tr>';
str += '<td bgcolor="#d0cbab">';
str += '<table cellpadding="0" cellspacing="0" border="0" width="147" bgcolor="#d0cbab">';
			for(i=0; i<temp_menu.length; i++){
			if (i==0) {
str += '<tr><td height="20" onclick="document.location=\'' + temp_menu[i].url + '\';" id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');this.className = \'table-umenu\'; U_over_m(\'kn'+index_menu[i]+'\',\'/img/menu/lk1.gif\');" onmouseout="td_menu_out(); this.className = \'table-umenu-s\'; U_out();"><DIV style="width:1px; height: 4px;"><SPACER type="block" width="1" height="4"></SPACER></DIV><table cellpadding="0" cellspacing="0" width="100%" border="0"><tr><td valign="top"><img src="/img/menu/lk'+ (temp_menu[i].div_style?1:2)+'.gif" alt="" width="3" height="3" border="0" style="margin-left: 10px; margin-right: 6px;" id="kn' + index_menu[i] + '" name="kn' + index_menu[i] + '" vspace="5"></td><td width="100%" align="left"><a href="'+ temp_menu[i].url + '" class="mmenu" onmouseover="U_over_m(\'kn'+index_menu[i]+'\',\'/img/menu/lk1.gif\');" onmouseout="U_out();">'+ temp_menu[i].text +'</a></td><td><img src="/img/sp.gif" width="10" height="1"></td></tr></table></td></tr>';    			
				}else{
str += '<tr><td height="20" onclick="document.location=\'' + temp_menu[i].url + '\';" id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');this.className = \'table-umenu\'; U_over_m(\'kn'+index_menu[i]+'\',\'/img/menu/lk1.gif\');" onmouseout="td_menu_out(); this.className = \'table-umenu-s\'; U_out();"><table cellpadding="0" cellspacing="0" width="100%" border="0"><tr><td valign="top"><img src="/img/menu/lk'+ (temp_menu[i].div_style?1:2)+'.gif" alt="" width="3" height="3" border="0" style="margin-left: 10px; margin-right: 6px;" id="kn' + index_menu[i] + '" name="kn' + index_menu[i] + '" vspace="5"></td><td width="100%" align="left"><a href="'+ temp_menu[i].url + '" class="mmenu" onmouseover="U_over_m(\'kn'+index_menu[i]+'\',\'/img/menu/lk1.gif\');" onmouseout="U_out();">'+ temp_menu[i].text +'</a></td><td><img src="/img/sp.gif" width="10" height="1"></td></tr></table></td></tr>';    			
				}	
			}
str += '</table>';			
str += '</td></tr><tr><td><img src="/img/menu/niz.gif" alt="" width="147" height="37" border="0"></td></tr></table>';
			str += "</div>";
		}
		if(menu_gen.length){
			getRef('place_menu2').innerHTML += str;
		}else{
			getRef('place_menu').innerHTML = str;
		}
		for(i=0; i<temp_menu.length; i++){
			if (menu_gen.length){
				menu[index_menu[i]].x = getRef("a" + id).offsetLeft + getRef("td_" + index_menu[i]).offsetLeft;
				menu[index_menu[i]].y = getRef("a" + id).offsetTop + getRef("td_" + index_menu[i]).offsetTop;
			}else{
				menu[index_menu[i]].x = menu_x + getRef("place_menu").offsetLeft + getRef("td_" + index_menu[i]).offsetLeft + 0;
				menu[index_menu[i]].y = menu_y + getRef("place_menu").offsetTop + getRef("td_" + index_menu[i]).offsetTop + 0;
			}
			menu[index_menu[i]].h = getRef("td_" + index_menu[i]).offsetHeight;
			menu[index_menu[i]].w = getRef("td_" + index_menu[i]).offsetWidth;
		}
		menu_gen[(menu_gen.length?menu_gen.length:0)] = id;
	}
}

function clear_all(){
menu_show = new Array();
menu_gen = new Array();
menu_id = "";
menu_status = 0;
getRef('place_menu2').innerHTML = "";
getRef('place_menu').innerHTML = "";
write_menu_l1(menu_x, menu_y);
}