//================================================
//
//  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){
	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].td_style >= 2){
			xx = menu[id].x + menu[id].w;
			yy = menu[id].y;
//            alert(yy);
		}else{
			xx = menu_gen.length?menu[id].x:'';
			yy = menu_gen.length?(menu[id].y + menu[id].h):'';
		}

		                                                
if (!menu_gen.length){
    str = '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr align="center">';
	for(i=0; i<temp_menu.length; i++){
    if (temp_menu[i].div_style == 1 && temp_menu[i].pid == 0){
        str += '<td width="20%" id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onclick="document.location=\'' + temp_menu[i].url + '\';" class="table-umenu-o"><a href="'+ temp_menu[i].url + '"><img src="'+ temp_menu[i].img_over +'" border="0" alt="' + temp_menu[i].text +'" vspace="2"></a></td>';
/*
str += '<td width="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] + ');" onmouseout="td_menu_out();" class="table-tmenu"><a href="'+ temp_menu[i].url + '"><img src="'+ temp_menu[i].img+'" border="0" alt="' + temp_menu[i].text +'" vspace="2"></a></td>';
*/
    }else{
        str += '<td width="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-tmenu-s\'" onmouseout="td_menu_out();" class="table-tmenu"><a href="'+ temp_menu[i].url + '"><img src="'+ temp_menu[i].img+'" border="0" alt="' + temp_menu[i].text +'" vspace="2"></a></td>';
    }

    if ((temp_menu.length-1) != i ){
        str += '<td><img src="/common/img/menu/m-hr.gif" width="2" height="45" border="0" alt=""><br></td>';
    }
/*
str += '<td width="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-tmenu-s\'" onmouseout="td_menu_out();" class="table-tmenu"><a href="'+ temp_menu[i].url + '"><img src="'+ temp_menu[i].img+'" border="0" alt="' + temp_menu[i].text +'" vspace="2"></a></td>';
*/
}

str += '<td valign="top"><img src="/common/img/menu/m-hr-last.gif" width="1" height="39" border="0" alt=""><br></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 border="0" cellspacing="0" cellpadding="0" width="' + (getRef("td_" + id).offsetWidth) + '">';
			for(i=0; i<temp_menu.length; i++){
                if ((temp_menu.length-1) != i ){
                if (temp_menu[i].child == 1){
str += '<tr>';
str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '">';
str += '<table border="0" cellspacing="0" cellpadding="0" width="' + (getRef("td_" + id).offsetWidth) + '">';
str += '<tr>';
str += '<td 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-s\';" onmouseout="td_menu_out();this.className = \'table-umenu\';" class="table-umenu">';
str += '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
str += '<tr>';
str += '<td><div style="height: 30px; width: 15px;"><spacer type="block" width="30" height="15"></spacer></div></td>';
str += '<td width="100%"><a href="' + temp_menu[i].url + '">' + temp_menu[i].text + '</a> <img src="/common/img/menu/n-next.gif" width="6" height="5" border="0" alt="" align="absmiddle" hspace="3"></td>';
str += '<td><div style="height: 30px; width: 15px;"><spacer type="block" width="30" height="15"></spacer></div></td>';
str += '</tr>';
str += '</table>';
str += '</td>';
str += '</tr>';
str += '</table>';
str += '</td><td bgcolor="#ffffff"><div style="height: 0px; width: 1px;"><spacer type="block" width="1"></spacer></div></td>';
str += '</tr>';
                }else{
str += '<tr>';
str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '">';
str += '<table border="0" cellspacing="0" cellpadding="0" width="' + (getRef("td_" + id).offsetWidth) + '">';
str += '<tr>';
str += '<td 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-s\';" onmouseout="td_menu_out();this.className = \'table-umenu\';" class="table-umenu">';
str += '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
str += '<tr>';
str += '<td><div style="height: 30px; width: 15px;"><spacer type="block" width="30" height="15"></spacer></div></td>';
str += '<td width="100%"><a href="' + temp_menu[i].url + '">' + temp_menu[i].text + '</a></td>';
str += '<td><div style="height: 30px; width: 15px;"><spacer type="block" width="30" height="15"></spacer></div></td>';
str += '</tr>';
str += '</table>';
str += '</td>';
str += '</tr>';
str += '</table>';
str += '</td><td bgcolor="#ffffff"><div style="height: 0px; width: 1px;"><spacer type="block" width="1"></spacer></div></td>';
str += '</tr>';
                }

            
                }else{
                if (temp_menu[i].child == 1){
str += '<tr>';
str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '">';
str += '<table border="0" cellspacing="0" cellpadding="0" width="' + (getRef("td_" + id).offsetWidth) + '">';
str += '<tr>';
str += '<td 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-s\';" onmouseout="td_menu_out();this.className = \'table-umenu-l\';" class="table-umenu-l">';
str += '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
str += '<tr>';
str += '<td><div style="height: 30px; width: 15px;"><spacer type="block" width="30" height="15"></spacer></div></td>';
str += '<td width="100%"><a href="' + temp_menu[i].url + '">' + temp_menu[i].text + '</a> <img src="/common/img/menu/n-next.gif" width="6" height="5" border="0" alt="" align="absmiddle" hspace="3"></td>';
str += '<td><div style="height: 30px; width: 15px;"><spacer type="block" width="30" height="15"></spacer></div></td>';
str += '</tr>';
str += '</table>';
str += '</td>';
str += '</tr>';
str += '</table>';
str += '</td><td bgcolor="#ffffff"><div style="height: 0px; width: 1px;"><spacer type="block" width="1"></spacer></div></td>';
str += '</tr>';
                }else{
str += '<tr>';
str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '">';
str += '<table border="0" cellspacing="0" cellpadding="0" width="' + (getRef("td_" + id).offsetWidth) + '">';
str += '<tr>';
str += '<td 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-s\';" onmouseout="td_menu_out();this.className = \'table-umenu-l\';" class="table-umenu-l">';
str += '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
str += '<tr>';
str += '<td><div style="height: 30px; width: 15px;"><spacer type="block" width="30" height="15"></spacer></div></td>';
str += '<td width="100%"><a href="' + temp_menu[i].url + '">' + temp_menu[i].text + '</a></td>';
str += '<td><div style="height: 30px; width: 15px;"><spacer type="block" width="30" height="15"></spacer></div></td>';
str += '</tr>';
str += '</table>';
str += '</td>';
str += '</tr>';
str += '</table>';
str += '</td><td bgcolor="#ffffff"><div style="height: 0px; width: 1px;"><spacer type="block" width="1"></spacer></div></td>';
str += '</tr>';
                }

             
                }
			}
            
str += '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
str += '<tr>';
str += '<td bgcolor="#ffffff"><div style="height: 1px; width: 0px;"><spacer type="block" height="1"></spacer></div></td>';
str += '<td bgcolor="#ffffff"><div style="height: 0px; width: 1px;"><spacer type="block" width="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;
				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 + 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(){
	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);
}