// created by: Andr� Dietisheim (dietisheim@sphere.ch)
// created:	2002-05-11
// modified by: Andr� Dietisheim (dietisheim@sphere.ch)
// modified: 2004-01-17
// version: 2.1.0

function Xmenus( sNavigationName, sNavigation )
{
		if( !Xmenus.prototype.instances ) Xmenus.prototype.instances = new Array();
		Xmenus.prototype.instances[ Xmenus.prototype.instances.length ] = this;

		this.index = Xmenus.prototype.instances.length - 1;

		this.iCloseDelay = 1;
		this.xmenus = new Array();

		this.sNavigationName = sNavigationName;
		this.sNavigation = sNavigation;
		this.navigationMenu = null;

		this.lastMenu = null;
		this.timeout = null;
		this.bReopenDisabled = false;
}

Xmenus.prototype.add = function( entry )
{
	this.xmenus[ this.xmenus.length ] = new Xmenu( this.sNavigationName, this.sNavigation, entry[ 0 ], entry[ 1 ], entry[ 2 ] );
}

Xmenus.prototype.create = function()
{
	for ( j = 0; j < this.xmenus.length; j++ )
	{
		this.xmenus[ j ].setOpenListener( this );
		this.xmenus[ j ].setCloseListener( this );
		this.xmenus[ j ].setLinkClickListener( this );
		this.xmenus[ j ].create();
		if ( this.xmenus[ j ].isNavigationNodeFound() )
		{
			this.openNavigationMenu( this.xmenus[ j ] );
		}
	}
}

Xmenus.prototype.openNavigationMenu = function( xmenu )
{
			this.navigationMenu = xmenu;
			this.lastMenu = xmenu;
			xmenu.open();
}

Xmenus.prototype.onMenuOpen = function( xmenu )
{ // fired by Xmenu on menu open
	if ( this.lastMenu != null && this.lastMenu != xmenu )
	{
		this.bReopenDisabled = true;
		this.lastMenu.close();
		this.bReopenDisabled = false;
	}
	this.bOpened = true;
	this.lastMenu = xmenu;
}

Xmenus.prototype.onMenuClose = function( xmenu )
{  // fired by Xmenu on menu close
	if ( !this.bReopenDisabled )
	{
		this.timeout = setTimeout( "Xmenus.prototype.instances[" + this.index + "].reopenAfterClose()", this.iCloseDelay * 1000 );
	}
	this.bOpened = false;
}

Xmenus.prototype.reopenAfterClose = function()
{
	if ( !this.bOpened && this.navigationMenu != null )
	{ //no other menu is opened -> open navigation menu
		this.navigationMenu.open();
	}
}

Xmenus.prototype.onLinkClick = function( xmenu )
{  // fired by Xmenu on click on a link
//	this.navigationMenu.clearHighlightChildren( this.navigationMenu.tree );
	this.openNavigationMenu( xmenu );
}
