var visibleForegroundLayer = null;

function getBrowserSizeXY() {
	var intH = 0;
	var intW = 0;

	if(typeof window.innerWidth  == 'number' ) {
	   //Non-IE
	   intH = window.innerHeight;
	   intW = window.innerWidth;
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		intH = document.documentElement.clientHeight;
		intW = document.documentElement.clientWidth;
	} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		intH = document.body.clientHeight;
		intW = document.body.clientWidth;
	}

	return { width: parseInt(intW), height: parseInt(intH) };
}

function getPageSizeXY() {
	var intH = 0;
	var intW = 0;

	intH = document.documentElement.scrollHeight;
	intW = document.documentElement.scrollWidth;
	
	return { width: parseInt(intW), height: parseInt(intH) };
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return { horizontal: parseInt(scrOfX), vertical: parseInt(scrOfY) };
}

function getScrollBarWidth() {
	// die Größe der Scrollbars
	document.body.style.overflow = 'hidden';
	var x = document.body.offsetWidth || document.body.clientWidth;
	document.body.style.overflow = 'scroll';
	
	var scrBarXY = x - (document.body.offsetWidth || document.body.clientWidth);
	if(!scrBarXY) scrBarXY = document.body.offsetWidth  - document.body.scrollWidth;
	document.body.style.overflow = '';
	
	return {width: scrBarXY};
}

function setLayerPosition() {
	var backgroundLayer = document.getElementById("backgroundLayer");
	var foregroundLayer = document.getElementById(visibleForegroundLayer);
	
	var bsXY = getBrowserSizeXY();
	var psXY = getPageSizeXY();
	var sXY = getScrollXY();

	backgroundLayer.style.height = parseInt(psXY.height) + "px";
	backgroundLayer.style.width = parseInt(psXY.width) + "px";
	
	foregroundLayer.style.left = parseInt((bsXY.width - 350) / 2) + "px";
	foregroundLayer.style.top = parseInt(30) + "px";

	if(parseInt(sXY.vertical) > 0 && (/msie/.test((navigator.userAgent.toLowerCase())))) {
		foregroundLayer.style.top = parseInt(sXY.vertical + 30) + "px";
	}
	
	if((sXY.vertical > 0 || (psXY.width != bsXY.width)) && (/firefox/.test((navigator.userAgent.toLowerCase())))) {
		backgroundLayer.style.width = parseInt(bsXY.width-16) + "px";
		foregroundLayer.style.top = parseInt(30) + "px";
	}

	backgroundLayer = null;
	foregroundLayer = null;
}

function showLayer(id) {
	visibleForegroundLayer = id;
	
	setLayerPosition();

	var backgroundLayer = document.getElementById("backgroundLayer");
	var foregroundLayer = document.getElementById(id);
	
	backgroundLayer.style.display = "block"; 
	foregroundLayer.style.display = "block";

	backgroundLayer = null;
	foregroundLayer = null;
}

function hideLayer() {
	var backgroundLayer = document.getElementById("backgroundLayer");
	var foregroundLayer = document.getElementById(visibleForegroundLayer);

	backgroundLayer.style.display = "none"; 
	foregroundLayer.style.display = "none";

	backgroundLayer = null;
	foregroundLayer = null;
	
	visibleForegroundLayer = null;
}

window.onresize = setLayerPosition;