var ns=0; //Netscape oder Mozilla endeckt
var ns4=0; //Netscape 4 endeckt
var ie=0; //Internet Explorer oder Opera endeckt
var na=0; //Unbekanter Browser, verwendet wird "getElementById"
var v=0; //1. Stelle der Browser-Versionsnummer 
var theObj;var checkrollover;var actuallayer;var theAnchorStyle;var theHTML;
var themouseoverbutton = 0;
var themouseoverlayer = 0;
var tpx=new Array("dwn_titel","dwn_ag","dwn_pro","dwn_kar","dwn_kon"); // Array speichert Bildnamen fuer rote Linie unter drop-down-Menues

red_gray = new Image(); //Image fr rote Linie, die mit drop-down-Menue mitlaeuft (graues Bild fuer keinen Rollover)
red_gray.src = "../pix/shared/gray.gif";
red_edge = new Image(); //Image fr rote Linie, die mit drop-down-Menue mitlaeuft (Ecke, erstes Bild)
red_edge.src = "../pix/shared/red_edge.gif";
red_line = new Image(); //Image fr rote Linie, die mit drop-down-Menue mitlaeuft (eigentliche rote Linie)
red_line.src = "../pix/shared/red_line.gif";

function initLayer(){ //Hier werden die Menuepunkte festgelegt, die Werte werden in der folgenden Kommentarzeile erlaeutert:
   	//drawLayer(Layername,Position links,Position oben,Breite,Zellenhoehe,Anzahl Submenues,'Link Sub 1','Link Sub n','Link-Text Sub 1','Link-Text Sub n');
	
    chkBrowser();
    checkmyxpos();
    
    drawLayer('menu1',left_start_x + 395,94,88,15,2,'../agentur/einblick.php','../agentur/service.php','Einblicke','Full-Service');
	//drawLayer('menu2',446,94,88,15,4,'../projekte/print.htm','../projekte/internet.htm','../projekte/mm.htm','../projekte/messe.htm','Print','Internet','Multimedia','Messen'); // Projekte mit "Messen"
	drawLayer('menu2',left_start_x + 446,94,88,15,4,'../projekte/print.php','../projekte/internet.php','../projekte/multimedia.php','../projekte/messen.php','Print','Internet','Multimedia','Messen'); // Projekte ohne "Messen"
	//drawLayer('menu3',513,94,88,15,1,'../karriere/jobs.htm','Jobs'); // Vorerst kein Submenue bei "Karriere"
	drawLayer('menu4',left_start_x + 581,94,88,15,1,'../kontakt/anfahrt.php','Anfahrt');
	drawLayer('menu5',left_start_x + 642,94,86,15,2,'../extras/links.php','../extras/glossar.php','Links','Glossar');
}

function drawLayer(layId,theLeft,theTop,theWidth,theCellHeight,subCount){

	if(ns==1 && v<5){ // wenn NS4
		theAnchorStyle="font-family: Verdana, Arial, Helvetica; font-size: 8pt;text-decoration: none;color: #000000";
	}else{
		theAnchorStyle="font-family: Verdana, Arial, Helvetica; font-size: 8pt;text-decoration: none";
	}
	
	theHTML = "<div id=\""+layId+"\" style=\"position: absolute; left: "+theLeft+"px; top: "+theTop+"px; width: "+theWidth+"px; height: "+(theCellHeight*subCount+7)+"px; z-index:1; visibility: hidden; background-color: #E6E7E8; background-color: #E6E7E8; border-color: #B3000D; border-left-width:1px; border-left-style:solid; border-bottom-width:1px; border-bottom-style:solid\"";
	theHTML += " onmouseover=\"layerAction(1);\" onmouseout=\"layerAction(0);hideM(\'"+layId+"\')\">";
	theHTML += "<table width=\""+theWidth+"\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#E6E7E8\">";
	
	for(i=0;i<subCount;i++){
		theHTML += "<tr><td height=\""+theCellHeight+"\" onmouseover=\"javascript:this.style.backgroundColor =\'#B3000D\';";
		theHTML += "if(ie==1){this.children.tags('\A\')[0].style.color = \'#FFFFFF\'}\"";
		theHTML +=" onmouseout=\"javascript:this.style.backgroundColor =\'#E6E7E8\';";
		theHTML +="if(ie==1){this.children.tags('\A\')[0].style.color = \'#282828\'}\"";
		theHTML +="onmouseup=\"javascript:location.href=\'"+drawLayer.arguments[i+6]+"\'\" >";
		theHTML += "<a href=\""+drawLayer.arguments[i+6]+"\" onmouseover=\"layerAction(1)\" ";
		theHTML += "onmouseout=\"layerAction(0);hideM(\'"+layId+"\')\" ";
		theHTML += "style=\""+theAnchorStyle+"\">&nbsp;";
		theHTML += drawLayer.arguments[i+6+subCount]+"</a></td></tr>";
	}
	theHTML += "</table></div>";
	if(ns4!=1){ // wenn nicht NS4, dann write menues ...
		document.writeln(theHTML);
	}
}

function chkBrowser(){
	if (navigator.appName=="Netscape"){
		ns=1;
		v=navigator.appVersion.substring(0,1);
	}else if(navigator.appName=="Microsoft Internet Explorer"){
		ie=1;
		v=navigator.appVersion.substring(22,23);
	}else{
		na=1;
	}
	if(ns==1 && v<5){ // wenn NS4
		ns4=1; // Netscape 4 endeckt fr spaetere Fallunterscheidungen ...
	}
}

function initObj(theLayId){
	if(ns==1 && v<5){ // wenn NS4
		result=eval("document.layers."+theLayId);
	}else if((ns==1 && v>=5)||(ie==1 && v>=5)||(na==1)){ // wenn NS5++ oder IE5++ oder Browser unbekannt
		result=document.getElementById(theLayId);
	}else if(ie==1 && v<5){ // wenn IE4
		result=document.all(theLayId);
	}
	return result;
}

function showM(theLayId){
	if(ns4!=1){ // wenn nicht NS4, then do it ...
	
		if(actuallayer){ // Bei Rollover ueber Hauptmenuebutton "alten" Layer zuerst ausblenden
			closeLayer();
		}
	
		themouseoverbutton = 1;
		clearTimeout(checkrollover);
		var theObj=initObj(theLayId); //ermittelt das erforderliche Objekt (all, layers, getElementById)
		theObj.style.visibility  = "visible"; //NS6++; IE5++; IE 4++; Mozilla
	}
}

function hideM(theLayId){
	if(ns4!=1){ // wenn nicht NS4, then do it ...
		actuallayer=theLayId;
		themouseoverbutton = 0;
		checkrollover=setTimeout("startTimeout()", 250);
	}
}

function startTimeout(theLayId){
	if(themouseoverlayer==0&&themouseoverbutton==0){
		clearTimeout(checkrollover);
		closeLayer();
	}
}

function closeLayer(){
	var theObj=initObj(actuallayer); //ermittelt das erforderliche Objekt (all, layers, getElementById)
	theObj.style.visibility  = "hidden"; //NS6++; IE5++; IE 4++; Mozilla
	changeRedLine(0,0,0,0,0); // Funktion, fuer die rote Linie, die mit den drop-down-menues mitlaeuft
}

function layerAction(theAction){
	clearTimeout(checkrollover);
	themouseoverlayer = theAction;
}

function changeRedLine(){ // Funktion, die die rote Linie, die mit den drop-down-menues mitlaeuft "zeichnet"
	if(ns4!=1){ // wenn nicht Netscape 4!
		for(i=0;i<tpx.length;i++){
			if(changeRedLine.arguments[i]==0){
				document.images[tpx[i]].src=red_gray.src;
			}else{
				if(i==0){
					document.images[tpx[i]].src=red_edge.src;
				}else{
					document.images[tpx[i]].src=red_line.src;
				}
			}
		}
	}
}

// Neupositionierung der Men-Layer nach Resize ------------------------------------>

function domoveme(){
    checkmyxpos();
    
    document.getElementById('menu1').style.left = left_start_x + 395;
    document.getElementById('menu2').style.left = left_start_x + 446;
    document.getElementById('menu4').style.left = left_start_x + 581;
    document.getElementById('menu5').style.left = left_start_x + 642;
    
    //window.document.body.style.background = '#B3000D';
}

// Ermittlung der Contentposition Links ----------------------------------------->

function checkmyxpos(){
    // Fenster-Breite wird ermittelt zur Positionierung der Men-Layer    
    left_start_x = 0;
    scrwidth = window.innerWidth; // Alle Browser ausser IE
    left_start_x = (scrwidth/2)-370.5; // Relative X-Position des Contents, von der aus die Mens positioniert werden knnen
    
    if (scrwidth/scrwidth != 1){ // Falls IE; Diese "umst?liche" Prfung muss sein, da manche Browser sich als IE ausgeben und deshalb nicht der UserAgent herangezogen werden kann
        scrwidth = document.body.offsetWidth; 
        left_start_x = (scrwidth/2)-382; // Relative X-Position des Contents, von der aus die Mens positioniert werden knnen
    }
    if (scrwidth/scrwidth != 1){ // Falls immer noch kein sinnvolles Ergebnis, wird Menanzeige ber ns4=TRUE unterdrckt
        ns4 = 1;
    }
    if (ie == 1 && navigator.platform=="MacPPC") { // IE auf Mac macht Unsinn: raus!
        ns4 = 1;
    }
}

// Menueposition fuer Fenstergroesse anpassen -Initialisierung


  window.onresize = domoveme;
  
