var isThisIE = (navigator.appVersion.indexOf("MSIE") > -1 ) ? true : false;
var timeOut = null;
var menu = new Array();
var showLayers = false;
var aktMenu = -1;

menu[0] = new Menu('vorstellung', 114, 'firma', 'mitarbeiter', 'veranstaltungen', 'presse', 'gaestebuch', 'alc');
menu[1] = new Menu('qualitaet', 61, 'vorfuehrung', 'zertifikate', '', '', '', '');
menu[2] = new Menu('leistungen', 77, 'produkte', 'schneeanlagen', 'referenzen', 'sonderkonstruktionen', 'altundneu', '');
menu[3] = new Menu('kontakt', 60, 'adresse', 'anfrage', '', '', '', '');

// for jsp Support
menu[2].norm[0].name += '.jsp';
menu[2].norm[4].name += '.jsp';
menu[3].norm[1].name += '.jsp';
menu[0].norm[4].name += '.jsp';


function Menu(name, imgHeight, punkt0, punkt1, punkt2, punkt3, punkt4, punkt5)
{
	this.name = name;
	this.imgHeight = imgHeight;
	this.norm = new Array();
	this.high = new Array();

	this.norm[0] = new Bild(punkt0, 'n');
	this.norm[1] = new Bild(punkt1, 'n');

	this.high[0] = new Bild(punkt0, 'h');
	this.high[1] = new Bild(punkt1, 'h');

	if (punkt2 != '') {
		this.norm[2] = new Bild(punkt2, 'n');
		this.high[2] = new Bild(punkt2, 'h');
	}
	if (punkt3 != '') {
		this.norm[3] = new Bild(punkt3, 'n');
		this.high[3] = new Bild(punkt3, 'h');
	}
	if (punkt4 != '') {
		this.norm[4] = new Bild(punkt4, 'n');
		this.high[4] = new Bild(punkt4, 'h');
	}
	
	if (punkt5 != '') {
		this.norm[5] = new Bild(punkt5, 'n');
		this.high[5] = new Bild(punkt5, 'h');
		if (punkt5 == 'alc')
		{
			this.norm[5].width = 180;
		}
	}
}

function Bild(name, typ) {
	this.bild = new Image();
	this.name = name;
	this.width = 140;
	this.height = 14;
	this.src = 'images/menu/layers/buttons/' + name + '_' + typ + '.gif';
}

// to open a new picture window
var picFileWindow = null;

function openSecondWindow(width, height, imgSource) {
	if (picFileWindow != null) {
		closeSecondWindow();
	}
	var windowWidth = width;
	var windowHeight = height;
	var scrolling = "no";

	if (windowHeight > 600)	{
		windowHeight = 600;
		windowWidth += 20;
		scrolling = "yes";
	}
	picFileWindow = window.open("picFile.html?src=" + imgSource + "&width=" + width + "&height=" + height, "picFile", "width=" + windowWidth + ",height=" + windowHeight +  ",hotkeys=no,dependent=yes,left=50,location=no,menubar=no,resizeable=no,scrollbars=" + scrolling + ",status=no,toolbar=no,top=50");
	picFileWindow.focus(); 
}

function closeSecondWindow() {
	if (picFileWindow != null) {
		picFileWindow.close();
	}
}
// picture window end

function swap(i, j, typ) {
	if (typ == "n") {
		if (isThisIE) {
			eval("document.images['" + menu[i].norm[j].name + "'].src = menu[" + i + "].norm[" + j + "].src;");
		} else {
			eval("document.layers['menu" + i + "'].document.images[" + j + "].src = menu[" + i + "].norm[" + j + "].src;");
		}
	} else {
		if (isThisIE) {
			eval("document.images['" + menu[i].norm[j].name + "'].src = menu[" + i + "].high[" + j + "].src;");
		} else {
			eval("document.layers['menu" + i + "'].document.images[" + j + "].src = menu[" + i + "].high[" + j + "].src;");
		}
	} 
}


function checkBrowser(){
	this.ver = navigator.appVersion
	this.dom = document.getElementById?1:0
	this.ie5 = ((this.ver.indexOf("MSIE 5") > -1) && (this.dom)) ? 1 : 0;
	this.ie4 = ((document.all) && (!this.dom)) ? 1 : 0;
	this.ns5 = ((this.dom) && (parseInt(this.ver) >= 5)) ? 1 : 0;
	this.ns4 = ((document.layers) && (!this.dom)) ? 1 : 0;
	this.bw  = (this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this;
}

var bw = new checkBrowser()
var lastshown = null;

function getObject(obj) {
	return (bw.dom) ? document.getElementById(obj).style : (bw.ie4) ? document.all[obj].style : (bw.ns4) ? document.layers[obj] : 0;
}

function sm_show(obj){
	if (timeOut != null) {
		window.clearInterval(timeOut);
		timeOut = null;
	}

	if ((lastshown) && (obj != lastshown)) { if (!showLayers) sm_hide(lastshown); }
	getObject(obj).visibility = 'visible';;
	lastshown = obj;

}


function sm_hide(obj){
	if (!showLayers) {
		if (obj == '') { obj = lastshown }
		if (obj) {
			getObject(obj).visibility='hidden';;
		}
	}
}


function getBrowserWidth() {
	return (isThisIE) ? document.body.clientWidth : window.innerWidth;
}

function doResize() {
	placeObjects();
}

function calcX() {
	var maxX = getBrowserWidth();
	if (maxX % 2 == 1) {
		maxX++;
	}
	var x = (maxX / 2) - ((isThisIE) ? 147 : 155) ;
	if (x < 165) {
		x = (isThisIE) ? 165 : 163;
	}
	return x;
}

function placeObjects() {
	for (var i in menu) {
		if (isThisIE) {
			eval("document.all['menu" + i + "'].style.left = calcX() + 'px';");
		} else {
			eval("document.layers['menu" + i + "'].left = Number(calcX());");
		}
	}
}

function hideLayer(index) {
	timeOut = window.setInterval("sm_hide('menu" + index + "')", ((isThisIE) ? 100 : 2000));
}

function buildMenu(aktMenu) {
	document.writeln('<TABLE border=0 cellspacing=0 cellpadding=0>');
	for (var i in menu) {
		if (i == aktMenu) {
			path = menu[i].name;
		} else {
			path = "images";
		}
		document.writeln('<TR><TD><A href="#" onMouseOver="sm_show(\'menu' + i + '\'); window.status=\'\'; return true;" onMouseOut="hideLayer(' + i + ');"><IMG src="' + path + '/menu/buttons/' + menu[i].name + '.gif" width=29 height=' + menu[i].imgHeight + ' alt="" border=0></A></TD></TR>');
	}
	document.writeln('<TR><TD><IMG src="images/menu/buttons/ende.gif" width=29 height=98 alt=""></TD></TR>');
	document.writeln('</TABLE>');
}

function showAllLayers() {
	for (var i in menu) {
		sm_show('menu' + i);
		lastshown = null;
	}
	showLayers = true;
}

function getFirstY() {
	var y = 54;
	if (!isThisIE) {
		y -= 7;
	}
	return y;
}

// code is called everytime

var startY = getFirstY();
var ext;

document.writeln('<STYLE>');
for (var i in menu) {

	document.writeln('#menu' + i + ' { position:absolute; left:' + (getBrowserWidth() / 2 - 156) + 'px; top:' + (startY) + 'px; visibility:hidden; }');
	startY += menu[i].imgHeight;
}
document.writeln('</STYLE>');

for (var i in menu) {
	document.writeln('<SPAN ID="menu' + i + '" onMouseOver="sm_show(\'menu' + i + '\');" onMouseOut="hideLayer(' + i + ');">');
	document.writeln('<TABLE border=0 cellspacing=0 cellpadding=0 width=422><TR>');
	document.writeln('	<TD valign=center align=left width="422" height="' + (menu[i].imgHeight + 1) + '" background="images/menu/layers/' + menu[i].name + '.gif">');
	document.writeln('		<TABLE border=0 cellspacing=0 cellpadding=0 width=392 background=""><TR>');
	document.writeln('			<TD valign=center align=right width="400">');

	for (var j in menu[i].norm) {
			ext = (menu[i].norm[j].name.indexOf('.') == -1) ? '.html' : '';
			document.writeln('				<A href="' + menu[i].norm[j].name + ext + '" onMouseOver="swap(' + i + ', ' + j + ', \'h\'); window.status=\'\'; return true;" onMouseOut="swap(' + i + ', ' + j + ', \'n\');"><IMG SRC="' + menu[i].norm[j].src + '" name="' + menu[i].norm[j].name + '" width="' + menu[i].norm[j].width + '" height="' + menu[i].norm[j].height + '" border=0 alt=""></A><BR>');
	}
	document.writeln('			</TD>');
	document.writeln('		</TR></TABLE>');
	document.writeln('</TD></TR></TABLE>');
	document.writeln('</SPAN>');
}

document.writeln('<MAP name="kci"><AREA shape="rect" coords="45, 2, 114, 11" href="http://www.kci-group.com" target=kcifenster></MAP>');
placeObjects();
