
var ctrlimg=new Array();
ctrlimg[0]=new Image; ctrlimg[0].src="img/menu-c.gif";
ctrlimg[1]=new Image; ctrlimg[1].src="img/menu-o.gif";


function swapImage(i) {
	if (i==null) return;
	if (i.src==ctrlimg[0].src) {
		i.src=ctrlimg[1].src;
	} else {
		i.src=ctrlimg[0].src;
	}
}

function findMenu(menu) {
	if (window.menus) return window.menus[menu];
	return null;
}

// show menu if exists
function sMiE(menuname) {
	var m=findMenu(menuname);
	if (m) {
		m.parentid=m.parentid;
		m.showMenu(0, 0)
		m.showParents();
	}
}



function Menu(menuid, parentid) {
	this.menuid=menuid;
	this.parentid=parentid;

	if (!window.menus) window.menus=new Array();

	window.menus[window.menus.length]=this;
	window.menus[this.menuid]=this;

	this.menu=null;
	this.parentMenu=null;
	this.visibility=false;
	this.level=0;

	this.registerMenu=registerMenu;
	this.showParents=showParents;
	this.hideMenu=hideMenu;
	this.hideSubmenus=hideSubmenus;
	this.hideSisters=hideSisters;
	this.registerChild=registerChild;

	this.showMenu=showMenu;

	this.children=null;
}


function registerMenu() {

	var menu=window.menus[this.parentid];
	this.parentMenu=menu;

//	this.width1=width1;

	if (document.layers) {
		menu=document.layers[this.menuid];
	} else if (document.all || document.getElementById) {
		menu=document.getElementById(this.menuid);
	}
	this.menu=menu;

//	window.menus2[window.menus2.length]=this;
//	window.menus2[this.menuid]=this;

	if (this.parentMenu) {
		this.parentMenu.registerChild(this);
//		alert("registered menu " + this.menuid + " to parent menu " + this.parentMenu.menuid + " " + this.menu);
	} else {
//		alert("registered menu " + this.menuid + " to no parent" + this.menu);
	}
}



function registerMenus() {

	if (!window.menus) window.menus=new Array();

	for (i=0; i<window.menus.length; i++) {
		th=window.menus[i];
		th.registerMenu();
	}
}

function showParents() {
	if (this.parentMenu && this.parentMenu.menu) {
		if (document.layers)
			this.parentMenu.menu.visibility=visibility;
		else {
			this.parentMenu.menu.style.visibility="visible";
			this.parentMenu.menu.style.display="inline";
		}
		this.parentMenu.showParents();
	}
}

function registerChild(menu) {
	if (!this.children) this.children=new Array();
	this.children[this.children.length]=menu;
	menu.level=this.level+1;
}

function hideSisters() {
	if (this.parentMenu && this.parentMenu.children) {
		for (var i=0; i<this.parentMenu.children.length; i++) {
			this.parentMenu.children[i].hideMenu();
		}
	}
}


function showMenu(A, B) {
	if (!this) return;

	if (!this.menu) {
		this.menu=document.getElementById(this.menuid);
	}

//	if (this.visible) return;

//	this.hideSisters();

//	if (!this.pos) this.pos=getXYcoord( 'pixel_' + A);

	if (document.layers) {
/*		eval("document.height")
		this.menu.zindex=1000;
		if (this.parentMenu.menu) {
			this.menu.left=this.pos.X;
			this.menu.top=this.pos.Y;
		} else {
			this.menu.left=this.pos.X;
			this.menu.top=this.pos.Y;
		}
		this.menu.visibility="visible";
		this.visible=true;
*/	}
	else if (document.all || document.getElementById)
	{
   	  if (this.parentMenu) {
//	    this.menu.style.left = this.pos.x;
//	    this.menu.style.top = this.pos.y;
		} else {
//	    this.menu.style.left = this.pos.x+5;
//	    this.menu.style.top = this.pos.y+8;
		}
		this.menu.style.visibility="visible";
	  this.menu.style.display="inline";
	  this.visible=true;
	}
}

function getXYcoord ( pixel ) {
     var el = document.images[pixel];
     if ( document.layers ) return el;
     var xy = { x:0 ,y:0 };
     do { xy.x += parseInt( el.offsetLeft );
        xy.y += parseInt( el.offsetTop );
        el = el.offsetParent;
     } while ( el );
   xy.x++; xy.y--;
   return xy;
}

function hideMenu() {
	if (!this.menu) return;
	if (!this.visible) return;

	this.hideSubmenus();
	if (document.layers) {
		this.menu.visibility="hidden";
	} else {
		this.menu.style.visibility="hidden";
		this.menu.style.display="none";
	}

	this.visible=false;
}

function hideSubmenus() {
	if (this.children) {
		for (var i=0; i<this.children.length; i++)
			this.children[i].hideMenu();
	}
}

new Menu('root', 'rooter');