function menuClass(){
	this.data = null;
	this.container = null;
	this.openBranch = "-1";
	this.hideTimer;
	this.rootOffsetLeft = 1;	
	this.rootOffsetTop = -2;
	this.childOffsetLeft = 1;	
	this.childOffsetTop = -2;
	this.drawGorMenu = function(){
		var table = document.createElement("TABLE");
		table.className = "menuRootTable";
		table.cellPadding = 0;
		table.cellSpacing = 0;
		var td, data, i, a;
		this.container.appendChild(table);
		var tbody = document.createElement("TBODY");
		table.appendChild(tbody);		
		var tr = document.createElement("TR");
		tbody.appendChild(tr);
		data = this.findChilds(-1);
		for (i in data){
			td = document.createElement("TD");
			tr.appendChild(td);
			td.noWrap = true;			
			td.className = "menuRoot";
			a = document.createElement("A");
			a.className = "menuA";
			a.appendChild(document.createTextNode(data[i].text));
			a.href = data[i].url;
			td.appendChild(a);
			td.url = data[i].url;
			td.onclick = function (){window.location = this.url;}
			//td.tabIndex = 1;
			td.noWrap = true;
			childs = this.findChilds(i);
			data[i].haveCHilds = false;
			if (childs.length > 0){
				td.className = "menuRootChilds";
				this.data[i].haveChilds = true;
				td.childObj = this.drawChilds(childs, td, "left", "bottom", this.rootOffsetLeft, this.rootOffsetTop);
				this.data[i].table = td.childObj;
			}
			this.data[i].owner = td;			
			a.nodeID = i;
			a.menuObj = this;
			a.onmouseover = this.showChild;
			a.onfocus = this.showChild;
			a.onkeydown = this.keyDownGor;
			a.onmouseout = this.outBranch;
			a.onblur = this.outBranch;
		}
	}
	this.drawVertMenu = function(){
		var table = document.createElement("TABLE");
		table.cellPadding = 0;
		table.cellSpacing = 0;
		var tr, td, data, i, a;
		this.container.appendChild(table);
		var tbody = document.createElement("TBODY");
		table.appendChild(tbody);		
		table.className = "menuRootTable";
		data = this.findChilds(-1);
		for (i in data){
			tr = document.createElement("TR");
			tbody.appendChild(tr);
			td = document.createElement("TD");
			tr.appendChild(td);
			td.noWrap = true;			
			td.className = "menuRoot";
			a = document.createElement("A");
			a.className = "menuA";
			a.appendChild(document.createTextNode(data[i].text));
			a.href = data[i].url;
			td.appendChild(a);
			td.url = data[i].url;
			//td.tabIndex = 1;
			td.onclick = function (){window.location = this.url;}
			td.noWrap = true;
			childs = this.findChilds(i);
			data[i].haveCHilds = false;
			if (childs.length > 0){
				td.className = "menuRootChilds";
				this.data[i].haveChilds = true;
				td.childObj = this.drawChilds(childs, td, "right", "top", this.rootOffsetLeft, this.rootOffsetTop);
				this.data[i].table = td.childObj;
			}
			this.data[i].owner = td;			
			a.nodeID = i;
			a.menuObj = this;
			a.onmouseover = this.showChild;
			a.onfocus = this.showChild;
			a.onkeydown = this.keyDown;
			a.onmouseout = this.outBranch;
			a.onblur = this.outBranch;
/*						
			td.nodeID = i;
			td.menuObj = this;
			td.onmouseover = this.showChild;
			td.onfocus = this.showChild;
			td.onkeydown = this.keyDown;
			td.onmouseout = this.outBranch;
			td.onblur = this.outBranch;
*/			
		}
	}	
	this.drawChilds = function (data, container, gorPos, vertPos, offsetLeft, offsetTop){
		var table = document.createElement("TABLE");
		table.style.position = "absolute";
		table.className = "menuChildTable";
		if (gorPos == "right") table.style.left = this.countOffsetLeft(container) + container.offsetWidth + offsetLeft;
		else table.style.left = this.countOffsetLeft(container) + offsetLeft;
		if (vertPos == "bottom") table.style.top = this.countOffsetTop(container) + container.offsetHeight + offsetTop;
		else table.style.top = this.countOffsetTop(container) + offsetTop;
		table.cellPadding = 0;
		table.cellSpacing = 1;
		var td, tr, childs, i, a;
		this.container.appendChild(table);
		var tbody = document.createElement("TBODY");
		table.appendChild(tbody);		
		for (i in data){
 			tr = document.createElement("TR");
			tbody.appendChild(tr);			
			td = document.createElement("TD");
			tr.appendChild(td);
			td.noWrap = true;			
			td.className = "menu";
			a = document.createElement("A");
			a.className = "menuA";
			a.appendChild(document.createTextNode(data[i].text));
			a.href = data[i].url;
			td.appendChild(a);
			td.url = data[i].url;
			//td.tabIndex = 1;
			td.noWrap = true;
			td.onclick = function (){window.location = this.url;}
			childs = this.findChilds(i);
			data[i].haveCHilds = false;
			if (childs.length > 0){
				td.className = "menuChilds";
				this.data[i].haveChilds = true;
				td.childObj = this.drawChilds(childs, td, "right", "top", this.childOffsetLeft, this.childOffsetTop);
				this.data[i].table = td.childObj;
			}
			this.data[i].owner = td;
			a.nodeID = i;
			a.menuObj = this;
			a.onmouseover = this.showChild;
			a.onfocus = this.showChild;
			a.onkeydown = this.keyDown;
			a.onmouseout = this.outBranch;
			a.onblur = this.outBranch;
		}		
		table.style.visibility = "hidden";
		return table;
	}	
	this.findChilds = function (nodeID){
		var childs = new Array();
		var i;
		for (i in this.data){
			if (this.data[i].parent == nodeID)
				childs[i] = this.data[i];
		}
		return childs;
	}
	this.showChild = function (){
		window.clearTimeout(this.menuObj.hideTimer);
		if (this.menuObj.openBranch.indexOf(this.menuObj.data[this.nodeID].parent) != -1){
			var node;
			var openBranch = this.menuObj.openBranch.split(",");
			while (node = openBranch.pop()){
				if (node != this.menuObj.data[this.nodeID].parent){
					this.menuObj.data[node].owner.className = (this.menuObj.data[node].parent==-1?"menuRoot":"menu");
					if (this.menuObj.data[node].haveChilds){
						this.menuObj.data[node].owner.className = (this.menuObj.data[node].parent==-1?"menuRootChilds":"menuChilds");
						this.menuObj.data[node].table.style.visibility = "hidden";
					}
				}else{
					openBranch.push(node);
					break;
				}
			}
			this.menuObj.openBranch = "" + this.menuObj.implode(openBranch);
		}
		this.menuObj.openBranch += "," + this.nodeID;
		this.parentNode.className = (this.menuObj.data[this.nodeID].parent==-1?"menuRootOver":"menuOver");
		if (this.menuObj.data[this.nodeID].haveChilds){
			this.parentNode.className = (this.menuObj.data[this.nodeID].parent==-1?"menuRootOverChilds":"menuOverChilds");
			this.parentNode.childObj.style.visibility = "visible";
		}
	}	
	this.keyDown = function (e){
		var evt = e?e:event;
		if (evt.keyCode == 40 && this.parentNode.parentNode.nextSibling){
			this.parentNode.parentNode.nextSibling.firstChild.firstChild.focus();
		}
		if (evt.keyCode == 38 && this.parentNode.parentNode.previousSibling){
			this.parentNode.parentNode.previousSibling.firstChild.firstChild.focus();
		}
		if (evt.keyCode == 39 && this.menuObj.data[this.nodeID].haveChilds){
			this.menuObj.data[this.nodeID].table.firstChild.firstChild.firstChild.firstChild.focus();
		}
		if (evt.keyCode == 37 && this.menuObj.data[this.nodeID].parent != -1){
			this.menuObj.data[this.menuObj.data[this.nodeID].parent].owner.firstChild.focus();
		}else if (evt.keyCode == 37 && this.menuObj.data[this.nodeID].parent == -1){
			this.blur();
		}
		
		if (evt.keyCode == 13){
			this.click();
		}
		return false;
		//alert (this.parentNode.nextSibling.firstChild.tagName);
	}
	this.keyDownGor = function (){
		if (event.keyCode == 39 && this.parentNode.nextSibling){
			this.parentNode.nextSibling.firstChild.focus();
		}
		if (event.keyCode == 37 && this.parentNode.previousSibling){
			this.parentNode.previousSibling.firstChild.focus();
		}
		if (event.keyCode == 40 && this.menuObj.data[this.nodeID].haveChilds){
			this.menuObj.data[this.nodeID].table.firstChild.firstChild.firstChild.firstChild.focus();
		}
		if (event.keyCode == 38 && this.menuObj.data[this.nodeID].parent != -1){
			this.menuObj.data[this.menuObj.data[this.nodeID].parent].owner.firstChild.focus();
		}else if (event.keyCode == 38 && this.menuObj.data[this.nodeID].parent == -1){
			this.blur();
		}
		
		if (event.keyCode == 13){
			this.click();
		}
		return false;
		//alert (this.parentNode.nextSibling.firstChild.tagName);
	}	
	this.outBranch = function (){
		window.status = "";
		window.clearTimeout(this.menuObj.hideTimer);
		this.menuObj.hideTimer = window.setTimeout("window."+this.menuObj.name+".hideBranch()", 1000);
	}
	this.hideBranch = function (){
		var node;
		var openBranch = this.openBranch.split(",");
		while (node = openBranch.pop()){
			if (node != -1){
				this.data[node].owner.className = (this.data[node].parent==-1?"menuRoot":"menu");
				if (this.data[node].haveChilds){
					this.data[node].owner.className = (this.data[node].parent==-1?"menuRootChilds":"menuChilds");
					this.data[node].table.style.visibility = "hidden";
				}
			}else{
				openBranch.push(node);
				break;
			}
		}
		this.openBranch = "" + this.implode(openBranch);
	}
	this.countOffsetLeft = function (obj){
		var offset = 0;
        while (obj.tagName != "BODY"){
        	if (obj.tagName != "TR")
            offset += obj.offsetLeft;
            if (obj.style.position == "absolute") break;
            obj = obj.parentNode;
        }
        return offset;
	}
	this.countOffsetTop = function (obj){
		var offset = 0;
        while (obj.tagName != "BODY" /*&& obj.style.position != "absolute"*/){
            if (obj.tagName != "TR")
            offset += obj.offsetTop;
            if (obj.style.position == "absolute") break;
            obj = obj.parentNode;
        }
        return offset;
	}
	this.implode = function (array){
		var result = "", i;
		if (array.length > 1){
			for (i in array)
				result += array[i] + ",";
			result = result.substr(0, (result.length - 1));
		}else{
			result = array;
		}
		return result;
	}
	this._showChild = function (){
		window.clearTimeout(this.menuObj.hideTimer);
		window.status = this.menuObj.data[this.nodeID].url;
		if (this.menuObj.openBranch.indexOf(this.menuObj.data[this.nodeID].parent) != -1){
			var node;
			var openBranch = this.menuObj.openBranch.split(",");
			while (node = openBranch.pop()){
				if (node != this.menuObj.data[this.nodeID].parent){
					this.menuObj.data[node].owner.className = "menu";
					if (this.menuObj.data[node].haveChilds){
						this.menuObj.data[node].owner.className = "menuChilds";
						this.menuObj.data[node].table.style.visibility = "hidden";
					}
				}else{
					openBranch.push(node);
					break;
				}
			}
			this.menuObj.openBranch = "" + this.menuObj.implode(openBranch);
		}
		this.menuObj.openBranch += "," + this.nodeID;
		this.className = "menuOver";
		if (this.menuObj.data[this.nodeID].haveChilds){
			this.className = "menuOverChilds";
			this.childObj.style.visibility = "visible";
		}
	}	
}
