var set=0;
var row2Id;
var buttonOut=0;
var graph=0;
var noWidthSetBack=0;
var finish=0;
var oldCtrWidth;
var oldMarginLeft;
var oldLftCtrFloat;
var oldCntWidth;
var oldCntFloat;

setBackOk=0;

function initSubNav2(type) { 
	if (isThereASubnav==1) {
		writeNav2(type);
	} 
}

function writeNav2(type) {
	if (type=="normal") {
		document.write('<div class="sgHide" id="sgHide" style="display:none;">');
		for (var p=0;p<navItems.length;p++) {
		document.write ('<span id="sub'+navItems[p].id+'_2">');
		if (navItems[p].subNav.length==0) {
		} else { 
			for (var i=0; i<navItems[p].subNav.length; i++) {
				document.write("<div class='unselected' id='_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2'><div onmouseover='changeStyleModBtn(1,this); setVarfor2Row();' onmouseout='changeStyleModBtn(0,this);' class='"+wscPrefix+"mnvBtnRow02Area' id='"+wscPrefix+"mnvBtnRow02Area_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2'><div class='"+wscPrefix+"mnvBtnRow02BdrHorz' id='"+wscPrefix+"mnvBtnRow02BdrHorz_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2'><div class='"+wscPrefix+"mnvBtnRow02BdrVert' id='"+wscPrefix+"mnvBtnRow02BdrVert_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2'><div class='"+wscPrefix+"ctlMnvBtnRow02'><div class='"+wscPrefix+"ctlBdrIn'><div class='"+wscPrefix+"ctlRoundCornLT' id='"+wscPrefix+"mnvBtnRow02RoundCornLT_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2'><div class='"+wscPrefix+"ctlRoundCornRT' id='"+wscPrefix+"mnvBtnRow02RoundCornRT_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2'><div class='"+wscPrefix+"ctlRoundCornLB' id='"+wscPrefix+"mnvBtnRow02RoundCornLB_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2'><div class='"+wscPrefix+"ctlRoundCornRB' id='"+wscPrefix+"mnvBtnRow02RoundCornRB_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2'><div class='"+wscPrefix+"mnvBtnRow02Ctr'><div class='"+wscPrefix+"mnvBtnRow02Cnt' id='"+wscPrefix+"mnvBtnRow02Cnt_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2'><div class='"+wscPrefix+"mnvBtnRow02Lft' id='"+wscPrefix+"mnvBtnRow02Lft_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2'><div class='"+wscPrefix+"mnvBtnRow02Rgt' id='"+wscPrefix+"mnvBtnRow02Rgt_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2'><div class='pad'><a id='"+wscPrefix+"mnvBtnRow02Lnk_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2' class='"+wscPrefix+"mnvBtnRow02Lnk' href='"+navItems[p].subNav[i].uri+"'><span class='background'><span class='text'>"+navItems[p].subNav[i].title+"</span></span></A></div></div></div></div></div></div></div></div></div></div></div></div></div><div class='ctlFloatClr'><div class='ctlEmptyBox'><span>&nbsp;</span></div></div></div></div>"); 
			}
		}
		document.write('</span>');
		}
		document.write('</div>');
	} else {
		document.write('<div class="sgHide" style="height:0px; float:left; overflow:hidden;">');
		for (var p=0;p<navItems.length;p++) {
			document.write ('<span id="sub'+navItems[p].id+'"');
			if (navItems[p].subNav.length==0) {
			} else { 
				for (var i=0; i<navItems[p].subNav.length; i++) {
					var write="<div class='unselected' id='_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2'><div onmouseover='changeStyleModBtn(1,this); setVarfor2Row();' onmouseout='changeStyleModBtn(0,this);' class='"+wscPrefix+"mnvImgBtnRow02Area' id='"+wscPrefix+"mnvImgBtnRow02Area_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2'><div class='"+wscPrefix+"mnvImgBtnRow02Ctr'><div class='pad'><a id='"+wscPrefix+"mnvImgBtnRow02Lnk_"+navItems[p].id+"_"+navItems[p].subNav[i].id+"_dyn_2' class='"+wscPrefix+"mnvImgBtnRow02Lnk' href='"+navItems[p].subNav[i].uri+"'>";
				
					if (navItems[p].subNav[i]) {
						write=write+"<img alt='"+navItems[p].subNav[i].title+"'";
					}
					if (navItems[p].subNav[i].link[0]) {
						write=write+"src='"+navItems[p].subNav[i].link[0].src+"' style='width:"+navItems[p].subNav[i].link[0].width+"px; height:"+navItems[p].subNav[i].link[0].height+"px;' /></A></div></div><div class='ctlFloatClr'><div class='ctlEmptyBox'><span>&nbsp;</span></div></div></div></div>";
					} else {
						write=write+"/></A></div></div><div class='ctlFloatClr'><div class='ctlEmptyBox'><span>&nbsp;</span></div></div></div></div>";
					}
					document.write(write); 
				}
			}
			document.write('</span>');
		}		
		document.write('</div>');
	}
}

function navRightOver (id) {
	if (document.getElementById("sgHide"))
		document.getElementById("sgHide").style.display="";
		
	//Wenn mosueOver Navigationspunkt Unterpunkte besitzt
	if ((document.getElementById("mnvBtnRow02Lnk_"+id.split("_")[1]+"_01"+"_dyn_2")) || (document.getElementById("mnvImgBtnRow02Lnk_"+id.split("_")[1]+"_01"+"_dyn_2"))) {		

	//Wenn der mouseOver Navigationspunkt nicht der aktuell selektierte Navigationspunkt ist
	if(document.getElementById(id).parentNode.className!="selected") {
		var buttonWidth=0;	
		if (document.getElementById("mnvBarRow02Area")) {
			var array=new Array();
			array=document.getElementsByTagName("div");
			var count=0;
			var widthInFirstRow=0;
			var finish=0;
			var copleteWidthFirstRow=0;
			
			//Breite der Navigationspunkte in der ersten Ebene berechnen
			for (var i=0;i<array.length;i++) {
				if ((array[i].className=="mnvBtnRow01Area") || (array[i].className=="mnvImgBtnRow01Area")) {
					count=count+1;
					if (array[i].parentNode.className=="mouseOver") {
						finish=1;
					}
					if (finish!=1) {
						widthInFirstRow=widthInFirstRow+array[i].offsetWidth;
					}
					copleteWidthFirstRow=copleteWidthFirstRow+array[i].offsetWidth;
				}
			}			
			
			
			// Margin-left der 2. Navigationsebene berechnen
			var marWidth=getElementPosition(id).x-getElementPosition("mnvBarRow02Area").x;

			//Breite der Navigationspunkte der 2. Ebene des mouseOver Navigationspunktes berechnen
			var width=0;
			for (var k=1;k<20;k++) {
				if (document.getElementById("mnvBtnRow02Lnk_"+id.split("_")[1]+"_0"+k+"_dyn_2")) {
					width=width+document.getElementById("mnvBtnRow02Lnk_"+id.split("_")[1]+"_0"+k+"_dyn_2").parentNode.offsetWidth;
				} else if (document.getElementById("mnvImgBtnRow02Lnk_"+id.split("_")[1]+"_0"+k+"_dyn_2")) {
					width=width+document.getElementById("mnvImgBtnRow02Lnk_"+id.split("_")[1]+"_0"+k+"_dyn_2").offsetWidth;
					graph=1;
				}
			}
			
			//Die komplette Breite der Navigation berechnen
			var fullWidth=document.getElementById("mnvBarRow02Area").offsetWidth;

			//Platz in der 2. Ebene berechen
			var spaceInSecondRow=fullWidth-marWidth;
			
			marginRight=fullWidth-widthInFirstRow-document.getElementById(id).offsetWidth;		

			//Wenn keine Untepunkte vorhanden sind, den Fake Unterpunkt einblenden um der 2. Ebene die Höhe zu geben
			if (width>0) {
				document.getElementById("subselectedEmpty").style.display="none";
			} else {
				document.getElementById("subselectedEmpty").style.display="";			
			}
			
			//Wenn die Unterpunkte nicht breiter sind, als der Platz in der 2. Ebene
				if (width<spaceInSecondRow) {
					document.getElementById("mnvBarRow02Cnt").style.cssFloat="left";
					document.getElementById("mnvBarRow02Cnt").style.width=width+1+"px";
					document.getElementById("mnvBarRow02Rgt").style.cssFloat="left";
					document.getElementById("mnvBarRow02Cnt").style.paddingLeft=marWidth+"px";
					document.getElementById("mnvBarRow02Ctr").style.marginLeft="0px";
					document.getElementById("mnvBarRow02Ctr").style.width=fullWidth+"px";
					document.getElementById("mnvBarRow02Lft").style.cssFloat="left";
				//Wenn die Unterpunkte breiter sind als der Platz in der 2. Ebene
				} else {
					document.getElementById("mnvBarRow02Cnt").style.paddingLeft="0px";
					if (navigator.userAgent.match("Firefox/3")) {
						document.getElementById("mnvBarRow02Ctr").style.width=width+1+"px";
						document.getElementById("mnvBarRow02Cnt").style.width=width+1+"px";
					} else {
						document.getElementById("mnvBarRow02Ctr").style.width=width+"px";
						document.getElementById("mnvBarRow02Cnt").style.width=width+"px";					
					}
					document.getElementById("mnvBarRow02Ctr").style.marginLeft=fullWidth-width+"px";
					document.getElementById("mnvBarRow02Lft").style.cssFloat="right";
					document.getElementById("mnvBarRow02Cnt").style.cssFloat="right";
				}
		}
	} else if (buttonOut==1) {
		setBack();
		hidenav();
	} 
	} else {
		setBack();
		hidenav();
	}	
		buttonOut=1;
		if (document.getElementById("sgHide"))
			document.getElementById("sgHide").style.display="none";
}
	

function navRight () {
		if (document.getElementById('surrounding2RowCtr')) {
			document.getElementById('surrounding2RowCtr').style.display='';
		}
		var buttonWidth=0;	
		
		if (document.getElementById("mnvBarRow02Area")) {
			var array=new Array();
			array=document.getElementsByTagName("div");
			var firstRowId;
			var j=0;
			while (j<array.length) {
				if (array[j].className=="selected") {
					firstRowId=array[j].id;
					j=array.length;
				} 
				j=j+1;
			}
			var align="left";
			if (getElementPosition("mnvBarRow02Cnt").x!=getElementPosition(firstRowId).x) {
				align="right";
			}

			/* firstRow of Nav */
			var fullWidth=document.getElementById("mnvBarRow02Area").offsetWidth;	

			var freeSpaceForSecondRow=fullWidth-(getElementPosition("mnvBtnRow01Area"+firstRowId).x-getElementPosition("mnvBarRow02Area").x);

			var secondRowWidth=document.getElementById("surrounding2RowCtr").offsetWidth;

			var marWidth=getElementPosition(firstRowId).x-getElementPosition("mnvBarRow02Area").x;
			
			if (document.getElementById("surrounding2RowCtr").offsetWidth>freeSpaceForSecondRow) {
				document.getElementById("mnvBarRow02Ctr").style.marginLeft=fullWidth-secondRowWidth+"px";
				document.getElementById("mnvBarRow02Cnt").style.paddingLeft="0";
				if (align=="right") {
					if (navigator.userAgent.match("Firefox/3")) {
						document.getElementById("mnvBarRow02Ctr").style.width=fullWidth-(fullWidth-secondRowWidth)+2+"px";
						document.getElementById("mnvBarRow02Cnt").style.width=fullWidth-(fullWidth-secondRowWidth)+2+"px";
					} else {
						document.getElementById("mnvBarRow02Ctr").style.width=fullWidth-(fullWidth-secondRowWidth)+"px";
						document.getElementById("mnvBarRow02Cnt").style.width=fullWidth-(fullWidth-secondRowWidth)+"px";					
					}
					//document.getElementById("mnvBarRow01Area").style.cssFloat="right";
					//document.getElementById("mnvBarRow02Area").style.cssFloat="right";
				}
			} else {
				document.getElementById("mnvBarRow02Ctr").style.marginLeft=marWidth+"px";
				document.getElementById("mnvBarRow02Cnt").style.paddingLeft="0px";
				document.getElementById("mnvBarRow02Ctr").style.width=fullWidth-marWidth+"px";
				document.getElementById("mnvBarRow02Cnt").style.width=secondRowWidth+3+"px";
				document.getElementById("mnvBarRow02Lft").style.cssFloat="left";
				document.getElementById("mnvBarRow02Rgt").style.cssFloat="left";
				document.getElementById("mnvBarRow02Cnt").style.cssFloat="none";
			}
			
			var oldMarginLeftLocal=document.getElementById("mnvBarRow02Ctr").style.marginLeft;
			var oldCtrWidthLocal=document.getElementById("mnvBarRow02Ctr").style.width;
			var oldLftCtrFloatLocal=document.getElementById("mnvBarRow02Lft").style.cssFloat;
			var oldCntWidthLocal=document.getElementById("mnvBarRow02Cnt").style.width;
			var oldCntFloatLocal=document.getElementById("mnvBarRow02Cnt").style.cssFloat;
			
		
			if (firstRowId) {
				row2Id=firstRowId.split("_")[1];
			}
		}
			if (set!=1) {		
				if ((document.getElementById('mnvBarRow02Cnt'))|| (document.getElementById('surrounding2RowCtr'))) {
					if (document.getElementById("mnvBarRow02Ctr")) {
						oldMarginLeft=oldMarginLeftLocal;
						oldCtrWidth=oldCtrWidthLocal;
						oldCntWidth=oldCntWidthLocal;
						oldCntFloat=oldCntFloatLocal;
					}
					if (document.getElementById("mnvBarRow02Lft")) {
						oldLftCtrFloat=oldLftCtrFloatLocal;
					}
					set=1;
				}	
		}
		setBackOk=1;
		if (document.getElementById('surrounding2RowCtr')) {
			document.getElementById('surrounding2RowCtr').style.display='none';
		}
	}

function setBack() {
	out=0;
	if (setBackOk==1) {
	if ((document.getElementById("mnvBarRow02Cnt")) || (document.getElementById("surrounding2RowCtr"))) {
		if (oldMarginLeft) {
			document.getElementById("mnvBarRow02Ctr").style.marginLeft=oldMarginLeft;
		}
		if (oldCtrWidth) {
			document.getElementById("mnvBarRow02Ctr").style.width=oldCtrWidth;
		} else {
			document.getElementById("mnvBarRow02Ctr").style.width=document.getElementById("mnvBarRow02Area").offsetWidth+"px";
		}
		if (oldCntWidth) {
			document.getElementById("mnvBarRow02Cnt").style.width=oldCntWidth;
		} else {
			document.getElementById("mnvBarRow02Cnt").style.width=document.getElementById("mnvBarRow02Ctr").offsetWidth+"px";
		}
		if (oldLftCtrFloat) {
			document.getElementById("mnvBarRow02Lft").style.cssFloat=oldLftCtrFloat;
			document.getElementById("mnvBarRow02Rgt").style.cssFloat=oldLftCtrFloat;
		}
		if (oldCntFloat) {
			document.getElementById("mnvBarRow02Cnt").style.cssFloat=oldCntFloat;
		}		
		document.getElementById("mnvBarRow02Cnt").style.paddingLeft="0px";
		document.getElementById("subselectedEmpty").style.display="";
	}
	}
	set=0;	
	buttonOut=0;
}

function setNoWidthSetBack() {
	this.noWidthSetBack=1;
}

function setFinish() {
	finish=1;
}
function checkFinish() {
		window.setTimeout("navRight()",100);
		if (document.getElementById('surrounding2RowCtr')) {
			window.setTimeout("document.getElementById('surrounding2RowCtr').style.display=''",102);
		}
}