
var men = new Object();
men.obj = new Array();
men.zust = new Array();
men.stufe = new Array();
men.pos = new Array();
men.timeout = false;

var farbe = new Object();
farbe.weiss = new Array(255, 255, 255);
farbe.ges = new Array(125, 125, 255);
farbe.hrc = new Array(240, 70, 70);
farbe.bgc = new Array(255, 170, 0);
farbe.email = new Array(0, 190, 140);
farbe.extern = new Array(200, 0, 255);

var li = new Object();
var start = new Array();
var prop_alpha = '';
var prop_text = '';
var hex = '0123456789ABCDEF';

function nix() {}

function dec2hex(num) {
	return hex.charAt(Math.floor(num/16)) + hex.charAt(num%16);
}

function hex2dec(num) {
	return hex.indexOf(num.substr(0, 1).toUpperCase())*16 + hex.indexOf(num.substr(1, 1).toUpperCase());
}

function scroll_pos() {
	var pos = 0;
	if (window.scrollY)
		pos = window.scrollY;
	else if (document.documentElement)
		pos = document.documentElement.scrollTop;
	return pos;
}

function liesfarbe(fa) {
	if (fa.search(/^#([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/ig) == 0) {
		if (!farbe[fa])
			farbe[fa] = new Array(hex2dec(RegExp.$1), hex2dec(RegExp.$2), hex2dec(RegExp.$3));
	}
	else if (fa.search(/^rgb\(([0-9]+), ?([0-9]+), ?([0-9]+)\)$/ig) == 0) {
		fa = '#' + dec2hex(RegExp.$1), dec2hex(RegExp.$2), dec2hex(RegExp.$3);
		if (!farbe[fa])
			farbe[fa] = new Array(RegExp.$1, RegExp.$2, RegExp.$3);
	}
	else
		fa = false;
	return fa;
}

function machfarbe(fa1, fa2, ant2) {
	var fa = '#';
	for (var k = 0; k < 3; k++)
		fa += dec2hex(Math.round((farbe[fa1][k] * (1 - ant2)) + (farbe[fa2][k] * ant2)));
	return fa;
}

function ereignis_reg(obj, fkt) {
	for (var i = 2; i < arguments.length; i++) {
		if (obj.addEventListener)
			obj.addEventListener(arguments[i], fkt, false);
		else if (obj.attachEvent)
			obj.attachEvent('on' + arguments[i], fkt);
		else if (!obj['on' + arguments[i]])
			obj['on' + arguments[i]] = fkt;
	}
}

function ereignis_dereg(obj, fkt) {
	for (var i = 2; i < arguments.length; i++) {
		if (obj.addEventListener)
			obj.removeEventListener(arguments[i], fkt, false);
		else if (obj.detachEvent)
			obj.detachEvent('on' + arguments[i], fkt);
		else if (obj['on' + arguments[i]] == fkt)
			obj['on' + arguments[i]] = '';
	}
}

function ereignis_stop(er) {
	er.returnValue = false;
	if (er.preventDefault)
		er.preventDefault();
	return false;
}

function anim(anw, fkt) {
	for (var i = 0; i < anw.length; i++) {
		if (anw[i][0].anim_int)
			clearInterval(anw[i][0].anim_int);
	}
	anw[0][0].anim_zeit = 0;
	anw[0][0].anim_int = setInterval(function() { anim_schritt(anw, fkt) }, 20);
}

function anim_schritt(anw, fkt) {
	var i1, i2, akt, zeit = (new Date()).getTime();
	if (zeit - anw[0][0].anim_zeit >= 50) {
		anw[0][0].anim_zeit = zeit;
		var ok = true;
		for (i1 = 0; i1 < anw.length; i1++) {
			for (i2 = 1; i2 < anw[i1].length; i2 += 3) {
				akt = parseInt(anw[i1][0].style[anw[i1][i2]]);
				if (akt != anw[i1][i2+1]) {
					anw[i1][0].style[anw[i1][i2]] = (akt + ((akt > anw[i1][i2+1] ? -1 : 1) * Math.ceil(Math.abs(akt - anw[i1][i2+1]) / 3))) + anw[i1][i2+2];
					ok = false;
				}
			}
		}
		if (ok) {
			clearInterval(anw[0][0].anim_int);
			if (fkt)
				fkt.call();
		}
	}
}

function obj_blend(obj, aend, deck, fkt) {
	obj.stufe = Math.max(0, Math.min(100, obj.stufe + aend));
	var opac = Math.round(((obj.aus * (100 - obj.stufe)) + (obj.ein * obj.stufe)) * deck / 10000);
	if (opac == 0)
		obj.style.visibility = 'hidden';
	else {
		if (prop_alpha == 'filters')
			obj.filters.alpha.opacity = opac;
		else if (prop_alpha)
			obj.style[prop_alpha] = opac / 100;
		if (obj.style.visibility == 'hidden')
			obj.style.visibility = 'visible';
	}
	if (obj.stufe > 0 && obj.stufe < 100)
		obj.timeout = setTimeout(function() { obj_blend(obj, aend, deck, fkt) }, 60);
	else if (fkt)
		fkt.call();
}

function link_blend(obj, aend, deck) {
	obj.stufe = Math.max(0, Math.min(100, obj.stufe + aend));
	obj.style[obj.eig] = machfarbe(obj.aus, obj.ein, obj.stufe * deck / 10000);
	if (obj.stufe > 0 && obj.stufe < 100)
		obj.timeout = setTimeout(function() { link_blend(obj, aend, deck) }, 60);
}

function link_wechsel(adr, aend, deck) {
	var l, b, obj_l, obj_b;
	for (l = 0; l < li[adr].links.length; l++) {
		obj_l = li[adr].links[l];
		if (obj_l.eig) {
			if (obj_l.timeout)
				clearTimeout(obj_l.timeout);
			link_blend(obj_l, aend, deck);
		}
		for (b = 0; b < obj_l.bilder.length; b++) {
			obj_b = obj_l.bilder[b];
			if (obj_b.timeout)
				clearTimeout(obj_b.timeout);
			obj_blend(obj_b, aend, deck);
		}
	}
}

function link_such(obj) {
	if (obj.currentTarget)
		obj = obj.currentTarget;
	else {
		if (obj.srcElement)
			obj = obj.srcElement;
		while (((obj.tagName && obj.tagName != 'A' && obj.tagName != 'AREA') || obj.nodeValue) && obj != document.body && obj.parentNode)
			obj = obj.parentNode;
	}
	return obj;
}

function link_maus(er) {
	if (!er)
		er = window.event;
	var verw = link_such(er);
	var ok = true;
	if (er.type == 'click') {
		if (verw.href.indexOf('mailto:') == 0 && confirm('Möchtest du die E-Mail direkt über unsere Internetseite schreiben? Dann klicke bitte "OK". Hast du ein eigenes E-Mail-Programm installiert und möchtest dieses benutzen, dann klicke bitte "Abbrechen".')) {
			document.location.href = '../kontakt/email.php?emp=' + verw.href.substring(7);
			ok = false;
		}
		if (verw.stufe != 100)
			link_wechsel(verw.href, 100, 100);
		verw.blur();
	}
	for (var i = 0; i < li[verw.href].sym.length; i++) {
		if (li[li[verw.href].sym[i]].links.length)
			link_wechsel(li[verw.href].sym[i], (er.type == 'mouseover' ? 100 : -5), 100);
	}
	if (!ok)
		ereignis_stop(er);
	return ok;
}

function men_blend() {
	var m, s, weiter = false;
	for (m = 0; m <= menue.length; m++) {
		s = men.zust[m]*10 - men.stufe[m];
		if (s) {
			men.stufe[m] += (s > 0) ? 1 : -1;
			if (men.stufe[m]) {
				if (m != menue.length)
					men.obj[m].style.top = (90 - (men.stufe[m] > 7 ? 8+men.stufe[m] : 2*men.stufe[m])) + 'px';
				if (m != menue.length || men.stufe[m] != 10) {
					if (prop_alpha == 'filters')
						men.obj[m].filters.alpha.opacity = men.stufe[m] * 10;
					else if (prop_alpha)
						men.obj[m].style[prop_alpha] = men.stufe[m] * .1;
				}
			}
			else
				men.obj[m].style.visibility = 'hidden';
		}
		if (!weiter && Math.abs(s) > 1)
			weiter = true;
	}
	if (men.zust[menue.length]) {
		s = 110 - scroll_pos();
		if (s < 0) {
			window.scrollBy(0, Math.max(s, -10));
			if (!weiter)
				weiter = true;
		}
	}
	if (weiter)
		men.timeout = setTimeout(men_blend, 60);
}

function men_wechsel(k) {
	for (var m = menue.length; m >= 0; m--) {
		if (m == menue.length)
			men.zust[m] = men.zust[k] ? 0 : 1;
		else {
			if (m != k && men.zust[m])
				link_wechsel(document.getElementById('k' + m).href, -10, 100);
			men.zust[m] = (m != k || men.zust[m]) ? 0 : 1;
		}
		if (men.zust[m] && men.stufe[m] == 0) {
			if (prop_alpha == 'filters')
				men.obj[m].filters.alpha.opacity = 0;
			else if (prop_alpha)
				men.obj[m].style[prop_alpha] = 0;
			men.obj[m].style.visibility = 'visible';
		}
	}
	clearTimeout(men.timeout);
	men_blend();
}

function men_maus(er) {
	if (!er)
		er = window.event;
	var verw = link_such(er);
	var k = verw.id.substr(1);
	var ok = true;
	if (er.type == 'click') {
		verw.blur();
		ok = false;
	}
	if (er.type == 'click' || (er.type == 'mouseover' && !men.zust[k] && men.zust[menue.length]))
		men_wechsel(k);
	if (er.type != 'mouseout' || !men.zust[k])
		link_wechsel(verw.href, (er.type == 'mouseout' ? -5 : 100), (men.zust[menue.length] ? 100 : 60));
	if (!ok)
		ereignis_stop(er);
	return ok;
}

function bild_wechsel() {
	var b;
	if (bild.fertig == bild.anz || bild.akt + 1 < bild.fertig) {
		for (b = 1; b <= bild.anz; b++) {
			if ((bild.akt + b) % bild.anz < bild.obj.length)
				bild.obj[(bild.akt + b) % bild.anz].style.zIndex = b;
		}
		bild.akt = ++bild.akt % bild.anz;
		if (scroll_pos() < 370) {
			obj_blend(bild.obj[bild.akt], -100, 100);
			obj_blend(bild.obj[bild.akt], 5, 100);
		}
		bild.obj[bild.akt].style.zIndex = bild.anz + 1;
		setTimeout(bild_wechsel, 13000);
	}
	else
		setTimeout(bild_wechsel, 1000);
}

function bild_laden() {
	bild.fertig++;
	var uebr = bild.liste.length;
	if (uebr) {
		var name = bild.liste.splice(Math.floor(Math.random() * uebr), 1);
		var obj = bild.obj[0].cloneNode(false);
		ereignis_reg(obj, bild_laden, 'load');
		obj.src = obj.src.substring(0, obj.src.lastIndexOf('/')+1) + name[0] + '.jpg';
		obj.style.zIndex = bild.fertig - bild.akt + 1;
		obj.aus = 0;
		obj.ein = 100;
		obj.stufe = 100;
		obj.timeout = false;
		bild.obj.push(obj);
		document.getElementById('kopf').appendChild(obj);
	}
}

function warten() {
	var min, sek;
	var obj = document.getElementById('wartezeit');
	if (obj[prop_text].search(/^([0-9]+):0?([1-5]?[0-9]) Minuten$/g) != -1) {
		min = parseInt(RegExp.$1);
		sek = parseInt(RegExp.$2);
		min = min - !sek;
		sek = (sek + 59) % 60;
		obj[prop_text] = min + ':' + (sek < 10 ? '0' : '') + sek + ' Minuten';
		obj = document.getElementById('subm_warten');
		if (obj && min == 0 && sek == 0) {
			clearInterval(obj.wart_int);
			obj.value = 'Nächste Seite wird geladen...';
			obj.form.submit();
		}
	}
}

function link_prep(li_kol) {
	var obj_l, obj_b, obj_bk, i1, i2, kol;
	for (i1 = 0; i1 < li_kol.length; i1++) {
		obj_l = li_kol[i1];
		if (obj_l.href && typeof(obj_l.ein) == 'undefined') {
			if (obj_l.tagName == 'A') {
				if (prop_text && obj_l[prop_text] != '') {
					if (obj_l.currentStyle)
						obj_l.aus = liesfarbe(obj_l.currentStyle.color);
					else if (window.getComputedStyle)
						obj_l.aus = liesfarbe(document.defaultView.getComputedStyle(obj_l, null).getPropertyValue('color'));
					if (obj_l.aus)
						obj_l.eig = 'color';
				}
				else if (obj_l.currentStyle && parseInt(obj_l.currentStyle.borderTopWidth)) {
					obj_l.aus = liesfarbe(obj_l.currentStyle.borderColor);
					if (obj_l.aus)
						obj_l.eig = 'borderColor';
				}
				else if (window.getComputedStyle && parseInt(document.defaultView.getComputedStyle(obj_l, null).getPropertyValue('border-top-width'))) {
					obj_l.aus = liesfarbe(document.defaultView.getComputedStyle(obj_l, null).getPropertyValue('border-top-color'));
					if (obj_l.aus)
						obj_l.eig = 'borderColor';
				}
				if (obj_l.parentNode.className.search(/^(abt|fuss)/) != -1)
					obj_l.ein = 'weiss';
				else if (obj_l.href.indexOf('mailto:') == 0)
					obj_l.ein = 'email';
				else if (obj_l.rel == 'direkt' || obj_l.href.indexOf('javascript:') == 0)
					obj_l.ein = abt;
				else if (obj_l.href.indexOf('www.maschsee-sport.de/') != -1 || obj_l.href.indexOf('ssl.maschsee-sport.de/ges/') != -1)
					obj_l.ein = 'ges';
				else if (obj_l.href.indexOf('www.hrc1880.de/') != -1 || obj_l.href.indexOf('ssl.maschsee-sport.de/hrc/') != -1)
					obj_l.ein = 'hrc';
				else if (obj_l.href.indexOf('www.blau-gold-club.de/') != -1 || obj_l.href.indexOf('ssl.maschsee-sport.de/bgc/') != -1)
					obj_l.ein = 'bgc';
				else
					obj_l.ein = 'extern';
				obj_l.bilder = new Array();
				kol = obj_l.getElementsByTagName('IMG');
				for (i2 = 0; i2 < kol.length; i2++) {
					obj_b = kol[i2];
					if (obj_b.src.search(/(.+_)aus\.gif$/ig) != -1) {
						obj_b.style.width = obj_b.width + 'px';
						obj_b.style.height = obj_b.height + 'px';
//						obj_b.style.height = obj_b.style.height;
						obj_bk = document.createElement('SPAN');
						obj_bk.style.display = 'inline-block';
						obj_bk.style.position = 'relative';
						obj_b.parentNode.replaceChild(obj_bk, obj_b);
						obj_b.style.position = 'absolute';
						obj_bk.appendChild(obj_b);
						obj_b = obj_b.cloneNode(false);
						obj_b.style.position = 'relative';
						obj_b.src = RegExp.$1 + 'ein.gif';
						obj_b.style.visibility = 'hidden';
						if (prop_alpha == 'filters')
							obj_b.style.filter = 'Alpha(opacity=0)';
						obj_bk.appendChild(obj_b);
						obj_b.aus = 0;
						obj_b.ein = 100;
					}
					else if (obj_b.src.search(/\.(gif|jpe?g)#([0-9]{1,3}),([0-9]{1,3})$/ig) != -1) {
						obj_b.aus = Math.max(0, Math.min(100, RegExp.$2));
						obj_b.ein = Math.max(0, Math.min(100, RegExp.$3));
						if (prop_alpha == 'filters')
							obj_b.style.filter = 'Alpha(opacity=' + obj_b.aus + ')';
					}
					if (typeof(obj_b.ein) != 'undefined') {
						obj_b.stufe = 0;
						obj_b.timeout = false;
						obj_l.bilder.push(obj_b);
					}
				}
				if (obj_l.eig) {
					obj_l.stufe = 0;
					obj_l.timeout = false;
				}
			}
			if (obj_l.ein == 'extern' || obj_l.rel == 'extern')
				obj_l.target = '_blank';
			if (document.location.protocol != 'https:' && obj_l.href.indexOf('_frei.php') == -1 && obj_l.href.indexOf('https://') == 0)
				obj_l.title = (obj_l.title ? (obj_l.title + ', ') : '') + 'Benutzername und Passwort erforderlich';
		}
	}
}

function link_reg(kol_l, er_nicht) {
	var obj_l, i1, i2, i3, i4, kol, ok;
	for (i1 = 0; i1 < kol_l.length; i1++) {
		obj_l = kol_l[i1];
		if (obj_l.href) {
			if (obj_l.href.search(/^((https?:\/\/(local\.)?(www|ssl)\.(maschsee-sport|hrc1880|blau-gold-club)\.de\/)[^0-9]+)([0-9]+(~[0-9]+)+)([^0-9]+)$/ig) != -1) {
				kol = RegExp.$6.split('~');
				for (i2 = 0; i2 < kol.length; i2++)
					kol[i2] = RegExp.$1 + kol[i2] + RegExp.$8;
			}
			else
				kol = new Array();
			kol.unshift(obj_l.href);
			for (i2 = 0; i2 < kol.length; i2++) {
				if (!li[kol[i2]]) {
					li[kol[i2]] = new Object();
					li[kol[i2]].links = new Array();
					li[kol[i2]].sym = new Array();
				}
				for (i3 = 0; i3 < (i2 ? 1 : kol.length); i3++) {
					ok = true;
					for (i4 = 0; (ok && i4 < li[kol[i2]].sym.length); i4++)
						ok = (li[kol[i2]].sym[i4] != kol[i3]);
					if (ok)
						li[kol[i2]].sym.push(kol[i3]);
				}
			}
			if (obj_l.tagName == 'A' && (obj_l.eig || obj_l.bilder.length))
				li[obj_l.href].links.push(obj_l);
			if (!er_nicht && obj_l.parentNode)
				ereignis_reg(obj_l, obj_l.href.search(/\/menue\/[0-9]\.php$/ig) != -1 ? men_maus : link_maus, 'mouseover', 'mouseout', 'click');
		}
	}
}

function link_dereg(kol_l, er_nicht) {
	var obj_l, i1, i2, i3;
	for (i1 = 0; i1 < kol_l.length; i1++) {
		obj_l = kol_l[i1];
		if (obj_l.href) {
			for (i2 = 0; i2 < li[obj_l.href].sym.length; i2++) {
				for (i3 = li[li[obj_l.href].sym[i2]].links.length-1; i3 >= 0; i3--) {
					if (obj_l == li[li[obj_l.href].sym[i2]].links[i3])
						li[li[obj_l.href].sym[i2]].links.splice(i3, 1);
				}
			}
			if (!er_nicht && obj_l.parentNode)
				ereignis_reg(obj_l, obj_l.href.search(/\/menue\/[0-9]\.php$/ig) != -1 ? men_maus : link_maus, 'mouseover', 'mouseout', 'click');
		}
	}
}

function init() {
	var obj1, obj2, obj3, i1, i2, i3, kol, hoehe, breite, pos;
	var abt = 'ges';
	if (document.location.href.search(/^https:\/\/(local\.)?ssl\.maschsee-sport\.de\/(hrc|bgc)\//i) != -1)
		abt = RegExp.$2;
	else if (document.location.href.indexOf('www.hrc1880.de/') != -1)
		abt = 'hrc';
	else if (document.location.href.indexOf('www.blau-gold-club.de/') != -1)
		abt = 'bgc';
	if (typeof(document.body.style.opacity) != 'undefined')
		prop_alpha = 'opacity';
	else if (typeof(document.body.style.MozOpacity) != 'undefined')
		prop_alpha = 'MozOpacity';
	else if (typeof(document.body.style.KhtmlOpacity) != 'undefined')
		prop_alpha = 'KhtmlOpacity';
	else if (typeof(document.body.filters) != 'undefined')
		prop_alpha = 'filters';
	if (typeof(document.body.textContent) != 'undefined')
		prop_text = 'textContent';
	else if (typeof(document.body.innerText) != 'undefined')
		prop_text = 'innerText';
	var kopf = document.getElementById('kopf');
	if (kopf) {
		obj1 = document.createElement('DIV');
		obj1.className = 'men-hg';
		if (prop_alpha == 'filters')
			obj1.style.filter = 'Alpha(opacity=0)';
		kopf.appendChild(obj1);
		men.obj[menue.length] = obj1;
		men.zust[menue.length] = 0;
		men.stufe[menue.length] = 0;
		for (i1 = 0; i1 < menue.length; i1++) {
			obj1 = document.createElement('DIV');
			obj1.className = 'men-cont';
			obj1.style.zIndex = 104 + i1;
			if (prop_alpha == 'filters')
				obj1.style.filter = 'Alpha(opacity=0)';
			kopf.appendChild(obj1);
			breite = new Array();
			pos = new Array();
			pos[0] = 0;
			for (i2 = 0; i2 < menue[i1].length; i2++) {
				obj2 = document.createElement('DIV');
				obj2.className = 'men-gr';
				obj3 = document.createElement('SPAN');
				obj3.style.color = machfarbe(abt, 'weiss', 0);
				obj3.style.lineHeight = '30px';
				obj3.appendChild(document.createTextNode(menue[i1][i2][0]));
				obj2.appendChild(obj3);
				for (i3 = 1; i3 < menue[i1][i2].length; i3++) {
					obj2.appendChild(document.createElement('BR'));
					obj3 = document.createElement(menue[i1][i2][i3][1] == '' ? 'SPAN' : 'A');
					obj3.style.color = menue[i1][i2][i3][1] == '' ? '#666666' : '#D0C5BF';
					obj3.href = menue[i1][i2][i3][1];
					obj3.appendChild(document.createTextNode('» ' + menue[i1][i2][i3][0]));
					obj2.appendChild(obj3);
				}
				obj1.appendChild(obj2);
				breite[i2] = obj2.offsetWidth ? obj2.offsetWidth : 260;
				pos[0] += breite[i2] + (i2 == 0 ? 0 : 45);
			}
			pos[0] = Math.round((940 - pos) / 2);
			hoehe = 0
			kol = obj1.childNodes;
			for (i2 = 0; i2 < kol.length; i2++) {
				hoehe = Math.max((kol[i2].offsetHeight ? kol[i2].offsetHeight : (16 * menue[i1][i2].legth + 14)) / (190 + (41 * pos[i2] + 20.5 * breite[i2]) / 940), hoehe);
				pos[i2+1] = pos[i2] + breite[i2] + 45;
			}
			for (i2 = 0; i2 < kol.length; i2++) {
				kol[i2].style.left = pos[i2] + 'px';
				kol[i2].style.top = Math.round(146 - ((20.5 * pos[i2] + 10.25 * breite[i2]) / 940) - ((hoehe / 2) * (190 + (41 * pos[i2] + 20.5 * breite[i2]) / 940))) + 'px';
			}
			men.obj[i1] = obj1;
			men.zust[i1] = 0;
			men.stufe[i1] = 0;
		}
	}
	link_prep(document.links);
	link_reg(document.links);
	for (i1 = 0; i1 < start.length; i1++)
		start[i1].call();
	obj1 = document.getElementById('wartezeit');
	if (obj1 && prop_text) {
		obj1 = document.getElementById('subm_warten');
		if (obj1) {
			obj1.disabled = true;
			obj1.value = 'Weiterleitung erfolgt automatisch...';
		}
		obj1.wart_int = setInterval(warten, 1000);
	}
	obj1 = document.getElementById('subm_einmal');
	if (obj1)
		ereignis_reg(obj1.form, function() { obj1.disabled = true; }, 'submit');
	if (kopf && bild.liste.length) {
		bild.obj[0] = document.getElementById('kopf_bild');
		bild.obj[0].removeAttribute('id');
		bild.obj[0].style.zIndex = bild.anz + 1;
		bild.obj[0].aus = 0;
		bild.obj[0].ein = 100;
		bild.obj[0].stufe = 0;
		bild.obj[0].timeout = false;
		if (bild.obj[0].src.search(/\/kopf\/([a-z0-9_]+)\.jpg/ig) != -1) {
			for (i1 = 0; i1 < bild.liste.length; i1++) {
				if (bild.liste[i1] == RegExp.$1)
					bild.liste.splice(i1, 1);
			}
		}
		if (prop_alpha == 'filters')
			bild.obj[0].style.filter = 'Alpha(opacity=100)';
		bild_laden();
		setTimeout(bild_wechsel, 12000);
	}
}

if (document.getElementById)
	ereignis_reg(window, init, 'load');
