function Menu(){
	this.mid = "menu";
	this.hideDelay = 50;
	this.levels = new Array();
	
	this.levels[1] = new Array();
	this.levels[1]['top'] = -1;
	this.levels[1]['left'] = 1;
	this.levels[1]['align'] = 'left';
	this.levels[1]['valign'] = 'bottom';
	
	this.levels[2] = new Array();
	this.levels[2]['top'] = 2;
	this.levels[2]['left'] = -1;
	this.levels[2]['align'] = 'right';
	this.levels[2]['valign'] = 'top';
	
	this.displays = new Array();
	this.over = '';
	this.out = '';
	this.overtimer = new Array();
	this.id = menuInstances.length;
	menuInstances[this.id] = this;
	
	this.show=function(trigger){
		var id=trigger.id;
		
		if(this.getLevel(id)>0){setcss(trigger,'hover');}
		if(this.getLevel(this.getRelative(id))>0){setcss(this.getRelative(id),'hover');}
		trigger.onmouseout = function(){delcss(this,'hover');}
		var child = this.getChild(id);
		if(!exists(child)){return;}

		ge(child).cl = this.id;
		ge(child).oid = child;
		
		
		ge(child).onmouseover = function(event){
			var inst = menuInstances[this.cl];
			if(inst.over==this){return;}
			
			inst.over=this;
			inst.out='';
			inst.blockHide(this.id);
		}

		ge(child).onmouseout=function(event){
			var inst = menuInstances[this.cl];
			if(inst.out==this){return;}
			if(mouse_is_out(event,this)==true){
				inst.over='';
				inst.out=this;
				inst.hide(this.id);
				inst.hide(inst.getParent(this.id));
				
			}
		}
		this.blockHide(this.getParent(id));
		this.blockHide(child);
		this.doShow(child);
		
		ge(id).iid = this.id;
		ge(id).child = child;
		trigger.onmouseout = function(){
			delcss(this,'hover');
			if(exists(this.child)){
				menuInstances[this.iid].hide(this.child);
				menuInstances[this.iid].hide(menuInstances[this.iid].getParent(this.child));
			}
		}
		
		
	}
	
	this.blockHide=function(oid){
		clearTimeout(this.overtimer[oid]);
		this.displays[oid]=true;
		
		this.overtimer[oid] = setTimeout('menuInstances['+this.id+'].resetShow("'+oid+'")',(this.hideDelay+1));
	}
	
	this.doShow=function(oid){
		this.setPosition(oid);
		show(oid,'block');
		/*var amove = new Array(0,100,0);
		var eff = new requiem_action();
		eff.element = oid;
		eff.amove = amove;
		eff.cycles = 3;
		eff.go();*/
	}
	
	this.resetShow=function(child) {
		this.displays[child] = false;
	}
	
	this.hide=function(oid){
		setTimeout('menuInstances['+this.id+'].doHide("'+oid+'")',this.hideDelay);
	}
	
	this.doHide=function(oid){
		if(!undef(this.over.id)){
			if(oid==this.over.id){return;}
			if(oid==this.getParent(this.over.id)){return;}
		}
		if(this.displays[oid]==false && exists(oid)){
			/*var amove = new Array(100,0,0);
			var eff = new requiem_action();
			eff.element = oid;
			eff.amove = amove;
			eff.cycles = 3;
			eff.callback = 'hide('+oid+')';
			eff.go();*/
			hide(oid);
		}
	}
	
	
	this.getLevel=function(oid){
		var a = oid.split('_');
		return a.length-2;
	}
	
	this.getRelative=function(oid){
		return oid.substring(0,oid.lastIndexOf('_'));
	}
	
	this.getParent=function(oid){
		var out = '0';
		if(oid.lastIndexOf('_')){var trigger = oid.substring(0,oid.lastIndexOf('_'));}
		if(trigger.lastIndexOf('_')){var out = trigger.substring(0,trigger.lastIndexOf('_'))+'_0';}
		return out;
	}
	
	this.getChild=function(oid){
		return oid+'_0';
	}
	
	this.setPosition=function(oid){
		var level = this.getLevel(oid);
		var config = this.levels[level];
		var parent = this.getRelative(oid);
		var x = getProperty(parent,'x') + config['left'];
		var y = getProperty(parent,'y') + config['top'];
		if(config['align']=='right'){x+= getProperty(parent,'w');}
		if(config['valign']=='bottom'){y+= getProperty(parent,'h');}
		setProperty(oid,'x',x);
		setProperty(oid,'y',y);
	}
	
	
	this.test=function(txt){
		ge('t').innerHTML = '<div>'+txt+'</div>'+ge('t').innerHTML;
	}
}

function mouse_is_out(e,obj){
	if (!e) var e = window.event;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg.tagName != 'BODY' && reltg.tagName != 'HTML' ){
		if (reltg.id == obj.id){return;}
		reltg = reltg.parentNode;
	}
	return true;
}

function mouse_is_over(e,obj){
	
	if (!e) var e = window.event;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg.tagName != 'BODY' && reltg.tagName != 'HTML' ){
		if (reltg.id == obj.id){return true;}
		reltg = reltg.parentNode;
	}
	return false;
}



var menuInstances = new Array();

var m = new Menu();
