var _menu_class_hover = 'menu_hover';
var _menu_class_frame = 'menu_frame';
var _menu_class_item = 'menu_item';
var _menu_prefix = 'xmenu_';
var _menu_arrow = '<img src="images/icon_muiten.gif" border="0" align ="absmiddle" />';
var _menu_delay = 10;
var _menu_trans = 98;
var _menu_timer = false;

function abs_left(obj){
	var x = 0;
	try{
		while(obj){
			if(obj.offsetLeft>0){
				x = x + obj.offsetLeft;
			}
			obj = obj.offsetParent;
		}
	}catch(e){
	}
	return x;
}
function abs_right(obj){
	var x = 0;
	try{
		x = obj.offsetWidth;
		while(obj){
			if(obj.offsetLeft>0){
				x = x + obj.offsetLeft;
			}
			obj = obj.offsetParent;
		}
	}catch(e){
	}
	return x;
}
function abs_top(obj){
	var y = 0;
	try{
		while(obj){
			if(obj.offsetTop>0){
				y = y + obj.offsetTop;
			}
			obj = obj.offsetParent;
		}
	}catch(e){
	}
	return y;
}
function abs_bottom(obj){
	var y = 0;
	try{
		y = obj.offsetHeight;
		while(obj){
			if(obj.offsetTop>0){
				y = y + obj.offsetTop;
			}
			obj = obj.offsetParent;
		}
	}catch(e){
	}
	return y;
}

/*----------------------------------------------------------------------------------*/
var _MENUSET = [];

function Menu(title,link,target,icon){
	this._id = _MENUSET.length;
	this._title = title;
	this._link = link;
	this._target = target;
	this._icon = icon;
	this._child = [];
	this._parent = null;
	this._srcobj = null;
	this._oframe = null;
	this._active = false;
	this._zindex = 100;
	_MENUSET[this._id] = this;
}
Menu.prototype.insert = function(menu){
	var i = this._child.length;
	this._child[i] = menu;
	this._child[i]._parent = this;
}
Menu.prototype.show = function(){
	try{
		if(this._oframe) {
			this._oframe.style.visibility = 'visible';
			this._oframe.style.display = 'block';
		}
	}catch(e){
	}
}
Menu.prototype.hide = function(){
	try{
		if(this._oframe) {
			this._oframe.style.visibility = 'hidden';
			this._oframe.style.display = 'block';
		}
	}catch(e){
	}
}
Menu.prototype.active = function(src,f){
	var p = this;
	if((!this._srcobj) && src) this._srcobj = src;
	while(p){
		p._active = true;
		if(p._srcobj && p._parent) p._srcobj.className=_menu_class_hover;
		p = p._parent;
	}
	for(var i=0;i<_MENUSET.length;i++){
		if(_MENUSET[i]._srcobj && _MENUSET[i]._parent && _MENUSET[i]._active==false){
			_MENUSET[i]._srcobj.className=_menu_class_item;
		}
	}
	try{
		if(this._oframe && src){
			var _sw = document.documentElement.scrollWidth;
			var _sh = document.documentElement.scrollHeight;
			var x = abs_right(src);
			var y = abs_bottom(src);
			if(f){
				x -= -1;
				y -= 18;
			}else{
				x -= src.offsetWidth;
			}
			if((y+this._oframe.offsetHeight)>=_sh){
				y = _sh - this._oframe.offsetHeight;
			}
			if((x+this._oframe.offsetWidth)>=_sw){
				if(f){
					x = abs_left(src) - this._oframe.offsetWidth;
				}else{
					x = _sw - this._oframe.offsetWidth;
				}
			}
			if(x<0) x=0;
			if(y<0) y=0;
			this._oframe.style.left = x + 'px';
			this._oframe.style.top = y + 'px';
			this.expand();
		}
	}catch(e){
	}
}
Menu.prototype.inactive = function(src,f){
	var p = this;
	while(p){
		p._active = false;
		p = p._parent;
	}
	this.collapse();
}
Menu.prototype.expand = function(){
	try{
		if(_menu_timer) clearTimeout(_menu_timer);
		var f0 = 'for(var i=0;i<_MENUSET.length;i++)if(_MENUSET[i]._active==true) _MENUSET[i].show(); else _MENUSET[i].hide();';
		_menu_timer = setTimeout(f0,_menu_delay);
	}catch(e){
	}
	window.status = this._link;
}
Menu.prototype.collapse = function(){
	try{
		if(_menu_timer) clearTimeout(_menu_timer);
		var f0 = 'for(var i=0;i<_MENUSET.length;i++) if(_MENUSET[i]._active==false) _MENUSET[i].hide();';
		_menu_timer = setTimeout(f0,400);
	}catch(e){
	}
	window.status = '';
}
Menu.prototype.clicked = function(){
	this.collapse();
	if(this._link.match(/^javascript:/i)){
		eval(this._link);
	}else{
		window.open(this._link,this._target);
	}
	return false;
}
Menu.prototype.build = function(){
	if(this._child.length>0){
		var html = '<div id="' + (_menu_prefix + this._id) + '" class="' + _menu_class_frame + '" style="visibility:hidden;position:absolute;z-index:' + this._zindex + ';filter:alpha(opacity=' + _menu_trans + ');" onmouseover="_MENUSET[' + this._id + '].active(null,true)" onmouseout="_MENUSET[' + this._id + '].inactive(null,true)">';
		html += '<table border="0" cellpadding="0" cellspacing="0">';
		for(var i=0;i<this._child.length;i++){
			var menu = this._child[i];
			var arrow = menu._child.length>0?_menu_arrow:'&nbsp;';
			var icon = menu._icon?'<img border="0" src="'+menu._icon+'" />':'&nbsp;';
			if(menu._title=='-'){
				html += '<tr class="menu_separator" height="1" onmouseover="_MENUSET[' + menu._id + '].active(null,true)" onmouseout="_MENUSET[' + menu._id + '].inactive(null,true)"><td></td><td></td><td></td></tr>';
			}else{
				html += '<tr class="' + _menu_class_item + '" onmouseover="_MENUSET[' + menu._id + '].active(this,true)" onmouseout="_MENUSET[' + menu._id + '].inactive(this,true)" onclick="_MENUSET[' + menu._id + '].clicked(this,true)"><td>' + icon + '</td><td nowrap>' + menu._title + '</td><td>' + arrow + '</td></tr>';
			}
			menu._zindex = this._zindex + 3;
			menu.build();
		}
		html +='</table></div>';
		document.write(html);
		this._oframe = document.getElementById(_menu_prefix + this._id);
		this._oframe.style.position = 'absolute';
		this._oframe.style.zIndex = this._zindex;
		this._oframe.style.visibility = 'hidden';
		this._oframe.style.display = 'block';
		this._oframe.style.filter = 'alpha(opacity=' + _menu_trans + ')';
		this._oframe.style.opacity = _menu_trans/100;
	}
}
