var cPath = (window.getRelativeWebRoot ? window.getRelativeWebRoot() : '') + 'js/Lib/';
document.write ('<SCR' + 'IPT LANGUAGE="JavaScript1.2" SRC="'+ cPath +'BMenu3.js" TYPE="text/javascript"><\/SCR' + 'IPT>');

function initMenus () {
	if (_aMs.length == 0) {
//		alert ('Javascript starting...');
		var oMenu = new StartMenu(0);
	}
}

function StartMenu (nLevel) {
	this.init = BTextMenu;
	this.init (nLevel);
	this.bFolded = null;
	this.nElementHeight = 21; 
	this.nChildOffset = -10;
	this.nOffset = 7;
	this.nStartImageWidth = 30;
	this.nEndImageWidth = 16;
	this.nMoreImageWidth = 22;
	this.bStartPage = (PageID == 1);
	this.nTextOffset = (this.bStartPage ? 30 : -30);
	
	this.calculateSize = function() {
		this.nElementsWidth = this.getElementsWidth();
		this.nWidth = this.nStartImageWidth + this.nEndImageWidth + this.nMoreImageWidth + this.nElementsWidth +  this.getStartOffset(0);
	};

	this.getStartOffset = function (nElement) {
		nOffset = (9 - nElement - 1) * this.nOffset + 1 + this.nTextOffset;
		if (nElement >= 5) nOffset += this.nStartImageWidth-1;
		return (nOffset);
	}
	
	this.getStartImageWidth = function (nElement) {
		return (nElement >= 5 ? 1 : this.nStartImageWidth);
	}

/*
	Bestimmt die Position des aktuellen Untermenüs
*/	
	this.getChildPosition = function() {
		var aPos = [0, 0];
		aPos[0] = this.aLayers[0].get('left') + this.getStartOffset(this.nSelected) + this.nElementsWidth + this.getStartImageWidth(this.nSelected) + this.nEndImageWidth  + this.nMoreImageWidth - this.oChild.getStartOffset(0) + this.nChildOffset;
		aPos[1] = (this.bFolded === true || this.bFolded === false ? _aMs[0].aPos[1] : this.aLayers[0].get('top') + this.nSelected * this.nElementHeight);
		return (aPos);
	}


/*
	Bestimmt die Position des aktuellen Menüs
*/	
	this.BMenuGetPosition = this.getPosition;
	this.getPosition = function () {
		var aPos = this.BMenuGetPosition();
		aPos[5] = aPos[5] + 1;
		return (aPos);
	};

	this.BTextMenuGetElementsWidth = this.getElementsWidth;
	this.getElementsWidth = function() {
		nWidth = Math.min(110,this.BTextMenuGetElementsWidth());
		return(nWidth);
	};


	this.getContent = function (nLayer) {
		var cPath = (window.getRelativeWebRoot ? window.getRelativeWebRoot() : '') + CONFIG['Images']['Dir'];
		var cHtml = '';
		var bPreset, bHasChildren, cClass;
		
		if (this.aElements.length) {
			for (var i=0; i<this.aElements.length; i++) {
				bHasChildren = (this.aElements[i][2] && this.aElements[i][2].length > 0);
				bPreset = false && (typeof(this.nPreSelected)=='number' && (i == this.nPreSelected));
				var nWidth = this.getStartImageWidth(i) + this.nEndImageWidth + this.nMoreImageWidth + this.nElementsWidth +  this.getStartOffset(i);
				cHtml += '<table border="0" cellspacing="0" cellpadding="0" width="' + nWidth + '"><tr>';
				switch (nLayer) {
					case 0:
					case 1: 
						cMenuPath = cPath + 'menu/' + (bPreset && nLayer == 0 ? 'preset/' : '');
						var cStartImg = cPath + 'start/menu/' + (bPreset && nLayer == 0 ? 'preset/' : '') + 'topmenu' + Math.min (5, i) + '_' + nLayer + '.gif';
						cClass = 'menu' + (nLayer == 1 ? 'act' : (bPreset ? 'preset' : ''));
						cHtml += '<td><img src="' + cStartImg + '" width="' + this.getStartImageWidth(i) + '" height="' + this.nElementHeight + '"></td>';
						cHtml += '<td class="' + cClass + '" ><img src="' + cPath + 'leer.gif" width="' + this.getStartOffset(i) + '" height="' + this.nElementHeight + '"></td>';
						cHtml += '<td class="' + cClass + '" width="' + this.nElementsWidth + '"><P class="' + cClass + '"><nobr>' + this.aElements[i][1] + '</nobr></P></td>';
						cHtml += '<td class="' + cClass + '"><img src="' + (bHasChildren ? cMenuPath + 'weiter' + nLayer + '.gif' : cPath + 'leer.gif') + '" width="' + this.nMoreImageWidth + '" height="13"></td>';
						cHtml += '<td><img src="' + cMenuPath + 'right' + nLayer + '.gif" width="' + this.nEndImageWidth + '" height="' + this.nElementHeight + '" alt=""></TD>';
						break;
					case 2: 
						cHtml += '<td height="' + this.nElementHeight + '" width="' + this.nWidth + '"><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;
				}
				cHtml += '</tr></table>';
//				document.write(cHtml);
			}
			
			if (nLayer == 0) {
				cMenuPath = cPath + 'menu/' + (bPreset && nLayer == 0 ? 'preset/' : '');
				var nWidth = this.getStartImageWidth(i) + this.getStartOffset(this.aElements.length) + this.nElementsWidth + this.nMoreImageWidth + this.nEndImageWidth - 1;
				cHtml += '<table border="0" cellspacing="0" cellpadding="0"><tr>';
				cHtml += '<td class="' + cClass + '"><img src="img/leer.gif" width="' + nWidth + '" height="1"></td>';
				cHtml += '</tr></table>';
			}
		}
		return (cHtml);
	};
	
	this.close = function () {
		if (this.aElements) {
			this.update (null);
			if (this.oChild) this.oChild.close();
			if (this.oParent) {
				this.oParent.highlight(null);
				this.oParent.close();
			}
		}
	};
	
	if (this.nLevel == 0) {
		this.bSuspended = false;
		this.aPos = [148, 26];
		this.close = function() {
			if (this.oChild) this.oChild.close();
		}

		if (window.StartPage) 
			this.aPos = [60, 234];
		else
			this.aPos = [2, 116];
		this.update (aMenuEntries);
	}
}



function Menu (nLevel) {
	this.init = BTextMenu;
	this.init (nLevel);
	this.bFolded = null;
	this.nElementHeight = 21; 
	this.nChildOffset = -10;
	this.nSelected = null;
	this.nPreSelected = null;
	this.nHigh = null;
	this.nOffset = 7;
	this.nStartImageWidth = 16;
	this.nEndImageWidth = 16;
	this.nMoreImageWidth = 22;

	
	this.calculateSize = function() {
		this.nElementsWidth = this.getElementsWidth();
		if (this.nLevel == 0) this.nElementsWidth = Math.max (this.nElementsWidth, 113);
		this.nWidth = this.nStartImageWidth + this.nEndImageWidth + this.nMoreImageWidth + this.nElementsWidth +  this.getStartOffset(0);
	};

	this.getStartOffset = function (nElement) {
		nOffset = (this.aElements.length - nElement - 1) * this.nOffset + 1;
		return (nOffset);
	}

/*
	Bestimmt die Position des aktuellen Untermenüs
*/	
	this.getChildPosition = function() {
		var aPos = [0, 0];
		aPos[0] = this.aLayers[0].get('left') + this.getStartOffset(this.nSelected) + this.nElementsWidth + this.nStartImageWidth + this.nMoreImageWidth + this.nEndImageWidth - this.oChild.getStartOffset(0) + this.nChildOffset;
		aPos[1] = (this.bFolded === true || this.bFolded === false ? _aMs[0].aPos[1] : this.aLayers[0].get('top') + this.nSelected * this.nElementHeight);
		return (aPos);
	}


/*
	Bestimmt die Position des aktuellen Menüs
*/	
	this.BMenuGetPosition = this.getPosition;
	this.getPosition = function () {
		var aPos = this.BMenuGetPosition();
		aPos[5] = aPos[5] + 1;
		return (aPos);
	};


	this.getContent = function (nLayer) {
		var cPath = (window.getRelativeWebRoot ? window.getRelativeWebRoot() : '') + CONFIG['Images']['Dir'];
		var cHtml = '';
		var bPreset, bHasChildren, cClass;
		if (this.aElements.length) {
			for (var i=0; i<this.aElements.length; i++) {
				bHasChildren = (this.aElements[i][2] && this.aElements[i][2].length > 0);
				bPreset = false && (typeof(this.nPreSelected)=='number' && (i == this.nPreSelected));
				cHtml += '<table border="0" cellspacing="0" cellpadding="0" width="' + (this.getStartOffset(i) + this.nElementsWidth + this.nStartImageWidth + this.nMoreImageWidth + this.nEndImageWidth) + '"><tr>';		
				switch (nLayer) {
					case 0:
					case 1: 
						var cMenuPath = cPath + 'menu/' + (bPreset && nLayer == 0 ? 'preset/' : '');
						cClass = 'menu' + (nLayer == 1 ? 'act' : (bPreset ? 'preset' : ''));
						cHtml += '<td><img src="' + cPath + 'leer.gif" width="' + this.getStartOffset(i) + '" height="' + this.nElementHeight + '"></td>';
						cHtml += '<td><img src="' + cMenuPath + 'left' + nLayer + '.gif" width="' + this.nStartImageWidth + '" height="' + this.nElementHeight + '" alt=""></TD>';
						cHtml += '<td class="' + cClass + '" width="' + this.nElementsWidth + '"><P class="' + cClass + '"><nobr>' + this.aElements[i][1] + '</nobr></P></td>';
						cHtml += '<td class="' + cClass + '"><img src="' + (bHasChildren ? cMenuPath + 'weiter' + nLayer + '.gif' : cPath + 'leer.gif') + '" width="' + this.nMoreImageWidth + '" height="13" alt=""></td>';
						cHtml += '<td><img src="' + cMenuPath + 'right' + nLayer + '.gif" width="' + this.nEndImageWidth + '" height="' + this.nElementHeight + '" alt=""></TD>';
						break;
					case 2: 
						if (this.oParent && ((this.oParent.nSelected + i) < this.oParent.aElements.length)) {
							cHtml += '<TD><a ' + this.oParent.getLink(this.oParent.nSelected + i) + ' onmouseover="return _aMs[' + this.oParent.nLevel + '].mo(' + (eval(this.oParent.nSelected + i)) + ',1)" onmouseout="return _aMs[' + this.oParent.nLevel + '].mo(' + i + ')"><IMG src="' + cPath + 'leer.gif" width="' + this.getStartOffset(i) + '" height="' + this.nElementHeight + '" alt="" border="0"></a></TD>';
						} else {
							cHtml += '<TD><IMG src="' + cPath + 'leer.gif" width="' + this.getStartOffset(i) + '" height="' + this.nElementHeight + '" alt=""></TD>';
						}
						
						cHtml += '<td height="' + this.nElementHeight + '" width="' + this.nWidth + '"><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;
				}
				cHtml += '</tr></table>';
			}
			
			if (nLayer == 0) {
				cHtml += '<table border="0" cellspacing="0" cellpadding="0"><tr>';
				cMenuPath = cPath + 'menu/' + (bPreset && nLayer == 0 ? 'preset/' : '');
				cClass = 'menu' + (nLayer == 1 ? 'act' : (bPreset ? 'preset' : ''));
				var nWidth = this.nStartImageWidth + this.getStartOffset(this.aElements.length) + this.nElementsWidth + this.nEndImageWidth + this.nMoreImageWidth - 3;
				cHtml += '<td><img src="' + cPath + 'leer.gif" width="' + (this.getStartOffset(this.aElements.length-1) + 1) + '" height="1"></td>';
				cHtml += '<td class="' + cClass + '"><img src="img/leer.gif" width="' + nWidth + '" height="1"></td>';
				cHtml += '</tr></table>';
			}
		}
		return (cHtml);
	};
	
	this.close = function () {
		if (this.aElements) {
			this.update (null);
			if (this.oChild) this.oChild.close();
			if (this.oParent) {
				this.oParent.highlight(null);
				this.oParent.close();
			}
		}
	};
	
}

