// HINTERGRUNDBILD AN FENSTERGR�SSE ANPASSEN

window.addEvent("resize",setBackgroundImage);
window.addEvent("load",setBackgroundImage);


function setBackgroundImage() {
	
	if(!$('backgroundContainer')) return;
	   
	// mit random bg hintergrund und infotext laden
	var imgSrc = $('backgroundContainerIMG').getProperty('src');
	   
	var defWidth         = 1500;
	var defHeight        = 1000;      
	var defRatio         = defWidth / defHeight;
	var hgbCt            = $('backgroundContainer');
	var img              = $('backgroundContainerIMG');
	   
	hgbCt.style.width    = "0px";
	hgbCt.style.height   = "0px";
	   
	var width            = document.documentElement.clientWidth;
	var height           = document.documentElement.clientHeight;
	   
	hgbCt.style.width    = width + "px";
	hgbCt.style.height   = height + "px";
	   
	var tmpRatio = width / height;
	   
	if(tmpRatio > defRatio) {
	   img.style.width     = width + "px";
	   img.style.height    = width/defRatio + "px";
	} else {
	   img.style.height    = height + "px";
	   img.style.width     = height*defRatio + "px";
	}
   
   img.setOpacity(0);
   
	var fadeInEffect = new Fx.Morph(img, {
		duration: 700, transition: Fx.Transitions.Sine.easeOut
	});
 
	fadeInEffect.start({
		'opacity': [0, 1]
	});
	
}