/**
*	Wrapper for all menus
*
*/
	function	dhtmlMenu()
	{
		this.menuCnt		=	0;
		this.menus			=	new	Array();

		this.checkTimer		=	false;

		this.enteredCurrent	=	false;
		this.currentMenu	=	false;
		this.imgPath		=	0;
		this.depth			=	100;
		
		this.addChild		=	menuAddChild;
		this.printCSS		=	menuPrintCSS;
		this.printDiv		=	menuPrintDiv;
		this.init			=	menuInit;

		this.showMenu		=	menuShowMenu;
		this.hideMenu		=	menuHideMenu;
		this.doHideMenu		=	menuDoHideMenu;

		this.checkActiveEntry=	menuCheckActiveEntry;
		
		this.hilightEntry	=	menuHilightEntry;
		this.checkMenu		=	menuCheckMenu;
		this.setDepth		=	setDepth;
		this.setImgPath		=	setImgPath;
	}

	function	menuAddChild( child )
	{
		child.setId( "mm" + this.menuCnt );
		child.setDepth( this.depth );

		child.nr					=	this.menuCnt;
		this.menus[this.menuCnt++]	=	child;
	}

	function	menuInit()
	{
		for( var i=0; i<this.menus.length; i++ )
		{
			this.menus[i].init();
		}
	}

	function	setImgPath( path )
	{
		alert( "path: "+path );
		this.imgPath	=	path;
	}

	function	menuPrintCSS()
	{
		document.writeln( '<style type="text/css">' );
		for( var i=0; i<this.menus.length; i++ )
		{
			this.menus[i].printCSS();
		}
		document.writeln( '</style>' );
	}
	
	function	menuCheckMenu()
	{
		if( this.currentMenu < 0 )
			return	false;

		if( this.enteredCurrent )
		{
			if( mdl_checkMouseInLayer( this.menus[this.currentMenu].layer ) || mdl_checkMouseInLayer( this.menus[this.currentMenu].layerHi ) )
			{
				this.checkActiveEntry();
				this.checkTimer		=	setTimeout( "menu.checkMenu()", 100 );
			}
			else
				this.doHideMenu( this.currentMenu );
		}

		//	Menü schon aufgeklickt, war aber noch nicht drin!
		else
		{
			if( mdl_checkMouseInLayer( this.menus[this.currentMenu].layer ) || mdl_checkMouseInLayer( this.menus[this.currentMenu].layerHi ) )
				this.enteredCurrent	=	true;

			this.checkTimer		=	setTimeout( "menu.checkMenu()", 500 );
		}
	}

	function	menuCheckActiveEntry()
	{
		for( var i=0; i< this.menus[this.currentMenu].entryCnt; i++ )
		{
			if( mdl_mouseY > ( this.menus[this.currentMenu].y + this.menus[this.currentMenu].tops[i] ) && mdl_mouseY <= ( this.menus[this.currentMenu].y + this.menus[this.currentMenu].bottoms[i] ) )
			{
				this.hilightEntry( this.currentMenu, i );
				break;
			}
		}
	}
	
	function	menuPrintDiv()
	{
		for( var i=0; i<this.menuCnt; i++ )
			this.menus[i].printDiv();
	}

	function	menuHideMenu()
	{
		this.enteredCurrent	=	true;
		this.checkTimer		=	setTimeout( "menu.checkMenu()", 1000 );
	}

	function	menuDoHideMenu( nr )
	{
		if( nr < 0 )
			return	false;
			
		mdl_hideLayer( this.menus[nr].layer );
		mdl_hideLayer( this.menus[nr].layerHi );

		this.currentMenu	=	-1;
	}
	
	function	menuShowMenu( nr )
	{
		nr--;

		if( nr < 0 )
			return	false;

		//	hide all other menus
		for( var i=0; i<this.menuCnt; i++ )
		{
			mdl_hideLayer( this.menus[i].layer );
			mdl_hideLayer( this.menus[i].layerHi );
		}
		
		mdl_showLayer( this.menus[nr].layer );
		this.currentMenu	=	nr;
		this.enteredCurrent	=	false;
		this.checkMenu();
	}

	function	menuHilightEntry( menu, entry )
	{
		if( this.currentMenu != menu )
			this.showMenu( menu );

		mdl_hideLayer( this.menus[menu].layerHi );
		mdl_clipLayer( this.menus[menu].layerHi, 0,this.menus[menu].tops[entry], this.menus[menu].width, this.menus[menu].bottoms[entry] );
		mdl_showLayer( this.menus[menu].layerHi );
	}
	
/**
*	Dropdown menu
*
*/
	function	ddMenu( x, y, imgPath )
	{
		this.x			=	x;
		this.y			=	y;
		this.imgPath	=	imgPath;

		this.nr			=	0;

		this.bordercol	=	"#000000";
		this.bgcol		=	"#ECEAEA";
		this.hicol		=	"#FFFFFF";

		this.entries		=	new	Array();
		this.entryCnt		=	0;

		this.width			=	0;
		this.tops			=	new	Array();
		this.bottoms		=	new	Array();
		
		//	Methoden
		this.setId			=	setId;
		this.setRefEntry	=	setRefEntry;
		this.addEntry		=	ddAddEntry;
		this.printCSS		=	ddPrintCSS;
		this.printDiv		=	ddPrintDiv;
		this.init			=	ddInit;
		this.calcPositions	=	ddCalcPositions;
		this.setPos			=	ddSetPos;
		
		this.setDepth		=	setDepth;
		
		this.setBorderColor	=	setBorderColor;
	}

	function	ddSetPos( x,y )
	{
		this.x	=	x;
		this.y	=	y;
	}
	
	
	function	ddAddEntry( text, url, target )
	{
		this.entries[this.entryCnt++]	=	new menuEntry( text, url, target );
	}
	
	function	ddInit()
	{
		this.layer	=	mdl_getLayer( this.id );
		mdl_moveLayerTo( this.layer, this.x, this.y );

		this.layerHi=	mdl_getLayer( this.id + "hi" );
		mdl_moveLayerTo( this.layerHi, this.x, this.y );

		this.calcPositions();
	}

	function	ddCalcPositions()
	{
		this.width	=	0;
		for( var i=0; i<this.entryCnt; i++ )
		{
			var	tl			=	mdl_getImage( this.id + "tl" + i );
			var	br			=	mdl_getImage( this.id + "br" + i );

			this.tops[i]	=	( mdl_getImageY( tl ) - this.y ) - 1;
			this.bottoms[i]	=	( mdl_getImageY( br ) - this.y ) + 1;

			var bottom		=	this.bottoms[i];
			
			var	w	=	mdl_getImageX( br ) - mdl_getImageX( tl ) + 2;
			if( w > this.width )
				this.width	=	w;
		}
	}
	
	function	ddPrintCSS()
	{
		if( IE55 )
			document.writeln( '#' + this.id + '		{position: absolute; top:0px; left:0px; visibility: hidden; z-Index:' + this.depth + '; filter:Alpha(opacity=75, finishopacity=75, style=2) }' );
		else
			document.writeln( '#' + this.id + '		{position: absolute; top:0px; left:0px; visibility: hidden; z-Index:' + this.depth + '; }' );
			
		document.writeln( '#' + this.id + 'hi	{position: absolute; top:0px; left:0px; visibility: hidden; z-Index:' + ( this.depth+1 ) + ';}' );
	}

	function	ddPrintDiv()
	{
		document.writeln( starttag + '"' + this.id + '">' );
	
		document.write( '<table border="0" cellpadding="0" cellspacing="0" bgcolor="' + this.bordercol + '">' );
		document.write( '	<tr>' );
		document.write( '		<td>' );
		document.write( '			<table border="0" cellpadding="0" cellspacing="1">' );
		
	
		for( var i=0; i<this.entryCnt; i++ )
		{
			document.write( '				<tr>' );
			document.write( '					<td bgcolor="' + this.bgcol + '">' );
			document.write( '						<table border="0" cellpadding="0" cellspacing="0">' );
			document.write( '							<tr>' );
			document.write( '								<td colspan="3"><img src="'+this.imgPath+'" width="1" height="1" alt="" border="0"></td>' );
			document.write( '							</tr>' );
			document.write( '							<tr>' );
			document.write( '								<td><img src="'+this.imgPath+'" width="2" height="1" alt="" border="0"></td>' );
			document.write( '								<td><a href="' + this.entries[i].url + '" target="' + this.entries[i].target + '" class="menuentry" onMouseOver="menu.hilightEntry( ' + this.nr + ', ' + i + ' );">' + this.entries[i].text + '</a></td>' );
			document.write( '								<td><img src="'+this.imgPath+'" width="4" height="1" alt="" border="0"></td>' );
			document.write( '							</tr>' );
			document.write( '							<tr>' );
			document.write( '								<td align="right" colspan="3"><img src="'+this.imgPath+'" width="1" height="1" alt="" border="0"></td>' );
			document.write( '							</tr>' );
			document.write( '						</table>' );
			document.write( '					</td>' );
		}
		
		document.write( '						</table>' );
		document.write( '					</td>' );
		document.write( '				</tr>' );
		document.write( '			</table>' );
		document.write( '		</td>' );
		document.write( '	</tr>' );
		document.write( '</table>' );
	
		document.writeln( endtag );

		//	active layer
		
		document.writeln( starttag + '"' + this.id + 'hi">' );
	
		document.write( '<table border="0" cellpadding="0" cellspacing="0" bgcolor="' + this.bordercol + '">' );
		document.write( '	<tr>' );
		document.write( '		<td>' );
		document.write( '			<table border="0" cellpadding="0" cellspacing="1">' );
	
		for( var i=0; i<this.entryCnt; i++ )
		{
			document.write( '				<tr>' );
			document.write( '					<td bgcolor="' + this.hicol + '">' );
			document.write( '						<table border="0" cellpadding="0" cellspacing="0">' );
			document.write( '							<tr>' );
			document.write( '								<td colspan="3"><img name="' + this.id + 'tl' + i + '" src="'+this.imgPath+'" width="1" height="1" alt="" border="0"></td>' );
			document.write( '							</tr>' );
			document.write( '							<tr>' );
			document.write( '								<td><img src="'+this.imgPath+'" width="2" height="1" alt="" border="0"></td>' );
			document.write( '								<td><a href="' + this.entries[i].url + '" target="' + this.entries[i].target + '" class="menuentry">' + this.entries[i].text + '</a></td>' );
			document.write( '								<td><img src="'+this.imgPath+'" width="4" height="1" alt="" border="0"></td>' );
			document.write( '							</tr>' );
			document.write( '							<tr>' );
			document.write( '								<td align="right" colspan="3"><img name="' + this.id + 'br' + i + '" src="'+this.imgPath+'" width="1" height="1" alt="" border="0"></td>' );
			document.write( '							</tr>' );
			document.write( '						</table>' );
			document.write( '					</td>' );
		}
		
		document.write( '						</table>' );
		document.write( '					</td>' );
		document.write( '				</tr>' );
		document.write( '			</table>' );
		document.write( '		</td>' );
		document.write( '	</tr>' );
		document.write( '</table>' );
	
		document.writeln( endtag );
	}		


	function	menuEntry( text, url, target )
	{
		if( !target )
			target	=	"_self";

		if( !url )
			url		=	"#";

		this.text	=	text;
		this.url	=	url;
		this.target	=	target;
	}
	
	
/**
*	Useful functions for all classes
*
*/
	function	setId( id )
	{
		this.id	=	id;
	}

	function	setBorderColor( color )
	{
		this.bordercol		=	color;
	}
	
	function	setBgColor( color )
	{
		this.bgcol		=	color;
	}
	
	function	setDepth( depth )
	{
		this.depth	=	depth;
	}
	
	function	setRefEntry( id )
	{
		this.refEntry	=	id;
	}
	
	if( NS4 )
	{
		var	starttag		=	'<layer visibility="hide" name=';
		var	endtag			=	'</layer>';
	}
	else
	{
		var	starttag		=	'<div id=';
		var	endtag			=	'</div>';
	}