
var menu_link;
var open_link;
var open_part;
var open_subpart;
var open_brother;
var brother = false;

function open_menu(_this){
	
	
	openmenuClose();
		
	_submenu = "sub_" + _this.id;
	_link = _this.id;
	
	if(open_part != undefined && _this.className != "parent" && _this.className != "parent_open" && _this.className != "opener"){
		menu_close();
		openmenuClose();
		
		if(window.timeOutId)
			clearTimeout(window.timeOutId);
	}
	
	var _object = document.getElementById(_submenu);
	
	if(_object.style.display == "block"){
		_object.style.display = "none";
		return;
	}
	
	var p, x, y;
	var _width = 0;
	var _height = 0;
	
	p = document.getElementById(_link);
	

	if(_this.className == "parent" || _this.className == "parent_open" || _this.className == "opener"){
		if(brother) document.getElementById(brother).style.display = "none";
		open_link = _this.id;
		open_subpart = _submenu;
		_width = p.offsetWidth;
	} else {
		_this.className = "over";
		menu_link = _link;
		open_part = _submenu;
		var _height = p.offsetHeight;
	}		
		
	x = p.offsetLeft;
	y = p.offsetTop;
	while((p=p.offsetParent)!=null){
		x += p.offsetLeft;
		y += p.offsetTop;
	}
	
	_object.style.top = y + _height;
	_object.style.left = x + _width;
	
	_object.style.display = "block";
				
	_object.onmouseout = function(){
		if(open_brother != undefined) document.getElementById(open_brother).style.display = "block";
		if(_this.className == "parent" || _this.className == "parent_open" || _this.className == "opener"){
			document.getElementById(open_subpart).style.display = "none";
			document.getElementById(_this.id).className = "parent";
		}
		window.timeOutId = setTimeout('menu_close()', 500); 
	}
	
	_object.onmouseover = function(){
		if(open_brother != undefined) document.getElementById(open_brother).style.display = "none";
		if(_this.className == "parent" || _this.className == "parent_open"){
			document.getElementById(open_subpart).style.display = "block";
			document.getElementById(_this.id).className = "opener";
		}
		if(window.timeOutId)
			clearTimeout(window.timeOutId);
	}
}

function timeout_close(){
	window.timeOutId = setTimeout('menu_close()', 500);
}

function menu_close(){
	document.getElementById(open_part).style.display = "none";
	document.getElementById(menu_link).className = "out";
	openmenuOpen();
}

function submenu_close(){
	if(brother){
		document.getElementById(open_subpart).style.display = "none";
		document.getElementById(open_brother).style.display = "block";
		brother = false;
	}else{
		document.getElementById(open_subpart).style.display = "none";
	}
}

/*********/

function openmenuClose(){
	if(!brother)
		if(document.getElementById("op_menu") != null)
			document.getElementById("op_menu").style.display = "none";	
}

function openmenuOpen(){

	if(!brother)
		if(document.getElementById("op_menu") != null)
			document.getElementById("op_menu").style.display = "block";
}

/*********/

function openmenu(id){
	
	_submenu = "sub_" + id;
	_link = id;
	
	var _object = document.getElementById(_submenu);
	var _this = document.getElementById(id);	
		
	var p, x, y;
	var _width = 0;
	var _height = 0;
	
	p = document.getElementById(_link);
	
	if(_this.className == "parent"){
		_width = p.offsetWidth;
	} else {
		var _height = p.offsetHeight;
	}		
		
	x = p.offsetLeft;
	y = p.offsetTop;
	while((p=p.offsetParent)!=null){
		x += p.offsetLeft;
		y += p.offsetTop;
	}
	
	_object.style.top = y + _height;
	_object.style.left = x + _width;
	
	_object.style.display = "block";
}