var cPath = (window.getRelativeWebRoot ? window.getRelativeWebRoot() : '') + 'js/Lib/';
document.write ('<SCR' + 'IPT LANGUAGE="JavaScript1.2" SRC="'+ cPath +'BMenu3.js" TYPE="text/javascript"><\/SCR' + 'IPT>');

var aMenuEntries;
var INTERNET = 41;
var EXTRANET = 42;

function isStartPage() {
	return (PageID == INTERNET || PageID == EXTRANET);
}

function initMenus () {
	if (_aMs.length == 0) {
		aMenuEntries = eval('aMenuEntries' + (bExtranet ? EXTRANET : INTERNET));
		var oMenu = new Menu(0);
	}
}

function Menu (nLevel) {
	this.init = BTextMenu;
	this.init (nLevel);
	this.bFolded = !isStartPage();
	this.nElementHeight = 25;
	this.nChildOffset = 10;
	
	this.calculateSize = function() {
		this.nElementsWidth = this.getElementsWidth();
		this.nWidth = 9 + this.nElementsWidth + 9;
	};

	
	this.mo = function (nElem, bOver) {
		if (!_aMs[0].bSuspended) {
			if (bOver) {
				clearTimeout (_aMs[0].oToClose);
				if (this.bFolded) {
					if (PageID != 1) _aMs[0].oToOpen = setTimeout ('_aMs[' + this.nLevel + '].unfold();_aMs[' + this.nLevel + '].nHigh=null;_aMs[' + this.nLevel + '].mo(0,1)', 500);
				}
				else {
					if (oSound) oSound.playMenu (Math.min (nElem+1, 10));
					if (this.highlight (nElem) && this.oChild) {
						clearTimeout (this.oToUpdateChild);
						if (PageID != 1) this.oToUpdateChild = setTimeout ('_aMs[' + this.nLevel + '].updateChild(' + nElem + ')', 200);	
						if (this.oChild.nSelected != null) this.oChild.highlight (this.oChild.nSelected);
					}
					if (this.oParent && this.oParent.nSelected != null) this.oParent.highlight (this.oParent.nSelected);
				}
			}
			else {
				clearTimeout (_aMs[0].oToOpen);
				if (this.bFolded == null) {
					_aMs[0].oToClose = setTimeout ('_aMs[' + this.nLevel + '].close()', 700);
					this.highlight (null);
				}
				else
					_aMs[0].oToClose = setTimeout ('_aMs[' + this.nLevel + '].fold()', 700);
			}
		}
		window.status = '';
		return (true);
	}


	this.getContent = function (nLayer) {
		var cPath = (window.getRelativeWebRoot ? window.getRelativeWebRoot() : '') + CONFIG['Images']['Dir'];
		var cHtml = '<table border="0" cellspacing="0" cellpadding="0" width="' + this.nWidth + '">';
		var bPreSelected, bHasChildren, cTextClass;

		for (var i=0; i<this.aElements.length; i++) 
			if (!this.bFolded || i == this.nPreSelected || (this.nLevel == 0 && typeof(this.nPreSelected) != 'number' && i==0)) {
				cHtml += '<tr>';
				
				if (nLayer < 2) {
					cExtra = (nLayer > 0 && bExtranet ? 'x' : '');
					cHtml += '<td><img src="' + cPath + 'nav/anfang_' + (nLayer + cExtra) + '.gif" width="9" height="25" alt=""></td>';
					bHasChildren = (this.aElements[i][2] && this.aElements[i][2].length > 0);
					bPreSelected = (typeof(this.nPreSelected)=='number' && (i == this.nPreSelected));
					cTextClass = 'menu' + (bPreSelected ? 'pre' : '');
				}
				switch (nLayer) {
					case 0:
						cHtml += '<td class="menu"><P class="menu"><nobr> &nbsp;' + this.aElements[i][1] + '</nobr></P></td>';
						break;
					case 1: 
						cHtml += '<td class="menuact"><P class="menu"><nobr> &nbsp;' + this.aElements[i][1] + '</nobr></P></td>';
						break;
					case 2: 
						cHtml += '<td><a ' + this.getLink(i) + ' onmouseover="return _aMs[' + this.nLevel + '].mo(' + i + ',1)" onmouseout="return _aMs[' + this.nLevel + '].mo(' + i + ')"><img src="' + cPath + 'leer.gif" width="' + this.nWidth + '" height="' + this.nElementHeight + '" border="0"></a></td>'; 
						break;
				}
	
				if (nLayer < 2) cHtml += '<td><img src="' + cPath + 'nav/ende_' + ((bHasChildren && PageID != 1) ? 'weiter' : '') + (nLayer+ cExtra) + '.gif" width="9" height="25" alt=""></td>';//(bHasChildren ? 'weiter_' : '')
				cHtml += '</tr>'
			}

		if (nLayer < 2) cHtml += '<tr><td></td><td><img src="' + cPath + 'leer.gif" width="' + this.nElementsWidth + '" height="1" alt=""></td><td></td></tr>';
		cHtml += '</table>';
		return (cHtml);
	};

	this.BMenu_getLink = this.getLink;
	this.getLink = function (nElem) {
		var cLink = this.BMenu_getLink(nElem);
		if (oSound) cLink = cLink + ' onclick="oSound.playKlick()"';
		return (cLink);
	}

	
	if (this.nLevel == 0) {
		this.bSuspended = false;
		this.aPos = [100, 10];
		
		if (isStartPage()) {
			this.aPos = [-8, 110];
			this.fold = function (bUnfold, oCallingMenu) {
				this.preset (aMenuEntries);
				if (oSound) oSound.play('menu', 'zu', 'play');
				if (oMatrix) oMatrix.suspend (false);
			};
			this.unfold = function () {};

			this.BupdateChild = this.updateChild;
			this.updateChild = function (nElem) {
				this.BupdateChild (nElem);
				if (oMatrix) oMatrix.suspend (true);
			}
		}			
		
		this.preset (aMenuEntries);
	}
}