var browserWidth 		= 0;
var browserHeight 	= 0; 
var scrollbarHeight	= 0; 
var bodyWidth 			= 0; 
var bodyHeight 			= 0;
var currentFrame		= 0;
var waitingTime			= 0;
var fadeSteps				= 8;
var fadeSpeed				= 20;
var flashWidth  		= 660;
var flashHeight 		= 540;
var noFlash					= false;
var fadingIn				= false;
var fadingOut				= false;

function fileName (file)
	{
	return file.replace(/_/g,"-");	
	}

function size() 
	{	
	//BROWSERÜBERGREIFENDE DOKUMENTENHÖHE
  bodyHeight = Math.max(Math.max(document.body.scrollHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.documentElement.offsetHeight), Math.max(document.body.clientHeight, document.documentElement.clientHeight));

	//INTERNET EXPLORER
	if (self.innerHeight) 
		{ 
		//INTERNET EXPLORER
		browserWidth  	= window.innerWidth;
		browserHeight 	= window.innerHeight;
		scrollbarHeight = window.pageYOffset;
		} 
	else if (document.documentElement && document.documentElement.clientHeight) 
		{ 
		//INTERNET EXPLORER 6
		browserWidth  	= document.documentElement.clientWidth;
		browserHeight 	= document.documentElement.clientHeight;
		scrollbarHeight = document.documentElement.scrollTop;
		} 
	else if (document.body) 
		{ 
		//INTERNET EXPLORER 7
		browserWidth  	= document.body.clientWidth;
		browserHeight	  = document.body.clientHeight;
		scrollbarHeight = document.body.scrollTop;
		}

	//BODYABMESSUNGEN
	if (window.innerHeight && window.scrollMaxY) 
		{	
		bodyWidth  = document.body.scrollWidth;
		} 
	else if (document.body.scrollHeight > document.body.offsetHeight) 
		{ 
		//ALLE AUSSER MAC
		bodyWidth  = document.body.scrollWidth;
		}
	else 
		{
		//MAC
		bodyWidth  = document.body.offsetWidth;
		}
	}
	
function fadeIn (swfFile, swfTitle)
	{
	if (!document.getElementById("divPreloader"))
		{
		if (currentFrame == 0)
			{
			size();	
	
			htmlBody = document.getElementsByTagName("body").item(0);		
			divLayer = document.createElement("divLayer");
			
			divLayer.setAttribute("id","divLayer");		

			divLayer.style.width	 	 	= bodyWidth  + "px";
			divLayer.style.height	 	 	= bodyHeight + "px";
			divLayer.style.background	= "#222222";
			divLayer.style.filter	 	 	= "alpha(opacity=0)";
			divLayer.style.opacity 	 	= "0.0";
			divLayer.style.MozOpacity	= "0.0";
			divLayer.style.position 	= "absolute"; 
			divLayer.style.left	 	 		= "0px";
			divLayer.style.top				= "0px";	
			divLayer.style.width 			= bodyWidth  + "px";
			divLayer.style.height 		= bodyHeight + "px";
			divLayer.style.zIndex 	 	= "9997";
			divLayer.style.display 	 	= "block";
			divLayer.className		 	 	= "layer0";		
				
			htmlBody.insertBefore(divLayer, htmlBody.firstChild);
			}
		}
	else
		{
		document.getElementById("divLayer").style.display = "block";
		}
		
	if (!fadingOut)
		{
		fadingIn = true;
			
		currentFrame++;		
	
		if (currentFrame <= fadeSteps)
			{
			divLayer.style.filter	 	 	= "alpha(opacity=" + currentFrame + "0)";
			divLayer.style.opacity 	 	= "0." + currentFrame;
			divLayer.style.MozOpacity	= "0." + currentFrame;

			setTimeout("fadeIn(\"" + swfFile + "\",\"" + swfTitle + "\")",fadeSpeed);
			}
		else if (currentFrame > fadeSteps) 
			{
			fadingIn = false;			

			preloader(swfFile, swfTitle);
			
			divLayer.setAttribute("onclick","fadeOut(\"" + swfFile + "\");");
			}
		}
	}
	
function preloader (swfFile, swfTitle)
	{	
	if (!document.getElementById("divPreloader"))
		{
		size();		
		
		htmlBody		 = document.getElementsByTagName("body").item(0);		
		divPreloader = document.createElement("div");
			
		divLeft = (bodyWidth		 / 2) - (50 / 2) + 20;
		divTop	= (browserHeight / 2) - (50 / 2) - 20;
		
		divPreloader.setAttribute("id","divPreloader");
		
		divPreloader.style.position 	= "fixed"; 
		divPreloader.style.left	 	 		= divLeft + "px";
		divPreloader.style.top				= divTop  + "px";	
		divPreloader.style.width 			= "50px";
		divPreloader.style.height 		= "50px";
		divPreloader.style.background = "transparent";
		divPreloader.style.zIndex 	 	= "9998";
		divPreloader.style.display 	 	= "block";
		divPreloader.style.color		  = "#CCCCCC";	
			
		htmlBody.insertBefore(divPreloader, htmlBody.firstChild);
		
		var swf = new SWFObject("files/swf/preloader.swf", "divPreloader", 50, 50, 10, "#CCCCCC");
						
		swf.addParam("wmode"		,"transparent");
		swf.addParam("quality"	,"high");
		
		if (!swf.write("divPreloader")) 
			{
			noFlash = true;		
			
			divPadding = 30;
			
			divLeft = (bodyWidth		 / 2) - (flashWidth  / 2);
			divTop	= (browserHeight / 2) - (120 / 2);
			
			divPreloader.setAttribute("onclick","fadeOut();");
			
			divPreloader.style.left	 			= divLeft + "px";
			divPreloader.style.top				= divTop  + "px";	
			divPreloader.style.width 			= (flashWidth  + (divPadding * 2)) + "px";
			divPreloader.style.height 		= (120 				 + (divPadding * 2) - (divPadding / 2)) + "px";
			divPreloader.style.background = "#222222";
			divPreloader.padding					= divPadding;
			divPreloader.innerHTML 				= "<h2 style='color:#FFFFFF;'>Inhalt kann nicht angezeigt werden.</h2>Ihr Browser verfügt derzeit nicht über ein FlashPlugin. Der von Ihnen angeforderte Inhalt benötigt das FlashPlugin ab Version 6. Das FlashPlugin ist absolut kostenlos und kann unter dem unten stehenden Link heruntergeladen werden. <p><a href='http://get.adobe.com/de/flashplayer/' target='_blank'>FlashPlugin kostenlos herunterladen</a></p>";			
			};
		}
	else
		{
		document.getElementById("divPreloader").style.display = "block";
		}
		
	if (!noFlash)
		{		
		setTimeout("flashLayer(\"" + swfFile + "\",\"" + swfTitle + "\")",waitingTime);
		}
	}
	
function flashLayer (swfFile, swfTitle)
	{	
	if (!document.getElementById(swfFile))
		{
		size();		
		
		htmlBody = document.getElementsByTagName("body").item(0);		
		divFlash = document.createElement("div");
			
		divLeft = (bodyWidth		 / 2) - (flashWidth  / 2);
		divTop	= (browserHeight / 2) - (flashHeight / 2);
		
		divFlash.setAttribute("id",fileName(swfFile));
		
		divFlash.style.position 	= "fixed"; 
		divFlash.style.left	 	 		= divLeft + "px";
		divFlash.style.top				= divTop  + "px";	
		divFlash.style.width 			= flashWidth  + "px";
		divFlash.style.height 		= flashHeight + "px";
		divFlash.style.background = "transparent";
		divFlash.style.zIndex 	 	= "9999";
		divFlash.style.display 	 	= "block";
			
		htmlBody.insertBefore(divFlash, htmlBody.firstChild);
		}
	else
		{
		document.getElementById(swfFile).style.display = "block";
		}
		
	getSWF(swfFile, swfTitle);
	}
	
function getSWF (swfFile, swfTitle)
	{
	var swf = new SWFObject("files/swf/" + swfFile + ".swf", fileName(swfFile), flashWidth, flashHeight, 10, "#CCCCCC");
						
	swf.addParam("wmode"		,"transparent");
	swf.addParam("quality"	,"high");
	swf.addParam("FlashVars","swfFile=" + fileName(swfFile) + "&swfTitle=" + swfTitle);
	
	swf.write(fileName(swfFile));	
	}
	
function flashLoaded ()
	{
	document.getElementById("divLayer").removeAttribute("onClick",0);
	document.getElementById("divPreloader").style.display = "none";	
	}
		
function fadeOut (swfFile)
	{
	if (!fadingIn)
		{	
		if (currentFrame == 8)
			{
			if (document.getElementById(fileName(swfFile)))
				{
				document.getElementById(fileName(swfFile)).style.display = "none";	
				}
			else
				{
				document.getElementById("divPreloader").style.display = "none";
				}
			}
		
		fadingOut = true;	
		
		currentFrame--;	
	
		if (currentFrame > 0)
			{	
			divLayer.style.filter	 	 	= "alpha(opacity=" + currentFrame + "0)";
			divLayer.style.opacity 	 	= "0." + currentFrame;
			divLayer.style.MozOpacity	= "0." + currentFrame;
			
			setTimeout("fadeOut(\"" + swfFile + "\")",fadeSpeed);
			}
		else
			{
			fadingOut = false;

			document.getElementById("divLayer").style.display		 	= "none";				
			document.getElementById("divPreloader").style.display = "none";
			}		
		}
	}
