var aStat = new Array();
var bStat = 0;
var bNr = 0;
var http = null;
var htOnline = null;
var htBericht = null;
var z = 1;
var vz, vx = 0;
var text1;

var ahover = new Image(); ahover.src = 'grafiken/_ahover.gif';
var bhover = new Image(); bhover.src = 'grafiken/_bhover.gif';
var ehover = new Image(); ehover.src = 'grafiken/_ehover.gif';
var mhover = new Image(); mhover.src = 'grafiken/_mhover.gif';
var dhover = new Image(); dhover.src = 'grafiken/_dhover.gif';
var fhover = new Image(); fhover.src = 'grafiken/_fhover.png';
var pr_hover = new Image(); pr_hover.src = 'grafiken/pr_hover.gif';
var klapp_auf = new Image(); klapp_auf.src = 'grafiken/klapp_auf_h.gif';
var klapp_zu = new Image(); klapp_zu.src = 'grafiken/klapp_zu_h.gif';

function start( buts ) {
	aStat = buts.split('|');
	document.getElementById('wetter').style.display = 'block';
	mkHyph();
	chkOnline();
	setInterval( 'chkOnline()', 15000 );
}

function prStart() {
	mkHyph()
	setTimeout( 'self.print()', 1000 );
	setTimeout( 'self.close()', 1000 );
}

function mkHyph() {
	var ua = navigator.userAgent.toLowerCase();
	if( document.createElement && ua.indexOf('firefox/2') == -1 && ua.indexOf('firefox/1') == -1 && ua.indexOf('firefox/0') == -1 ) {
		var head = document.getElementsByTagName('head').item(0);
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = 'hyph.js';
		head.appendChild(script);

		ld = setInterval( function() {
			try {
				throw ldstat;
			} catch(e) {
				if( e == 'ok' ) {
					Hyphenator.hyphenateDocument( 4, '­' );
					clearInterval(ld);
				}
			}
		}, 100 );
	}
}

function mkRequest( but ) {
	if( window.XMLHttpRequest ) http = new XMLHttpRequest();
	else if( window.ActiveXObject ) http = new ActiveXObject( "Microsoft.XMLHTTP" );

	if( http != null ) {
		http.open( 'POST', 'menustat.php', true );
		http.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
		http.send( 'but=' + but + '&stat=' + aStat[but] );
		document.getElementById( 'sub' + but ).style.display = aStat[but] > 0 ? 'none' : 'block';
		document.getElementById( 'klappzu' + but ).style.display = aStat[but] > 0 ? 'none' : 'inline';
		document.getElementById( 'klappauf' + but ).style.display = aStat[but] > 0 ? 'inline' : 'none';
		aStat[but] = aStat[but] > 0 ? 0 : 1;
		return false;
	} else return true;
}

function zaehler( sw ) {
	document.getElementById( 'zaehler' ).style.display = sw > 0 ? 'none' : 'block';
	document.getElementById( 'besucher' ).style.display = sw > 0 ? 'block' : 'none';
}

function chkOnline() {
	if( window.XMLHttpRequest ) htOnline = new XMLHttpRequest();
	else if( window.ActiveXObject ) htOnline = new ActiveXObject( 'Microsoft.XMLHTTP' );
	if( htOnline != null ) {
		htOnline.open( 'GET', 'live.php', true );
		htOnline.onreadystatechange = function() {
			if ( htOnline.readyState == 4 ) document.getElementById('live').innerHTML = htOnline.responseText;
		}
		htOnline.send( null );
	}
}

function mkBericht( wid ) {
	if( wid == bNr || bStat == 1 ) {
		swBericht();
		return false;
	} else {
		if( window.XMLHttpRequest ) htBericht = new XMLHttpRequest();
		else if( window.ActiveXObject ) htBericht = new ActiveXObject( "Microsoft.XMLHTTP" );

		if( htBericht != null ) {
			htBericht.open( 'POST', 'galerien/bericht.php', true );
			htBericht.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
			htBericht.onreadystatechange = function() {
				if ( htBericht.readyState == 4 ) {
					document.getElementById('gal_bericht').innerHTML = htBericht.responseText;
					mkHyph();
					swBericht();
					bNr = wid;
				}
			}
			htBericht.send( 'wid=' + wid );
			return false;
		}
	}
	return true;
}

function swBericht() {
	if( bStat == 1 ) {
		document.getElementById('gal_bericht').style.display = 'none';
		document.getElementById('gal_link').firstChild.className = 'ein';
		document.getElementById('gal_link').firstChild.innerHTML = 'Bericht lesen';
		document.getElementById('gal_link').firstChild.blur();
		bStat = 0;
	} else {
		document.getElementById('gal_bericht').style.display = 'block';
		document.getElementById('gal_link').firstChild.className = 'aus';
		document.getElementById('gal_link').firstChild.innerHTML = 'Bericht ausblenden';
		document.getElementById('gal_link').firstChild.blur();
		bStat = 1;
	}
}

function bild( d, i, b, h ) {
	var vl = screen.availWidth > b ? parseInt(( screen.availWidth - b ) / 2 ) : 0;
	var vo = screen.availHeight > h ? parseInt(( screen.availHeight - h ) / 4 ) : 0;
	if( open( 'bild.php?dir=' + d + '&pic=' + i, 'Bild_' + d + i, 'width=' + b + ',height=' + h + ',left=' + vl + ',top=' + vo + ',resizable' )) return false;
	return true;
}

function pic( i, t, b, h ) {
	if( b > screen.availWidth - 40 ) {
		b = screen.availWidth - 40;
		h += 22;
	}
	if( h > screen.availHeight - 90 ) {
		h = screen.availHeight - 90;
		b += 22;
	}
	var vl = screen.availWidth > b + 16 ? parseInt(( screen.availWidth - ( b + 16 )) / 2 ) : 0;
	var vo = screen.availHeight > h ? parseInt(( screen.availHeight - h ) / 4 ) : 0;
	if( open( 'bilder/viewer.php?i=' + i + '&t=' + t, 'Bild_' + i, 'width=' + b + ',height=' + h + ',left=' + vl + ',top=' + vo + ',resizable,scrollbars' )) return false;
	return true;
}

function grbild( d, i, t, b, h ) {
	var vl = screen.availWidth > b ? parseInt(( screen.availWidth - b ) / 2 ) : 0;
	var vo = screen.availHeight > h ? parseInt(( screen.availHeight - h ) / 4 ) : 0;
	if( open( 'grbild.php?verz=' + d + '&bild=' + i + '&titel=' + t, 'Bild_' + i, 'width=' + b + ',height=' + h + ',left=' + vl + ',top=' + vo + ',resizable' )) return false;
	return true;
}

function popup( u, w, b, h, s ) {
	var vl = screen.availWidth > b ? parseInt(( screen.availWidth - b ) / 2 ) : 0;
	var vo = screen.availHeight > h ? parseInt(( screen.availHeight - h ) / 4 ) : 0;
	var p = 'width=' + b + ',height=' + h + ',left=' + vl + ',top=' + vo + ',resizable';
	if( s ) p += ',scrollbars';
	if( open( u, w, p )) return false;
	return true;
}

function diashow(d) {
  var vl = screen.availWidth > 790 ? parseInt(( screen.availWidth - 790 ) / 2 ) : 0;
  var vo = screen.availHeight > 650 ? parseInt(( screen.availheight - 650 ) / 4 ) : 0;
  if( open( 'diashow.php?ds=' + d, 'diashow' + d, 'width=790,height=650,left=' + vl + ',top=' + vo + ',resizable' )) return false;
  return true;
}

function blaettern( name, x, max ) {
	z += x;
	if( z > max ) z = 1;
	if( z < 1 ) z = max;
	document.pics.src = name + z + '.jpg';
}

function vh_init() {
	vz = 0;
	if( ++vx > 5 ) vx = 1;
	var ein = vx < 5 ? vx + 1 : vx - 4;
	var aus = vx > 1 ? vx - 1 : vx + 4;

	document.getElementById( 'vh_c' + ein ).style.display = 'block';
	document.getElementById( 'vh_c' + aus ).style.display = 'none';
	vh_fade();
}

function vh_fade() {
	var vy = vx < 5 ? vx + 1 : vx - 4;
	var b_1 = document.getElementById( 'vh_tr_bild' + vx );
	var b_2 = document.getElementById( 'vh_tr_bild' + vy );

	b_1.style.MozOpacity = ( 100 - vz ) / 100;
	b_1.style.opacity = ( 100 - vz ) / 100;
	b_1.style.filter = 'alpha(opacity:' + ( 100 - vz ) + ')';

	b_2.style.MozOpacity = vz / 100;
	b_2.style.opacity = vz / 100;
	b_2.style.filter = 'alpha(opacity:' + vz + ')';

	if( vz++ < 100 ) setTimeout( 'vh_fade()', 20 );
	else setTimeout( 'vh_init()', 5000 );
}

function drucken(inc) {
	if( inc != 3 && inc != 12 ) {
		text1 = document.getElementById('rechts').innerHTML;
		var text2 = text1.replace( /»/g, '&bdquo;' );
		text2 = text2.replace( /«/g, '&ldquo;' );
		document.getElementById('rechts').innerHTML = text2;
	}
	self.print();
	if( inc != 3 && inc != 12 ) setTimeout( 'gedruckt()', 3000 );
}

function gedruckt() {
	document.getElementById('rechts').innerHTML = text1;
}
