	window.onload = function() { foo = window.setTimeout( next, 3000 ); }
	
	var lastBody = 0, marginHeight = 0;
	function setMargin()
	{
		bodyHeight = $(window).height();
		if( lastBody < ( bodyHeight - 5 ) || lastBody > ( bodyHeight + 5 ) )
		{
			marginHeight = bodyHeight / 100 * 37.6667 - 220;
			marginHeight = marginHeight.toFixed(0);
			if( marginHeight < -23 )
				marginHeight = -23;
			document.getElementById( 'main' ).style.marginTop = marginHeight + 'px';
			lastBody = bodyHeight;	
		}
	}
	
	
	function FlyIn()
	{
		$( '#slide' ).animate( {'right': '377px'}, 6500 );
	}


	var counter=0;
	var foo;	
	function fade(step) {
		var imgs = document.getElementById("wechsel").getElementsByTagName("img");
		
		step = step || 0;
		
		imgs[counter].style.opacity = step / 100;
		imgs[counter].style.filter = "alpha(opacity=" + step + ")";
		
		step = step + 5;
		
		if (step <= 100) {
			foo=window.setTimeout(function () { fade(step); }, 1);
		} else {
			foo=window.setTimeout(next, 3000);
			fadeOut(imgs);
		}
	}
	
	function last() {
		var imgs = document.getElementById("wechsel").getElementsByTagName("img");
		element = imgs[imgs.length - 1];
		
		for(i = 0; i <= 100; i++)
			window.setTimeout('element.style.filter = "Alpha(opacity=' + (100 - i) + ')"; element.style.MozOpacity = ' + (1 - i / 100) + '; element.style.opacity = ' + (1 - i / 100) + ';', i);
	}
	
	function fadeOut(imgs) {
		if(imgs.length > 1) {
			if(counter > 0) {
				imgs[counter - 1].style.opacity = 0;
				imgs[counter - 1].style.filter = "alpha(opacity=0)";
			} 
			else {
				imgs[imgs.length - 1].style.opacity = 0;
				imgs[imgs.length - 1].style.filter = "alpha(opacity=0)";
			}
		}
	}
	
	function next() {
		var imgs = document.getElementById("wechsel").getElementsByTagName("img");
		if(imgs.length > 1) {
			if (typeof(counter) != "number") {
				counter = 0;
			}	
			
			if(counter == imgs.length - 1)
				counter = 0;
			else
				counter += 1;
			
			if(counter == 0)
				last();
				
			fade();
		}
	};
	
	function hideScrollbarShowButton( siteCount )
	{
		// Scrollbar ausblenden
		document.getElementById( 'content-right' ).style.overflowY = 'hidden';
		// Buttons einblenden
		if( siteCount > 1 )
			document.getElementById( 'scroller' ).style.display = 'block';
		// alle Seitenteile ausblenden, außer Seitenteil 1
		for( var i = 2; i <= siteCount; i++ )
			document.getElementById( 'switcher-' + i ).style.display = 'none';
	}
	
	function switchSite( siteCount, scrollMode )
	{
		var aktuellAktiv;
		for( var i = 1; i <= siteCount; i++ )
		{
			// aktuelles Seitenteil ermitteln
			if( document.getElementById( 'switcher-' + i ).style.display == 'block' )
				aktuellAktiv = i;
		}
		if( scrollMode == 'next' && aktuellAktiv < siteCount )
		{
			// aktuelles Seitenteil ausblenden
			document.getElementById( 'switcher-' + aktuellAktiv ).style.display = 'none';
			aktuellAktiv++;
			// nachfolgendes Seitenteil einblenden
			document.getElementById( 'switcher-' + aktuellAktiv ).style.display = 'block';
		}
		if( scrollMode == 'last' && aktuellAktiv > 1 )
		{
			// aktuelles Seitenteil ausblenden
			document.getElementById( 'switcher-' + aktuellAktiv ).style.display = 'none';
			aktuellAktiv--;
			// voriges Seitenteil einblenden
			document.getElementById( 'switcher-' + aktuellAktiv ).style.display = 'block';
		}
		// Seitenanzahl aktualisieren
		document.getElementById( 'sitecounter' ).innerHTML = aktuellAktiv + ' / ' + siteCount;
	}
