window.addEvent('domready',function(){

	var imageDims = new Object();
	imageDims.width = 1024;
	imageDims.height = 768;	
	
	// Ende Anpassbarer Teil
	
	function windowWidth () {
		var theWidth;
		
		if (window.innerWidth) {
		theWidth=window.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientWidth) {
		theWidth=document.documentElement.clientWidth;
		}
		else if (document.body) {
		theWidth=document.body.clientWidth;
		}
		
		return theWidth;

	}
	
	

	

	function windowHeight () {
		
		
		var theHeight;
		// Window dimensions:
		if (window.innerHeight) {
		theHeight=window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight) {
		theHeight=document.documentElement.clientHeight;
		}
		else if (document.body) {
		theHeight=document.body.clientHeight;
		}
		
		
		if($('whiteContainer').getCoordinates().height < theHeight){
			return theHeight;
		}else{
			return $('whiteContainer').getCoordinates().height + 40;
		}
		
	}
	
	
	var wWidth    = windowWidth();
	var wHeight   = windowHeight();
	


	var newWidth  = 0;
	var newHeight = 0;
	


	function stretchBg(){

		wWidth  = windowWidth();
		wHeight = windowHeight();
		
		// console.log('wWidth, wHeight',wWidth, wHeight);
		
		newWidth = wWidth;
		newHeight = (imageDims.height / imageDims.width) * newWidth;
		
		if(newHeight<wHeight){
			newHeight = wHeight;
			newWidth = (imageDims.width / imageDims.height) * newHeight;
		}
				
		// console.log('newWidth',newWidth);
		// console.log('newHeight',newHeight);
 		
		imageDims.width = newWidth;
		imageDims.height = newHeight;
		
		$('background').setStyle('width',imageDims.width);
		$('background').setStyle('height',imageDims.height);		
		$('bgContainer').setStyle('height', wHeight);
		$('bgContainer').setStyle('width',wWidth);	
		// alert('streched');
	}
	
	
	stretchBg();
	
	
	window.addEvent('resize',function(){
		stretchBg();
	});
	
	window.addEvent('load',function(){
		stretchBg();
	});

	
});


