//================================================
//
//  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== 2){
			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 cellpadding=0 cellspacing=0 border=0 width="100%">';
			for(i=0; i<temp_menu.length; i++){
str += '<tr>';
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].img_over:temp_menu[i].img)+'" alt="'+ temp_menu[i].text +'" border="0"></a></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="200">';
str += '<tr>';
str += '<td bgcolor="#4e4e4e"><div style="height: 1px; width: 200px"><spacer type="block" width="200" height="1"></spacer></div></td>';
str += '</tr>';
str += '</table>';
str += '<table border="0" cellspacing="0" cellpadding="0" width="200">';
str += '<tr>';
str += '<td style="background: url(/common/img/menu/u_bg.gif) repeat-y left">';
str += '<table border="0" cellspacing="0" cellpadding="0">';
str += '<tr valign="top">';
str += '<td><img src="/common/img/menu/u_l.gif" width="7" height="35" border="0" alt=""><br></td>';
str += '<td><div style="height: 1px; width: 4px"><spacer type="block" width="4" height="1"></spacer></div></td>';
str += '<td>';
str += '<div style="height: 4px; width: 1px"><spacer type="block" width="1" height="4"></spacer></div>';
str += '<table border="0" cellspacing="0" cellpadding="3" width="192">';
			for(i=0; i<temp_menu.length; i++){
str += '<tr>';
str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();">';
str += '<table border="0" cellspacing="1" cellpadding="7" width="178">';
str += '<tr>';
str += '<td name="td_z_' + index_menu[i] + '" id="td_z_' + index_menu[i] + '" onclick="document.location=\'' + temp_menu[i].url + '\';" class="table-umenu"><a href="' + temp_menu[i].url + '">' + temp_menu[i].text + '</a></td>';
str += '</tr>';
str += '</table>';
str += '</td>';
str += '</tr>';
			}
str += '</table>';
str += '<div style="height: 4px; width: 1px"><spacer type="block" width="1" height="4"></spacer></div>';
str += '</td>';
str += '</tr></table>';
str += '</td></tr>';
str += '</table>';
str += '<table border="0" cellspacing="0" cellpadding="0" width="200">';
str += '<tr>';
str += '<td><div style="height: 1px; width: 6px"><spacer type="block" width="6" height="1"></spacer></div></td>';
str += '<td bgcolor="#4e4e4e"><div style="height: 1px; width: 194px"><spacer type="block" width="194" height="1"></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 - 8;
				menu[index_menu[i]].y = getRef("a" + id).offsetTop + getRef("td_" + index_menu[i]).offsetTop + 7;
			}else{
				menu[index_menu[i]].x = menu_x + getRef("place_menu").offsetLeft + getRef("td_" + index_menu[i]).offsetLeft + 10;
				menu[index_menu[i]].y = menu_y + getRef("place_menu").offsetTop + getRef("td_" + index_menu[i]).offsetTop + 4;
			}
			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);
}
