var speedPX = 30;
var speedInt = 20;

var speedClosePX = 50;
var speedCloseInt = 10;

var isIE6 = navigator.appVersion.match(/MSIE 6/) == "MSIE 6";

var buttID = "nav_", subID="sub_", aktiv, subAktiv=0,ieSel;
var oMove = new Array();
var bMove = new Array(true,true,true,true,true,true,true);
var oSubHide = new Array();

var navi = {
	eClip:function(o,t,h) {
		o.style.clip = "rect("+t+"px 168px "+h+"px auto)";
	},
	
	eTop:function(o,t) {
			o.style.top = t+"px";
	},
	
	openSite:function(iN) {
		document.location.href=aNav[iN-1][0][1];
	},
	
	openURL:function(url,iN) {
		if (bMove[iN]) document.location.href=url;
	},
	
	subMain:function(iN) {
		return aNav[iN-1].length>1;
	},
	
	eMove:function(iN, dir) {
		var id = subID+iN;
		var fH = parseInt(fkt.gE(id).style.height);
		var t = parseInt(fkt.gE(id).style.top);
		if (dir)	t = t+speedPX; else t = t-speedClosePX;
		if (t>28) {
			t=28;
			window.clearInterval(oMove[iN]);
			bMove[iN]=true;
		}
		if (t<28-fH) {
			t=28-fH;
			if (aktiv==iN) button = "hi"; else button= "lo";
			navi.changeBild(iN, "main_"+button+"_0" );
			fkt.gE("sub_"+iN).style.display = "none";
			window.clearInterval(ieSel);
			if (subAktiv==0) ieSel = window.setInterval("fkt.showIESelects();",10);
			window.clearInterval(oMove[iN]);
			bMove[iN]=true;
		}
		navi.eClip(fkt.gE(id),28-t,fH+17);
		navi.eTop(fkt.gE(id),t);
	},

	moveSub:function(iN,dir) {
		bMove[iN] = false;
	  if (dir==0 && iN==subAktiv) { subAktiv=0; navi.clearAllSubSub(iN); }
		window.clearInterval(oSubHide[iN]);
		window.clearInterval(oMove[iN]);
		oMove[iN] = window.setInterval("navi.eMove("+iN+","+dir+");",speedInt);
	},
	
	changeBild:function(iN,temp) {
		var bild;
		if (bild=fkt.gE(buttID+iN)) bild.src = sBildpfad + temp +iN+".gif";
	},
	
	clearAllSubSub:function(iN) {
		for (var i=1;i<aNav[iN-1].length;i++) { //alle Menüpunkte durchgehen
			fkt.gE("sublink_"+iN+"_"+i).className='';
			if (aNav[iN-1][i][2]!=0)  { //wenn subsub vorhanden ist
				fkt.gE("sub_"+iN+"_"+i).style.display="none";
			}
		}
	},
	
	navOver:function(iN) {
		window.clearInterval(ieSel);
		window.clearInterval(oSubHide[iN]);
		fkt.hideIESelects();
		navi.clearAllSubSub(iN);
		if (iN!=subAktiv) {
			if ( subAktiv!=0 && navi.subMain( subAktiv ) ) {
				navi.moveSub(subAktiv,0);
				bMove[subAktiv] = false;
			}
			subAktiv = iN;
			navi.changeBild(iN, ( navi.subMain(iN) ? "sub_0" : "main_hi_0" ) );
			if ( navi.subMain(iN) ) {
				var oSub = fkt.gE("sub_"+iN);
				oSub.style.display = "block";
				bMove[iN] = false;
				var fH = parseInt(oSub.style.height);
				navi.eClip(oSub,fH,fH+17);
				navi.eTop(oSub,28-fH);
				navi.moveSub(iN,1);
			} 
		}
	},
	
	navOverSub:function(iN,iS) {
		navi.clearAllSubSub(iN);
		fkt.gE("sublink_"+iN+"_"+iS).className='aktivbutt';
		window.clearInterval(oSubHide[iN]);
		if (bMove[iN]){
			subAktiv=iN;	
			if (aNav[iN-1][iS][2]!=0)  { 
				fkt.gE("sub_"+iN+"_"+iS).style.display = "block";
			}
		}
	},
	
	navOut:function(iN) {
		if ( !navi.subMain(iN) ) {
			if (aktiv==iN) button = "hi"; else button= "lo";
			navi.changeBild(iN, "main_"+button+"_0" );
			window.clearInterval(ieSel);
			ieSel = window.setInterval("fkt.showIESelects();",10);
			subAktiv = 0;
		} else {
			window.clearInterval(oSubHide[iN]);
			oSubHide[iN] = window.setInterval("navi.moveSub("+iN+",0);",500);
		}
	},
	
	navOutSub:function(iN,iS) {
		window.clearInterval(oSubHide[iN]);
		oSubHide[iN] = window.setInterval("navi.moveSub("+iN+",0);",500);
	},
	
	createNav:function() {
		var html = "", html_sub, o = fkt.gE("navigation"), klasse;
		if (o) {
			for (var i=1;i<=aNav.length;i++) {
				html_sub = "";
				if (aktiv==i) {button = "hi"; hoch=37;} else {button= "lo"; hoch=25;}
				html += '<img src="'+sBildpfad+'main_'+button+'_0'+i+'.gif" alt="" onmouseover="navi.navOver('+i+');" onmouseout="navi.navOut('+i+');" id="nav_'+i+'" onclick="navi.openSite('+i+');" style="cursor:pointer;width:169px;" />'; 
				for (var j=1;j<aNav[i-1].length;j++) {
					html_subsub = "";
					if (j==aNav[i-1].length-1) klasse='class="letzter"'; else klasse="";
					html_sub += '<li '+klasse+'><a href="'+aNav[i-1][j][1]+'" id="sublink_'+i+'_'+j+'" onmouseover="navi.navOverSub('+i+','+j+');" onmouseout="navi.navOutSub('+i+','+j+');">'+aNav[i-1][j][0]+'</a></li>';
					if (aNav[i-1][j][2]!=0)  {
						for (var k=2;k<aNav[i-1][j].length; k++) {
							html_subsub += '<li><a href="'+aNav[i-1][j][k][1]+'" onmouseover="navi.navOverSub('+i+','+j+');" onmouseout="navi.navOutSub('+i+','+j+');">'+aNav[i-1][j][k][0]+'</a></li>';
						}
						o.innerHTML += '<div id="sub_'+i+'_'+j+'" class="subsub" style="top:'+(44+31*(j-1))+'px;left:'+(169*i)+'px;height:'+(12+15*(aNav[i-1][j].length-2))+'px"><ul class="subsub_main">'+html_subsub+'</ul></div>'
					}
				}
				if (html_sub!="") {
					o.innerHTML += '<div id="sub_'+i+'" class="sub" style="left:'+(169*(i-1)+1)+'px;top:44px;"><ul class="sub_main">'+html_sub+'</ul></div></div>';
					var submenu = document.getElementById("sub_"+i);
					submenu.style.display = "block"; //height only readable if displayed
					submenu.style.height = submenu.offsetHeight+14 + "px";
					submenu.style.display = "none";
				}
			} 
			o.innerHTML = '<div id="navmain">'+html+'</div>' + o.innerHTML;			
		}
	}
	
}

window.onunload = function () {
	if(fkt.gE('navigation')) {fkt.gE('navigation').innerHTML='';}
}

// init JS-Funktionen
window.onload = function () {
	
	prepareImageSwap(document.body);

	//Navigation eintragen (IE6 sofort, FF verzögert)
	/*if (isIE6) navi.createNav(); 
	else setTimeout("navi.createNav();",20);*/

	
} //onload


//Klasse mit allgemein gültigen Funktionen
var fkt = {	
	gE: function(id) {
		return document.getElementById(id);
	},	
	hideIESelects: function() {
		if (isIE6) {
			var s = document.getElementsByTagName("select");
			for (var i=0;i<s.length;i++) s[i].style.visibility = "visible";
		}	
	},
	showIESelects: function() {
			// make select boxes visible
			if (isIE6) {
				var s = document.getElementsByTagName("select");
				for (var i=0;i<s.length;i++) s[i].style.visibility = "visible";
			}
	}
}

function prepareImageSwap(elem) { 
//Do not delete these comments. 
//Non-Obtrusive Image Swap Script V1.1 by Hesido.com 
//Attribution required on all accounts 
    if (typeof(elem) == 'string') elem = document.getElementById(elem); 
    if (elem == null) return; 
    var regg = /(.*)(_lo\.)([^\.]{3,4})$/ ;
    var prel = new Array(), img, imgList, imgsrc, mtchd; 
    imgList = elem.getElementsByTagName('img'); 
    for (var i=0; img = imgList[i]; i++) { 
        if (!img.rolloverSet && img.src.match(regg)) { 
            mtchd = img.src.match(regg); 
            img.hoverSRC = mtchd[1]+'_hi.'+ mtchd[3]; 
            img.outSRC = img.src; 
            if (img.hoverSRC) {preLoadImg(img.hoverSRC); img.onmouseover = imgHoverSwap;} 
	        if (img.outSRC) {preLoadImg(img.outSRC); img.onmouseout = imgOutSwap;}       
            img.rolloverSet = true; 
        } 
    } 
    function preLoadImg(imgSrc) { 
        prel[prel.length] = new Image(); prel[prel.length-1].src = imgSrc; 
    } 
} 
function imgHoverSwap() {this.src = this.hoverSRC;} 
function imgOutSwap() {this.src = this.outSRC;} 




