function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var mainmenu;
var pulldowns = new Array();

window_onload = function()
{
	mainmenu = new MainMenu('mainmenu');
	w = xGetElementById('bodytable').style.width;
	for (i in pulldowns)
	{
		new PullDownMenu(mainmenu, pulldowns[i][0],pulldowns[i][1],pulldowns[i][2]);
	}
	/*if (home_page)
	{
		zsidemenu = xGetElementById('sidemenu');
		if (zsidemenu)
		{
			xTableIterate(zsidemenu, sideMenuInit);
		}
	}*/
}

function smMouseOver()
{
	this.className = 'sidemenuitemH';
}

function smMouseOut()
{
	this.className = 'sidemenuitem';
}

function smMouseClick()
{
	for (i in this.childNodes)
	{
		if (this.childNodes[i].tagName == 'A')
		{
			document.location = this.childNodes[i].href;
		}
	}
}
function sideMenuInit(item,data)
{
	if (item.className == 'sidemenuitem')
	{
		item.onmouseover = smMouseOver;
		item.onmouseout = smMouseOut;
		item.onclick = smMouseClick;
	}
}

function xGetElementById(e)
{
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}

// documentation is available for this function:
function xTableIterate(sec, fnCallback,data)
{
  var r, c;
  sec = xGetElementById(sec);
  if (!sec || !fnCallback) { return; }
  for (r = 0; r < sec.rows.length; ++r)
  {
    for (c = 0; c < sec.rows[r].cells.length; ++c)
	{
      fnCallback(sec.rows[r].cells[c],data);
    }
  }
}

// Find the x,y location in pixels for a relatively positioned object
// returns an object with .x and .y properties.
function FindXY(obj){
	var x=0,y=0;
	while (obj!=null){
		x+=obj.offsetLeft;
		y+=obj.offsetTop;

//		x+=obj.offsetLeft-obj.scrollLeft;
//		y+=obj.offsetTop-obj.scrollTop;
		obj=obj.offsetParent;
	}
	return {x:x,y:y};
}

// Find the x,y location in pixels for a relatively positioned object
// returns an object with .x, .y, .w (width) and .h (height) properties.
function FindXYWH(obj){
	var objXY = FindXY(obj);
//	return objXY?{ x:objXY.x, y:objXY.y, w:obj.style.width, h:obj.style.height }:{ x:0, y:0, w:0, h:0 };
	return objXY?{ x:objXY.x, y:objXY.y, w:obj.offsetWidth, h:obj.offsetHeight }:{ x:0, y:0, w:0, h:0 };
}

function MainMenu(id)
{
	var items =  new Array();
	this.submenus = new Array();
	this.insideMenu = false;
	this.id=id;
	var tbl = xGetElementById(id);
	if (tbl)
	{
		xTableIterate(tbl,init);
	}
	this.items = items;
	this.addSubMenu = addSubMenu;

	function init(item,data)
	{
		if (item.className == 'menuitem')
		{
			item.onmouseover = evOver;
			item.onmouseout = evOut;
			items[item.id] = item;
		}
	}

	function evOver()
	{
		this.className = 'menuitemH';
		
		if (this.getAttribute('first_m')=='1')
		{
			MM_swapImage('l'+this.id,'','/img/l_over.png',1);
		}
		else
		{
			MM_swapImage('l'+this.id,'','/img/mleft_over.jpg',1);
		}

		if (this.getAttribute('last_m')=='1')
		{
			MM_swapImage('r'+this.id,'','/img/r_over.png',1);
		}
		else
		{
			MM_swapImage('r'+this.id,'','/img/mright_over.jpg',1);
		}
		//document.getElementById('left_image')
		
		mainmenu.insideMenu = true;
		mainmenu.insideSubMenu = false;
		for (var i in mainmenu.submenus)
		{
			if (i != this.id)
				mainmenu.submenus[i].elmnt.style.display='none';
		}

		if (mainmenu.submenus[this.id] != null)
		{
			var pos = FindXYWH(this);
			mainmenu.submenus[this.id].elmnt.style.top = pos.y+35;

			pos = FindXYWH(mainmenu.submenus[this.id].anchor);
			mainmenu.submenus[this.id].elmnt.style.left = pos.x;
			//mainmenu.submenus[this.id].elmnt.style.width = pos.w+56;
			mainmenu.submenus[this.id].elmnt.style.display='block';
		}

	}

	function evOut()
	{
		this.className = 'menuitem';
		
		if (this.getAttribute('first_m')=='1')
		{
			MM_swapImage('l'+this.id,'','/img/l.png',1);
		}
		else
		{
			MM_swapImage('l'+this.id,'','/img/mleft.jpg',1);
		}

		if (this.getAttribute('last_m')=='1')
		{
			MM_swapImage('r'+this.id,'','/img/r.png',1);
		}
		else
		{
			MM_swapImage('r'+this.id,'','/img/mright.jpg',1);
		}
		
		mainmenu.insideMenu = false;
		
		//setTimeout("hideMenu();hideImgs('"+this.id+"');", 500);
		setTimeout("hideMenu();", 500);
	}

	function addSubMenu(itemid,submenu)
	{
		this.submenus[itemid] = submenu;
		// setting submenu position
		var pos = FindXYWH(items[itemid]);
		submenu.elmnt.style.position = 'absolute';
		submenu.elmnt.style.left = pos.x;
		//submenu.elmnt.style.width = pos.w+56;
		submenu.elmnt.style.top = pos.y+35;
		xTableIterate(submenu.elmnt,setwidth, 0);
	}
	function setwidth(obj,data)
	{
		obj.style.width = data;
	}
}

function hideMenu()
{

	if (!( mainmenu.insideMenu || mainmenu.insideSubMenu))
	{
		for (var i in mainmenu.submenus)
		{
			mainmenu.submenus[i].elmnt.style.display='none';
		}

		
	}
}

/*function hideImgs(iid)
{
	MM_swapImage('left_image_'+iid,'','/img/border_menu_left.gif',1);
	MM_swapImage('right_image_'+iid,'','/img/border_menu_right.gif',1);
	//alert('kuku');
}*/

var hColor;

function PullDownMenu(mainmenu, id, anchorId, hiliteColor)
{
	this.elmnt = xGetElementById(id);

	this.anchor = xGetElementById(anchorId);
	this.elmnt.onmouseover = mOverMenu;
	this.elmnt.onmouseout = mOutMenu;
	this.hiliteColor = hiliteColor;

	this.elmnt.pulldown = this;
	var tbl = xGetElementById(id);
	xTableIterate(this.elmnt,init,this);

	mainmenu.addSubMenu(anchorId,this);

	function init(obj,data)
	{
		obj.className = 'submenuitem';
		obj.onmouseover = evOver;
		obj.onmouseout = evOut;
		obj.onclick = evClick;
		//obj.hiliteColor = data.hiliteColor;
	}

	function evClick()
	{
		for (i in this.childNodes)
		{
			if (this.childNodes[i].tagName == 'A')
			{
				document.location = this.childNodes[i].href;
			}
		}
	}
	function evOver()
	{
		this.className = 'submenuitemH';
//		this.style.borderLeftColor = this.hiliteColor;
//		this.style.borderRightColor = this.hiliteColor;
	}
	function evOut()
	{
		this.className = 'submenuitem';
//		this.style.borderLeftColor = '#808080';
//		this.style.borderRightColor = '#808080';
	}

	function mOverMenu()
	{
		mainmenu.insideSubMenu = true;
	}
	function mOutMenu()
	{
		mainmenu.insideSubMenu = false;
		//setTimeout("hideMenu();hideImgs('"+this.id+"');", 500);
		setTimeout("hideMenu();", 500);
	}
}

