//================================================
//
//  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].pid!=0){
			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):'';
		}
		                                                
		if (!menu_gen.length){
str = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#FFFFFF" width="100%"><table width="100%" border="0" cellspacing="10" cellpadding="0"><tr>';
			for(i=0; i<temp_menu.length; i++){
str += '<td width="25%" id="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();">';
str += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
str += '<tr bgcolor="#0E324A">';
str += '<td><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 += '<td align="right"><img src="/common/img/td/menu-arr.gif" width="30" height="30" border="0" alt=""></td>';
str += '</tr>';
str += '</table>';
str += '</td>';
			}
str += '</tr></table></td><td bgcolor="#F4CB1A"><div style="width: 10px; height: 0px;"><spacer type="block" width="10"></spacer></div></td></tr></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 width="100%" border="0" cellspacing="0" cellpadding="5">';
			for(i=0; i<temp_menu.length; i++){
                if (i!=0)
				str += '<tr>';
				str += '<td onclick="document.location=\'' + temp_menu[i].url + '\';" onmouseover="this.style.backgroundColor=\'#155987\'; td_menu_over(' + index_menu[i] + ');" onmouseout="this.style.backgroundColor=\'#0E324A\'; td_menu_out();" style="border-top: 1px solid #155987;" bgcolor="#0E324A" id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();" width="100%" class="lblue"><a href="' + temp_menu[i].url + '" class="w_menu">' + temp_menu[i].text + '</a></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 + 210;
				menu[index_menu[i]].y = menu_y + getRef("place_menu").offsetTop + getRef("td_" + index_menu[i]).offsetTop + 1;
			}
			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);
}