//================================================
//
//  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 = '';

	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== 1){
			xx = menu[id].x + menu[id].w;
			yy = menu[id].y;
		}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 width="100%" border="0" cellspacing="0" cellpadding="0">';
str += '<tr>';
str += '<td background="/img/bg-menu.gif">';
str += '<table border="0" cellspacing="0" cellpadding="0">';
str += '<tr>';
			for(i=0; i<temp_menu.length; i++){

str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();"><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].table_style:temp_menu[i].img)+'" alt="'+ temp_menu[i].text +'" border="0"></a></td>';

			}
str += '<td><img src="/img/a-menu.gif" width="30" height="30" border="0" alt=""></td>';
str += '</tr>';
str += '</table>';
str += '<table border="0" cellspacing="0" cellpadding="0">';
str += '<tr>';
str += '<td><img src="/img/u-menu.gif" width="450" height="29" border="0" alt=""></td>';
str += '</tr>';
str += '</table>';
str += '</td>';
str += '</tr>';
str += '</table>';


		}else{
			str = "<div id='a" + id + "' style='width: 190px; position: absolute; left: " + xx + "px; top: " + yy + "px; visibility: visible; z-index: 999999;'>";
			str += '<table border="0" cellspacing="0" cellpadding="0" width="201">';
				str += '<tr>';
                str += '<td align="left" colspan="4" background="/img/bgmn.gif"><img src="/img/mv.gif" width="106" height="18" alt="" border="0"></td>';
				str += '<td valign="top" rowspan="20" bgcolor="#0968ac"><img src="/img/menu_left.gif" width="15" height="23" alt="" border="0"></td>';
				str += '</tr>';
			for(i=0; i<temp_menu.length; i++){
                if (i!=0)
				str += '<tr><td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();" colspan="4" background="/img/lin.gif"><div style="height:1px;width:0px"><spacer type="block" height=1></spacer></div></td></tr>';
                str += '<tr bgcolor="#0968ac">';
				str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();"><DIV style="width: 20px;"><SPACER type="block" width="20"></SPACER></DIV></td>';
				str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();"><img src="/img/str.gif" width="3" height="5" alt="" border="0"></td>';
				str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();"><a href="' + temp_menu[i].url + '"><DIV style="width: 7px;"><SPACER type="block" width="7"></SPACER></DIV></td>';
				str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();" class="mm" width="100%"><div style="width: 0px; height: 4px;"><spacer type="block" height="4"></spacer></div><a href="' + temp_menu[i].url + '">' + temp_menu[i].text + '</a><div style="width: 0px; height: 7px;"><spacer type="block" height="7"></spacer></div></td>';
				str += '</tr>';
			}
				str += '<tr>';
				str += '<td  align="left"><img src="/img/mn.gif" width="20" height="13" alt="" border="0"></td>';
				str += '<td colspan="3" bgcolor="#0968ac"><div style="height:13px;width:0px"><spacer type="block" height=13></spacer></div></td>';
				str += '</tr>';
			str += '</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;
				menu[index_menu[i]].y = menu_y + getRef("place_menu").offsetTop + getRef("td_" + index_menu[i]).offsetTop;
			}
			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);
}