/*document.getElementById('content').style.display = 'block';
document.getElementById('content').style.width = document.getElementById('content').firstChild.style.width = 1000 + 'px';
document.getElementById('content').style.height = document.getElementById('content').firstChild.style.height = 739 + 'px';
document.getElementById('footer').style.display = 'block';
document.getElementById('content').parentNode.style.width = 1000 + 'px';
document.getElementById('windowhelper').style.display = 'none';
*/
///// INIT

var def_scale_x = 2500;
var def_scale_y = 739;

var iMinWidth = 1962;
var iMinHeight = 580;

var iFlashContentAspectRatio = 1000/739;
var iDefaultContentWidthCentered = 1000;

var iFooterHeightMin = 60;
var iFooterWidth = 500;


//// PREPARE

var iWindowWidth;
var iWindowHeight;

var scale_x = def_scale_x; 
var scale_y = def_scale_y; 

var iWrapperXPos;
var iWrapperWidth;


///// PROGRAM


function Fensterweite (){
	try{
		iWindowWidth = window.innerWidth;
	}
	catch(e){
		iWindowWidth = 0;
	}
	if(!iWindowWidth)
	{
		document.getElementById('windowhelper').style.display = 'block';
		iWindowWidth = document.getElementById('windowhelper').offsetLeft;
		if(iWindowWidth){
			iWindowWidth = iWindowWidth + 10;
		}
	}
	//document.getElementById('windowhelper').style.display = 'none';
}

function Fensterhoehe ()
{
	try{
		iWindowHeight = window.innerHeight;
	}
	catch(e){
		iWindowHeight = 0;
	}
	if(!iWindowHeight)
	{
		document.getElementById('windowhelper').style.display = 'block';
		iWindowHeight = document.getElementById('windowhelper').offsetTop;
		if(iWindowHeight){
			iWindowHeight = iWindowHeight + 10;
		}
	}
	//document.getElementById('windowhelper').style.display = 'none';
}



function ScaleFlash()
{
	var iFlashAspectRatioW = def_scale_x/def_scale_y;
	var iFlashAspectRatioH = def_scale_y/def_scale_x;
	
	var iWindowAspectRatio = iWindowWidth/ (iWindowHeight - iFooterHeightMin);
	
	if(iFlashContentAspectRatio > iWindowAspectRatio)
	{	
		// Breite anpassen
		scale_x = iWindowWidth * def_scale_x / iDefaultContentWidthCentered ;
		scale_y = iFlashAspectRatioH * scale_x;
	}
	else
	{
		// Höhe anpassen
		scale_y =  iWindowHeight - iFooterHeightMin;
		scale_x = iFlashAspectRatioW * scale_y;
	}
	
	scale_x = Math.round(scale_x);
	scale_y = Math.round(scale_y);
	
	if(scale_x < iMinWidth || scale_y < iMinHeight)
	{
		scale_x = iMinWidth;
		scale_y = iMinHeight;
	}
	else if(scale_x > def_scale_x || scale_y > def_scale_y)
	{
		scale_x = def_scale_x;
		scale_y = def_scale_y;
	}
	
	document.getElementById('content').style.width = document.getElementById('content').firstChild.style.width = scale_x + 'px';
	document.getElementById('content').style.height = document.getElementById('content').firstChild.style.height = scale_y + 'px';
}

function CenterFlash()
{
	var iWindowCenterX = iWindowWidth / 2;
	var iContentWidth = iDefaultContentWidthCentered / def_scale_x * scale_x;
	
	if((iContentWidth / 2) > iWindowCenterX){
		iWrapperXPos = (scale_x - iContentWidth) / -2;
	}
	else{
		iWrapperXPos = iWindowCenterX - (scale_x / 2);
	}
	
	iWrapperXPos = Math.round(iWrapperXPos);
	
	document.getElementById('content').parentNode.style.left = iWrapperXPos + 'px';
}

function fixScrolling()
{
	var iWrapperHeight = scale_y + iFooterHeightMin - 5;
	document.getElementById('content').parentNode.style.height = iWrapperHeight + 'px';
	
	var iContentWidth = iDefaultContentWidthCentered / def_scale_x * scale_x;
	iWrapperWidth = iWrapperXPos < 0 ? (iWrapperXPos * -1) : iWrapperXPos;
	
	var iFooterXpos = iWrapperWidth;
	
	if(iContentWidth > iWindowWidth){
		iWrapperWidth += iContentWidth;
		iFooterXpos += ((iContentWidth - iFooterWidth) / 2);
	}
	else{
		iWrapperWidth += iWindowWidth;
		iFooterXpos += ((iWindowWidth - iFooterWidth) / 2);
	}
	
	iWrapperWidth = Math.round(iWrapperWidth);
	iFooterXpos = Math.round(iFooterXpos);
	
	document.getElementById('content').parentNode.style.width = iWrapperWidth + 'px';
	document.getElementById('footer').style.marginLeft = iFooterXpos + 'px';
}



function neuAufbau()
{
	try
	{
		Fensterweite();
		Fensterhoehe();
		ScaleFlash();
		CenterFlash();
		fixScrolling();
	}
	catch(e){

	}
}


var iTmp = iMinHeight + iFooterHeightMin - 5;
document.getElementById('scrollhelper').style.height = iTmp + 'px';
iTmp = iDefaultContentWidthCentered / def_scale_x * iMinWidth;
document.getElementById('scrollhelper').style.width = iTmp + 'px';

neuAufbau();
window.onresize = neuAufbau;
document.getElementById("wrapper").style.display = 'block';


