
var _menu_top_class_frame = 'menu_top_frame';
var _menu_top_class_main = 'm0l0iout';//'menu_top_main';
var _menu_top_class_item = 'm0l1iout';//'menu_top_item';
var _menu_top_class_main_hover = 'm0l0iover';
var _menu_top_class_item_hover = 'm0l1iover';
var _menu_arrow = 'icon_01.gif';
var _menu_padding = 0;
var _menu_delay = 400;
var _menu_refs = new Array();

function Menu(text,href,target,icon){
	this._id = _menu_refs.length;
	this._text = text;
	this._href = href;
	this._target = target;
	this._icon = icon;
	this._parent = false;
	this._nextSibling = false;
	this._prevSibling = false;
	this._items = new Array();
	this._level = 0;
	this._timer = 0;
	_menu_refs[this._id] = this;
}
Menu.prototype.addMenuItem = function(menu){
	var n = this._items.length;
	var p = n - 1;
	this._items[n] = menu;
	this._items[n]._parent = this;
	this._items[n]._level = this._level + 1;
	if( p>=0 ){
		this._items[n]._prevSibling = this._items[p];
		this._items[p]._nextSibling = this._items[n];
	}
}
Menu.prototype.writeMenu = function(){
	var n = _menu_refs.length;
	var _html = new Array();
	for(var i=0; i<n; i++){
		var m = _menu_refs[i]._items;
		_html[i] = '<div id="frame_'+_menu_refs[i]._id+'" class="'+_menu_top_class_frame+'" onmouseover="_menu_refs['+i+'].onFocus();" onmouseout="_menu_refs['+i+'].onBlur();" style="display:none; visibility:visible; position:absolute; z-index:'+_menu_refs[i]._level+';"><table border="0" cellpadding="0" cellspacing="'+_menu_padding+'">';
		if( m.length>0 ){
			for(var j=0; j<m.length; j++){
				var id = "menu_" + m[j]._id;
				var bg_arrow = m[j]._items.length>0?'background-image:url('+_menu_arrow+')':'';
				var bg_icon = m[j]._icon?'background-image:url('+m[j]._icon+')':'';
				_html[i] += '<tr bgcolor=#f4f5f6><td align=left nowrap id="'+id+'" class="'+_menu_top_class_item+'" onmouseover="_menu_refs['+m[j]._id+'].onmouseover(this)" onmouseout="_menu_refs['+m[j]._id+'].onmouseout(this)" onclick="_menu_refs['+m[j]._id+'].onclick(this)"><div style="'+bg_icon+'; padding-left:15px; padding-top:5px; height:20px; background-repeat:no-repeat; background-position:left;"><div style="'+bg_arrow+'; padding-right:16px; font-weight:bold; background-repeat:no-repeat; background-position:right;">'+m[j]._text+'</div></div></td></tr>';
			}
		}else{
			_html[i] += '';
		}
		_html[i] += '</table></div>';
	}
	document.write(_html.join(''));
}
Menu.prototype.expand = function(){
	var oMenu = document.getElementById('frame_'+this._id);
	if( (this._items.length>0) && (oMenu.style.display=='none') ){
		var x = 0;
		var y = 0;
		var obj = this._eventSrc;
		while( obj ){
			if( obj.offsetLeft>0 ) x+=obj.offsetLeft;
			if( obj.offsetTop>0 ) y+=obj.offsetTop;
			obj = obj.offsetParent;
		}
		var tmp = x;
		y += this._eventSrc.offsetHeight;
		if( this._parent ){
			x += this._eventSrc.offsetWidth - 6;
			y -= 8;
		}
		oMenu.style.left = '0px';
		oMenu.style.top = '0px';
		oMenu.style.display = 'block';
		var max_width = oMenu.offsetWidth;
		var max_height = oMenu.offsetHeight;
		if( (x + max_width)>document.documentElement.scrollWidth ){
			if( (tmp - max_width + 6)>0 ){
				x = tmp - max_width + 6;
				tmp = 0;
			}else{
				x = 0;
			}
		}
		if( (y + max_height)>document.documentElement.scrollHeight ){
			if( (document.documentElement.scrollHeight - max_height)>0 ){
				y = document.documentElement.scrollHeight - max_height;
			}else{
				y = 0;
			}
		}
		oMenu.style.left = x + 'px';
		oMenu.style.top = y + 'px';
		this.fadeOut(x,y,max_width,0,tmp);
	}
}
Menu.prototype.collapse = function(){
	document.getElementById('frame_'+this._id).style.display = "none";
	this._eventSrc.className = this._parent?_menu_top_class_item:_menu_top_class_main;
}
Menu.prototype.onclick = function(_eventSrc){
	var m = this;
	while( m ){
		clearTimeout( m._timer );
		m.collapse();
		m = m._parent;
	}
	var regs = this._href.match(/^[a-z:]+:/i);
	if( regs && (regs[0].toLowerCase()=='javascript:') ){
		eval( this._href );
	}else{
		if( this._target ){
			window.open( this._href, this._target );
		}else{
			window.open( this._href, '_self' );
		}
	}
}
Menu.prototype.onmouseover = function(_eventSrc){
	this._eventSrc = _eventSrc;
	this.onFocus();
}
Menu.prototype.onmouseout = function(_eventSrc){
	this._eventSrc = _eventSrc;
	this.onBlur();
}
Menu.prototype.onFocus = function(){
	try{
		var m = this;
		while( m ){
			clearTimeout( m._timer );
			m._timer = setTimeout( '_menu_refs['+m._id+'].expand();', 100 );
			m = m._parent;
		}
		try{
			var p = this._prevSibling;
			this._eventSrc.className = this._parent?_menu_top_class_item_hover:_menu_top_class_main_hover;
			while( p ){
				p._eventSrc.className = p._parent?_menu_top_class_item:_menu_top_class_main;
				p = p._prevSibling;
			}
		}catch(e){
		}
		try{
			var p = this._nextSibling;
			while( p ){
				p._eventSrc.className = p._parent?_menu_top_class_item:_menu_top_class_main;
				p = p._nextSibling;
			}
		}catch(e){
		}
	}catch(e){
	}
}
Menu.prototype.onBlur = function(){
	try{
		var m = this;
		while( m ){
			clearTimeout( m._timer );
			m._timer = setTimeout( '_menu_refs['+m._id+'].collapse();', _menu_delay );
			//m._eventSrc.className = m._parent?_menu_top_class_item:_menu_top_class_main;
			m = m._parent;
		}
	}catch(e){
	}
}
Menu.prototype.fadeOut = function(_x,_y,_w,_h,_d){
	var oMenu = document.getElementById('frame_'+this._id);
	var _dx = Math.ceil( (oMenu.offsetWidth-_w)/3 );
	var _dy = Math.ceil( (oMenu.offsetHeight-_h)/3 );
	var _ok = true;
	if( _dx<10 ) _dx = 10;
	if( _dy<10 ) _dy = 10;
	if( (_w+_dx)<=oMenu.offsetWidth ){
		_w += _dx;
		_ok = false;
	}else{
		_w = oMenu.offsetWidth;
	}
	if( (_h+_dy)<=oMenu.offsetHeight ){
		_h += _dy;
		_ok = false;
	}else{
		_h = oMenu.offsetHeight;
	}
	/*clip=rect(top,right,bottom,left)*/
	if( _d ){
		oMenu.style.clip = 'rect('+(oMenu.offsetHeight-_h)+'px,'+oMenu.offsetWidth+'px,'+_h+'px,'+(oMenu.offsetWidth-_w)+'px)';
		oMenu.style.left = ( _x - oMenu.offsetWidth + _w ) + 'px';
		oMenu.style.top = ( _y - oMenu.offsetHeight + _h ) + 'px';
	}else{
		oMenu.style.clip = 'rect('+(oMenu.offsetHeight-_h)+'px,'+_w+'px,'+_h+'px,0px)';
		oMenu.style.left = ( _x + oMenu.offsetWidth - _w ) + 'px';
		oMenu.style.top = ( _y - oMenu.offsetHeight + _h ) + 'px';
	}
	if( _ok==false ){
		setTimeout('_menu_refs['+this._id+'].fadeOut('+_x+','+_y+','+_w+','+_h+','+_d+')',10);
	}
}
