// settings
var num_of_submenu=21;
var overcolor='#e7e7e7';
var outcolor='#f7f7f7';

// system variables
var ie5=false;
var ns6=false;
var ns4=false;
var timer=null;
var loaded=false;
var offset_x=0;
var offset_y=32;
var main_menu_items=new Array;
var last_opened=null;

// basic browser detection
if (document.getElementById && document.all) {ie5=true};
if (document.getElementById && !document.all) {ns6=true};
if (document.layers) {ns4=true};

//window.onload=init();
//window.onresize=init();

function init() {
	// set X, Y positions
	for (a=first_menu;a<=last_menu;a++) {
		if (document.images['menu'+a]) {
		posMenu('submenu'+a,getXYcoord('menu'+a).x,getXYcoord('menu'+a).y+offset_y);
		}
	}
	// let's start the fun
	loaded=true;
}

// get position
function getXYcoord ( nvn ) {
   var elm = document.images[nvn];
   if ( ns4 ) return elm;
   // NS4 images contain x and y values
   var rd = { x:0 ,y:0 };
   do { rd.x += parseInt( elm.offsetLeft );
        rd.y += parseInt( elm.offsetTop );
        elm = elm.offsetParent;
   } while ( elm );
   return rd
}; //end getXYcoord ( string ) -> object{x,y}


function startTimer() {
	timer=setTimeout('hideActiveMenu()',1000);
};


function stopTimer() {
	clearTimeout(timer);
};

function hideActiveMenu() {
	if (!loaded || last_opened==null) {return false;};

		if(ns6)	{
			document.getElementById(last_opened).style.visibility='hidden';
			}

		if(ie5)	{
			eval('document.all.'+last_opened).style.visibility='hidden';
			}

		if(ns4)	{
			eval('document.layers.'+last_opened).visibility='hide';
			}
	last_opened=null;
}

function showMenu(menu_id) {
	if (!loaded) {return false;};
	stopTimer();
	hideActiveMenu();

		if(ns6)	{
			document.getElementById(menu_id).style.visibility='visible';
			}

		if(ie5)	{
			eval('document.all.'+menu_id).style.visibility='visible';
			}

		if(ns4)	{
			eval('document.layers.'+menu_id).visibility='show';
			}
	last_opened=menu_id;
}

function posMenu(menu_id,xpos,ypos) {
		if(ns6)	{
			document.getElementById(menu_id).style.top=ypos+'px';
			document.getElementById(menu_id).style.left=xpos+'px';
			}

		if(ie5)	{
			eval('document.all.'+menu_id).style.top=ypos;
			eval('document.all.'+menu_id).style.left=xpos;
			}

		if(ns4)	{
			eval('document.layers.'+menu_id).top=ypos;
			eval('document.layers.'+menu_id).left=xpos;
			}
}

function co(which) {
which.bgColor=overcolor;
stopTimer();
}

function cout(which) {
which.bgColor=outcolor;
startTimer();
}



function generateMenu() {
code='';
for (a=first_menu;a<=last_menu;a++) {
	code=code+'<div id="submenu'+a+'" class="submenu">'+"\n";
	code=code+'<table class="menutable" border="0" cellspacing="1" cellpadding="2" width="150" bgcolor="'+outcolor+'">'+"\n";
		b=0;
		do {
			code=code+'<tr><td class="menucell" onmouseover="co(this)" onmouseout="cout(this)" bgColor="'+outcolor+'" onclick="jumpTo(\''+menuitems[a][b][1]+'\')" nowrap>';
			code=code+'<a href="'+menuitems[a][b][1]+'" class="dropdown">&nbsp;'+menuitems[a][b][0]+'&nbsp</a></td></tr>'+"\n";
			//code=code+'<tr><td bgcolor=#ffffff><img src="/images/nyito_hirelvalaszto.gif" border="0" alt=""></td></tr>';
			b++;
		} while (menuitems[a][b][0]!=null);
	code=code+'</table>'+"\n";
	code=code+'</div>'+"\n";
	}
document.write(code);
}

// megadott URL-re atiranyitja a bongeszot
function jumpTo(url) {
window.top.location=url;
}
