//================================================
//
//  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){
	if (!isDOM) return true;
menu_x = ox;
menu_y = oy;
write_menu_custom(0);
}
function write_menu_other(){
	if (!isDOM) return true;
}
function write_menu_custom(id){
browserName = navigator.appName;
var vvv=0;
if (browserName == "Microsoft Internet Explorer") {
	vvv=15;
}

	if (!isDOM) return true;
	var temp_menu = new Array();
	var index_menu = new Array();
	var str = '';


	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].pid == 0){
			xx = menu[id].x;
			yy = menu[id].y + menu[id].h;
		}
		if (menu_gen.length && menu[id].pid != 0){
			xx = menu[id].x + menu[id].w-vvv;
			yy = menu[id].y;
		}
		 
		
		                                                
if (!menu_gen.length){
    str = '<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td></td><td background="/common/img/bg111.gif" style="background-repeat: repeat-y;"><DIV style="width: 26px; height: 38px;"><SPACER type="block" width="26" height="38"></SPACER></DIV></td>';
	for(i=0; i<temp_menu.length; i++){
    	if (i==0) {
			str +='<td onmouseover="td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();" id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" valign="bottom" align="right" nowrap class="table-o'+(temp_menu[i].div_style == 1 ? 'n' : '')+'"><img src="/common/img/sp.gif" alt="" width="8" height="19" border="0" vspace="7" align="absmiddle"><a href="'+ temp_menu[i].url + '">'+ temp_menu[i].text +'</a><img src="/common/img/sp.gif" alt="" width="8" height="1" border="0" align="absmiddle"></td>';
		}else{
			str +='<td onmouseover="td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();" id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" valign="bottom" align="right" nowrap class="table-o'+(temp_menu[i].div_style == 1 ? 'n' : '')+'"><img src="/common/img/line.gif" vspace="7" alt="" width="1" height="19" border="0" align="absmiddle"><img src="/common/img/sp.gif" alt="" width="8" height="1" border="0" align="absmiddle"><a href="'+ temp_menu[i].url + '">'+ temp_menu[i].text +'</a><img src="/common/img/sp.gif" alt="" width="8" height="19" border="0" align="absmiddle" vspace="7"></td>'; 
		}
	}
    str += '<td><DIV style="width: 14px;"><SPACER type="block" width="14"></SPACER></DIV></td><td></td></tr><tr><td width="50%"></td><td background="/common/img/bg111.gif" style="background-repeat: no-repeat;"><DIV style="width: 26px; height: 2px;"><SPACER type="block" width="26" height="2"></SPACER></DIV></td><td colspan="22"><DIV style="width: 965px; height: 1px;"><SPACER type="block" width="965" height="1"></SPACER></DIV></td><td width="50%"></td></tr></table>';
}else{
	str = "<div id='a" + id + "' name='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" class="tab-b"><tr><td><DIV style="width: 0px; height: 15px;"><SPACER type="block" width="1" height="15"></SPACER></DIV></td></tr>';
	//svik's versuch
		str +='<tr><td><table cellpadding="0" cellspacing="0" border="0">';
	//end svik's versuch
	for(i=0; i<temp_menu.length; i++){
	//svik's versuch
		//str +='<tr><td width="21"><DIV style="width: 19px; height: 1px;"><SPACER type="block" width="19" height="1"></SPACER></DIV></td><td><table cellpadding="0" cellspacing="0" border="0">';
	//end svik's versuch
		str += '<tr><td style="padding: 0px 20px 5px 20px;" onclick="document.location=\'' + temp_menu[i].url + '\';" id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" nowrap onmouseover=" td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();"><a href="'+ temp_menu[i].url + '">'+ temp_menu[i].text +'</a></td></tr>'; 
	//svik's versuch
		//str +='</table></td><td width="55"><DIV style="width: 55px; height: 1px;"><SPACER type="block" width="55" height="1"></SPACER></DIV></td></tr>';
		//end svik's versuch   
	}
	//svik's versuch
	str +='</table></td></tr>';
	//end svik's versuch
    str += '<tr><td><DIV style="width: 0px; height: 18px;"><SPACER type="block" width="1" height="18"></SPACER></DIV></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(){
	if (!isDOM) return true;
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);
}
