var menu =
{
	menuButton     : {},
	menuContent    : {},
	menuOpen       : {},
	menuToggleMode : {},
	setonclickObj  : {},
	styles         : {},
	divergent      : {},
	CUR_MENU       : null,
	TIMER          : {},


	init : function ( menuid, buttonid, toggle_mode, styles, divergent, setonclick )
	{
		this.menuOpen[buttonid]                      = false;
		this.menuToggleMode[buttonid]                = toggle_mode;
		this.menuContent[buttonid]                   = my_getbyid(menuid);
		this.menuButton[buttonid]                    = my_getbyid(buttonid);

		this.menuContent[buttonid].onmouseout        = this.setmenuMouseOut(buttonid);
		this.menuContent[buttonid].onmouseover       = this.setmenuMouseOver(buttonid);
		this.menuButton[buttonid].onmouseover        = this.setMenuButtonMouseOver(buttonid);
		this.menuButton[buttonid].onmouseout         = this.setMenuButtonMouseOut(buttonid);
		this.menuButton[buttonid].onclick            = this.setShowMenu(buttonid);

		this.menuContent[buttonid].style.display      = 'none';
		this.menuContent[buttonid].style.zIndex       = 100;
		this.menuContent[buttonid].style.position     = 'absolute';

		this.setonclickObj[buttonid] = setonclick;
		this.styles[buttonid]        = styles;

		if( typeof divergent == 'undefined' || divergent.length != 2 )
		{
			divergent = [0,0];
		}

		this.divergent[buttonid]                      = divergent;

		this.markElement(this.menuButton[buttonid]);
		this.markElement(this.menuContent[buttonid]);
	},

	markElement : function ( element, sExpandoProperty )
	              {
	                  element['MenuElem'] = 1;

	                  for( var x = 0, node = null; x < element.childNodes.length; x++ )
	                  {
	                  	  node = element.childNodes[x];

	                  	  if( node.tagName )
	                  	  {
	                  	      this.markElement( node, sExpandoProperty );
	                  	  }
	                  }
	              },

	setmenuMouseOut : function ( buttonid )
	{
		return function () { menu.menuMouseOut(buttonid); }
	},

	menuMouseOut : function ( buttonid )
	{
		this.TIMER = setTimeout('menu.hideMenu("' + buttonid + '");', 250 );
	},

	setmenuMouseOver : function ( buttonid )
	{
		return function () { menu.menuMouseOver(buttonid); }
	},

	menuMouseOver : function ( buttonid )
	{
		clearTimeout(this.TIMER);
	},

	setMenuButtonMouseOver : function ( buttonid )
	{
		return function() { menu.menuButtonMouseOver(buttonid); }
	},

	menuButtonMouseOver : function ( buttonid )
	{
		clearTimeout(this.TIMER);

		if( this.menuOpen[buttonid] )
		{
			return false;
		}

		if( typeof this.styles[buttonid] != 'undefined' )
		{
			for( var i in this.styles[buttonid].over )
			{
				this.menuButton[buttonid].style[i] = this.styles[buttonid].over[i];
			}
		}

		this.showMenu(buttonid);
	},

	setMenuButtonMouseOut : function ( buttonid )
	{
		return function() { menu.menuButtonMouseOut(buttonid); }
	},

	menuButtonMouseOut : function ( buttonid )
	{
		this.TIMER = setTimeout('menu.hideMenu("' + buttonid + '");', 250 );

		if( typeof this.styles[buttonid] != 'undefined' )
		{
			for( var i in this.styles[buttonid].out )
			{
				this.menuButton[buttonid].style[i] = this.styles[buttonid].out[i];
			}
		}
	},

	setHideMenu : function ( buttonid )
	{
		return function () { menu.hideMenu(buttonid); }
	},

	hideMenu : function ( buttonid )
	{
		if( typeof(buttonid) == 'undefined' )
		{
			buttonid = this.CUR_MENU;
		}

		if( ! this.menuOpen[buttonid] )
		{
			return;
		}

		if( typeof this.styles[buttonid] != 'undefined' )
		{
			for( var i in this.styles[buttonid].out )
			{
				this.menuButton[buttonid].style[i] = this.styles[buttonid].out[i];
			}
		}

		this.menuButton[buttonid].onclick        = this.setShowMenu(buttonid);
		this.menuContent[buttonid].style.display = 'none';
		this.menuOpen[buttonid]                  = false;
	},

	setShowMenu : function ( buttonid )
	              {
	              	  return function() { menu.showMenu(buttonid); }
	              },

	showMenu : function ( buttonid )
	           {
	           	   if( this.menuOpen[buttonid] )
	           	   {
	           	   	   return;
	           	   }

	           	   this.hideMenu(this.CUR_MENU);
	           	   this.CUR_MENU = buttonid;

	           	   this.menuContent[buttonid].style.display = '';

	           	   if( this.menuToggleMode[buttonid] == 2 )
	           	   {
	           		   this.menuContent[buttonid].style.top     = ( get_obj_top_pot(this.menuButton[buttonid]) + this.menuButton[buttonid].offsetHeight + this.divergent[buttonid][1] ) + 'px';
			           this.menuContent[buttonid].style.left    = ( get_obj_left_pot(this.menuButton[buttonid]) + this.menuButton[buttonid].offsetWidth - this.menuContent[buttonid].offsetWidth + this.divergent[buttonid][0] ) + 'px';  
	           	   }
	           	   else if( this.menuToggleMode[buttonid] == 3 )
	           	   {
	           		   this.menuContent[buttonid].style.top     = ( get_obj_top_pot(this.menuButton[buttonid]) + this.divergent[buttonid][1] ) + 'px';
			           this.menuContent[buttonid].style.left    = ( get_obj_left_pot(this.menuButton[buttonid]) + this.menuButton[buttonid].offsetWidth + this.divergent[buttonid][0] ) + 'px';  
	           	   }
	           	   else if( this.menuToggleMode[buttonid] == 4 )
	           	   {
	           		   this.menuContent[buttonid].style.top     = ( get_obj_top_pot(this.menuButton[buttonid]) + this.divergent[buttonid][1] ) + 'px';
			           this.menuContent[buttonid].style.left    = ( get_obj_left_pot(this.menuButton[buttonid]) - this.menuContent[buttonid].offsetWidth - this.divergent[buttonid][0] ) + 'px';  
	           	   }
	           	   else
	           	   {
	           		   this.menuContent[buttonid].style.top     = ( get_obj_top_pot(this.menuButton[buttonid]) + this.menuButton[buttonid].offsetHeight + this.divergent[buttonid][1] ) + 'px';
			           this.menuContent[buttonid].style.left    = ( get_obj_left_pot(this.menuButton[buttonid]) + this.divergent[buttonid][0] ) + 'px';   
	           	   }
	           	   
		           this.menuOpen[buttonid]                  = true;
		           this.menuButton[buttonid].onclick        = this.setHideMenu(buttonid);
		           //document.onclick                       = this.setHideMenu(buttonid);

	           	   if( typeof this.setonclickObj[buttonid] != 'undefined' )
		           {
		           	   eval( this.setonclickObj[buttonid] );
		           }
		       }
};