// *** CROSS-BROWSER COMPATIBILITY ***
var isDOM   = (document.getElementById ? true : false); 
var isIE4   = ((document.all && !isDOM) ? true : false);
var isIE5   = ((document.all && isDOM) ? true : false);
var isNS4   = (document.layers ? true : false);
var isNS6   = ((isDOM && !isIE5) ? true : false);
var isDyn   = (isDOM || isIE4 || isNS4);

var isOpera = (navigator.userAgent.toLowerCase().match(/opera/) ? true : false);
//var isDOM = (isOpera ? false : isDOM);

function getRef(id) {
	if (isDOM) return document.getElementById(id);
	if (isIE4) return document.all[id];
	if (isNS4) return document.layers[id];
}

function getSty(id) {
	return (isNS4 ? getRef(id) : getRef(id).style);
} 

//if (!document.getElementById) alert("Bitte benutzen Sie einen Browser mit DOM-Unterstützung.\n \nz.B. MS IE 5+, Netscape 7, Opera 7 oder Konquerer 3");

// Defining a few global variables to keep things simpler and to avoid complications
var HexChars = "0123456789ABCDEF";
var RGBHexValue="#FFFFFF";
var RGBDecValue = "255,255,255";

// Created by T.N.W.Hynes - (c) 2002 PalandorZone.com ... Use it freely but leave this line intact
// Conversion function for Hexadecimal to Decimal - FF max
function Hex2Dec(HexVal){
	HexVal=HexVal.toUpperCase();
	var DecVal=0;
	var HV1=HexVal.substring(0,1);
	DecVal=(HexChars.indexOf(HV1)*16);
	HV1=HexVal.substring(1);
	DecVal+=HexChars.indexOf(HV1);
	return DecVal;
}

// Created by T.N.W.Hynes - (c) 2002 PalandorZone.com ... Use it freely but leave this line intact
// Conversion function for Decimal to Hexadecimal - 255 max
function Dec2Hex(DecVal){
	DecVal=parseInt(DecVal);
	if (DecVal > 255 || DecVal < 0){
		DecVal=255;
	}
	var Dig1 = DecVal % 16;
	var Dig2 = (DecVal-Dig1) / 16;
	var HexVal = HexChars.charAt(Dig2)+HexChars.charAt(Dig1);
	return HexVal;
}

init_complete = false;

// Define the manipulatable CSS properties of menu items
//StyleProps = new Array("backgroundColor","borderColor","color");
StyleProps = new Array("backgroundColor","color");

// Define start and end values of changable menu item CSS properties
// Don't use if element's "low/normal" colors defined within HTML-code should be used
// MenuLo_backgroundColor = "#CECED1";
// MenuLo_borderColor ="#CECED1";
// MenuLo_color   ="#ffffff";

MenuHi_backgroundColor  ="#000000";     //BGColor
MenuHi_borderColor ="#000000";  //BorderColor
MenuHi_color   ="#005500";      //(Font)Color

// Define how many steps menu item metamorphosis from normal to hilitie and v.v. will take
schritte = 10;

// Define interval in ms between two metamorphosis steps
MenuIntervalTime = 30;

function highlightTrigger(which) {
	if (init_complete) {
		if (eval("lolite"+which.id)) {
			clearFadeVals(which.id);
		}
		if (!eval("hilite"+which.id)) {
			for(i=0;i<StyleProps.length;i++) { //StyleProperties abklappern
				
				// Startwert ist Basiswert -> init()
				eval("start_" + which.id + StyleProps[i] + " = basis_" + which.id + StyleProps[i]);
	
				eval("ziel_" + which.id + StyleProps[i] + " = new Array(0,0,0)");
				eval("d_" + which.id + StyleProps[i] + " = new Array(0,0,0)");
	
				for(j=0;j<3;j++) { //RGB (=0,1,2) abklappern
					//eval("start_" + which.id + StyleProps[i] + "[" + j + "] = Hex2Dec(MenuLo_" + StyleProps[i] + ".substr(" + (2*j + 1) + ",2))");
					eval("ziel_" + which.id + StyleProps[i] + "[" + j + "] = Hex2Dec(MenuHi_" + StyleProps[i] + ".substr(" + (2*j + 1) + ",2))");
					eval("d_" + which.id + StyleProps[i] + "[" + j + "] = Math.round((ziel_" + which.id + StyleProps[i] + "[" + j + "] - start_" + which.id + StyleProps[i] + "[" + j + "]) / schritte)");
				}
			}
			eval("hilite" + which.id + " = window.setInterval(\"fade('" + which.id + "');\"," + MenuIntervalTime + ")");
		}
	}
}


function lowlightTrigger(which) {
	if (init_complete) {
		if (eval("hilite" + which.id)) {
			clearFadeVals(which.id);
		}
		if (!eval("lolite" + which.id)) {
			for(i=0;i<StyleProps.length;i++) { //StyleProperties abklappern
	
				// Ziel-Werte ergeben sich aus alten Startwerten
				//eval("ziel_" + which.id + StyleProps[i] + " = start_" + which.id + StyleProps[i]);
				//trace("ziel_" + which.id + StyleProps[i] + ": " + eval("ziel_" + which.id + StyleProps[i] + " = start_" + which.id + StyleProps[i]));
				//eval("ziel_" + which.id + StyleProps[i] + " = new Array(0,0,0)");
	
				// Endwert ist Basiswert -> init()
				eval("ziel_" + which.id + StyleProps[i] + " = basis_" + which.id + StyleProps[i]);
	
				eval("start_" + which.id + StyleProps[i] + " = new Array(0,0,0)");
				eval("d_" + which.id + StyleProps[i] + " = new Array(0,0,0)");
	
				for(j=0;j<3;j++) { //RGB (=0,1,2) abklappern
					// Zielwert nicht neu berechnen!
					//eval("ziel_" + which.id + StyleProps[i] + "[" + j + "] = Hex2Dec(MenuLo_" + StyleProps[i] + ".substr(" + (2*j + 1) + ",2))");
					eval("start_" + which.id + StyleProps[i] + "[" + j + "] = Hex2Dec(MenuHi_" + StyleProps[i] + ".substr(" + (2*j + 1) + ",2))");
					eval("d_" + which.id + StyleProps[i] + "[" + j + "] = Math.round((ziel_" + which.id + StyleProps[i] + "[" + j + "] - start_" + which.id + StyleProps[i] + "[" + j + "]) / schritte)");
				}
			}
			eval("lolite" + which.id + " = window.setInterval(\"fade('" + which.id + "');\"," + MenuIntervalTime + ")");
		}
	}
}

function fade(objid) {
	if ( eval("hilite"+objid) || eval("lolite"+objid) ) {
		for (k=0;k<StyleProps.length;k++) {
			eval("document.getElementById('" + objid + "').style." + StyleProps[k] + " = calcFadeVal('" + StyleProps[k] + "','" + objid + "')");
		}
		eval("laufvar" + objid + "++");
		if (eval("laufvar" + objid + "==schritte")) {
			for (k=0;k<StyleProps.length;k++) {
				if (eval("hilite"+objid)) eval("document.getElementById('" + objid + "').style." + StyleProps[k] + " = MenuHi_" + StyleProps[k]);
				if (eval("lolite"+objid)) {
					//eval("document.getElementById('" + objid + "').style." + StyleProps[k] + " = MenuLo_" + StyleProps[k]);
					for (k=0;k<StyleProps.length;k++) {
						tmp_val = "#" + Dec2Hex(eval("ziel_" + objid + StyleProps[k] + "[0]")) + Dec2Hex(eval("ziel_" + objid + StyleProps[k] + "[1]")) + Dec2Hex(eval("ziel_" + objid + StyleProps[k] + "[2]"));
						eval("document.getElementById('" + objid + "').style." + StyleProps[k] + " = \"" + tmp_val + "\"");
					}
				}
			}
			clearFadeVals(objid);
		}
	}
}

function calcFadeVal(styleProp,objid) {
	tmp_startArray = eval("start_" + objid + styleProp);
	tmp_dArray = eval("d_" + objid + styleProp);
	tmp_Array = new Array(3); // 3 Werte für R,G,B
	for (i=0;i<tmp_Array.length;i++) {
		tmp_Array[i] = tmp_startArray[i] + (tmp_dArray[i] * (eval("laufvar"+objid)+1));
	}
	return "#" + Dec2Hex(tmp_Array[0]) + Dec2Hex(tmp_Array[1]) + Dec2Hex(tmp_Array[2]);
}

function clearFadeVals(objid) {
//trace(objid);
	// Initialisiert alle Variablen, Objekte
	for(i=0;i<StyleProps.length;i++) { //StyleProperties abklappern
		for(j=0;j<3;j++) { //RGB (=0,1,2) abklappern
			/*
			eval("start_" + objid + StyleProps[i] + "[" + j + "] = 0 ");
			eval("ziel_" + objid + StyleProps[i] + "[" + j + "] = 0 ");
			eval("d_" + objid + StyleProps[i] + "[" + j + "] = 0 ");
			*/
			eval("start_" + objid + StyleProps[i][j] + " = 0 ");
			eval("ziel_"  + objid + StyleProps[i][j] + " = 0 ");
			eval("d_"     + objid + StyleProps[i][j] + " = 0 ");
		}
	}
	window.clearInterval(eval("hilite" + objid));
	eval("hilite" + objid + " = false");
	window.clearInterval(eval("lolite" + objid));
	eval("lolite" + objid + " = false");
	eval("laufvar" + objid + "= 0");
}

function trace(text) {
	//Dient der Ausgabe von Werten zwischendurch
	document.all.tracer.innerHTML += text+"<br>";
}

function init() {
	// Feststellen wieviel Menu-Elemente (menu1, menu2 ...) existieren
	// und Intervall-Objekte sowie Zähler instanzieren (??)
	// Max. Anzahl Menuitems: 7
	for (i=1;i<1000;i++) {
		if (document.getElementById("menu"+i)) {
			// Style-Sheet-Eigenschaften zuweisen,
			// damit wir diese Dinge später manipuilieren können!
			// Farb-Werte müssen den Klassen div.menuliteLinkBox und div.menuLinkBox in der CSS-Datei entsprechen!
			getSty("menu"+i).backgroundColor = ( document.getElementById("menu"+i).attributes["class"].value.match(/menuLinkLite/) ) ? "#58AED9" : ( ( document.getElementById("menu"+i).attributes["class"].value.match(/menuLinkAct/) ) ? "#cc3300" : "#ACB1B6" ); 
			getSty("menu"+i).color = "#FFFFFF";
			eval("hilitemenu" + i + " = false"); //preparing interval object for fade in
			eval("lolitemenu" + i + " = false"); //preparing interval object for fade out
			eval("laufvarmenu" + i + " = 0");

			//Arrays mit Grundfarbwerten für StyleEigenschaften zusammenbasteln
			for (j=0;j<StyleProps.length;j++) {
				eval("basis_menu" + i + StyleProps[j] + " = new Array(0,0,0)");
				if (eval("getSty('menu" + i + "')." + StyleProps[j]).substr(0,3) == "rgb") {
					// For browsers storing color info like "rgb(rrr,ggg,bbb)";
					// Style-Eigenschaften (Farben) abrufen
					tmp_str = eval("getSty('menu" + i + "')." + StyleProps[j]);
					// Rückgabewert beschneiden
					tmp_str = tmp_str.substring(4,tmp_str.length-1);
					// in Array aufsplitten
					tmp_val = tmp_str.split(", ");
					for(k=0;k<3;k++) { //RGB (=0,1,2) abklappern
						eval("basis_menu" + i + StyleProps[j] + "[" + k + "] = " + tmp_val[k]);
					}
				}
				else	{
					for(k=0;k<3;k++) { //RGB (=0,1,2) abklappern
					//IE und so
						tmp_val = eval("Hex2Dec(getSty('menu" + i + "')." + StyleProps[j] + ".substr(" + (2*k + 1) + ",2))");
						eval("basis_menu" + i + StyleProps[j] + "[" + k + "] = " + tmp_val);
					}
				}
			}
		}
	}
	init_complete = true;
}

// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

function q_innerText(Which,Text) {
	//Erneuert den Inhalt eines Divs nach Abhängigkeit des Browsers
	//IE -> document.all
	//NS -> DOM
	//Which: Name des Layers als String
	if (getRef(Which).innerHTML) {
		getRef(Which).innerHTML = Text
	}
	else {
		getRef(Which).removeChild(document.getElementById(Which).firstChild);
		getRef(Which).appendChild(document.createTextNode(Text));
	}
	/*
	if (document.all) getRef(Which).innerHTML = Text;
	else {
		getRef(Which).removeChild(document.getElementById(Which).firstChild);
		getRef(Which).appendChild(document.createTextNode(Text));
	}
	*/
}

function showPicDiv(datei) {
	//alert(getRef('marker').offsetParent.offsetLeft);
	with(getSty('picDiv')) {
		top = getRef('marker').offsetTop + 200;
		left = getRef('marker').offsetLeft;
		document.images['pic'].src = "img/" + datei;
		visibility = "visible";
	}
}

function hidePicDiv() {
	getSty('picDiv').visibility="hidden";
	document.images['pic'].src = "img/spacer.gif";
}

// ToolTips sind deprecated!
// Wird jetzt über HTMl und StyleSheets abgefeiert!!
function showToolTip(modus) {
	if (toolTipMsg[modus]) {
		q_innerText("toolTip",toolTipMsg[modus]);
	}
	else {
		q_innerText("toolTip",modus);
	}
	getSty("toolTip").left = xMousePos + 10;
	getSty("toolTip").top  = yMousePos + 10;
	getSty("toolTip").visibility = "visible";
}

function showGlossar(modus) {
	hideToolTip();
	if (glossar[modus]) {
		q_innerText("glossarDiv",glossar[modus]);
	}
	else {
		q_innerText("glossarDiv",modus);
	}
	getSty("glossarDiv").left = xMousePos + 10;
	getSty("glossarDiv").top  = yMousePos + 10;
	getSty("glossarDiv").visibility = "visible";
}

function hideToolTip(modus) {
	getSty("toolTip").visibility = "hidden";
}

toolTipMsg = new Array();
toolTipMsg['Glossar'] = "Zeigt Ihnen den entsprechenden Glossar-Eintrag an!";

glossar = new Array();
glossar['Lorem'] = "<b>Lorem</b> ist der Anfang des wichtigsten Blindtextes aller Zeiten. Bereits seit Jahrhunderten wird dieser Text von Typographen und Setzern verwendet, um noch nicht geschriebenen Mengentext darzustellen."
glossar['Quadracom'] = "Quadracom sind drei abgespacte Freaks, die nichts lieber wollen als Ihr sauer verdientes Geld - und das mit möglichst wenig Arbeit oder Leistung. Also: <b>Raus mit dem Scheckbuch!</b>"

// End of Deprecated

function autoleuchter() {
	timeouts = new Array();
	for (i=1;i<7;i++) {
		commandhi = "highlightTrigger(getRef('menu" + i + "'))";
		commandlo = "lowlightTrigger(getRef('menu" + i + "'))";
		timeouts[i] = window.setTimeout(commandhi,100*i);
		timeouts[2*i] = window.setTimeout(commandlo,100*i+300);
	}
}

function openFenster(URL, Fenstername, Hoehe, Breite, Statusbar, Locationbar, Resizable, MenuBar) {
	//-------------
	//Fenster öffnen
	//-------------
	if (isDOM) Fenster = window.open(URL, Fenstername ,"height="+Hoehe+",width="+Breite+",dependent=no,status="+Statusbar+",locationbar="+Locationbar+",resizable="+Resizable+",menubar="+MenuBar+",scrollbars=yes");
	else alert("Ihr Internet-Browser entspricht nicht den Standards des W3C!");
	Fenster.focus();
}

