// JavaScript Document


function WindowSizewidth() {
        var myWidth = 0;
        if (typeof(window.innerWidth) == 'number')
        {
            //Non-IE
            myWidth = window.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientWidth)
        {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
        }
        else if (document.body && document.body.clientWidth)
        {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
        }
		//alert(myWidth);
        return myWidth;
}

function WindowSizeheight() {
   
        var myHeight = 0;
        if (typeof(window.innerHeight) == 'number')
        {
            //Non-IE
            myHeight = window.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
            //IE 6+ in 'standards compliant mode'
            myHeight = document.documentElement.clientHeight;
        }
        else if (document.body && document.body.clientHeight)
        {
            //IE 4 compatible
            myHeight = document.body.clientHeight;
        }
        return myHeight;
}


var Winwidth= WindowSizewidth();
var Winheight= WindowSizeheight();

Event.observe(window, 'load', function(event) {
									 
    Winwidth 	= WindowSizewidth();
	Winheight 	= WindowSizeheight();
});

Event.observe(window, 'resize', function(event) {
										 
    Winwidth 	= WindowSizewidth();
	Winheight 	= WindowSizeheight();
});










//bg skalieren
function resizebildb (elm) {
	
	
	
	browserw 	= WindowSizewidth();
	browserh 	= WindowSizeheight();
	
}


function resizebild () {
	
	
	$$('.backimage').each(function(element) {
	
		new resizebild_e (element,0,0);
		
		
	});
	
}



function resizebild_e (element,bildw,bildh) {
	//alert(element);
		bild = element;
		//bild.makePositioned();
		
//		bildh = bild.getHeight();
//		bildw = bild.getWidth();
		
		browserw 	= WindowSizewidth();
		browserh 	= WindowSizeheight();
		
		//alert(bildw);
		
		
		
		
		
		
		
		if (bildw<1) bildw = bild.getWidth();
		if (bildh<1) bildh = bild.getHeight();
	
	
		factorh = browserh / bildh;
		factorw = browserw / bildw;
		
		//alert(factorh + ' '+factorw);
		
		if (factorh > factorw) {
			
			factor = factorh;
		} else {
			factor = factorw;
		}
		
		//alert(browserw);
	//	alert(Math.ceil(bildw * factor) );
		
		bild.style.height = (bildh * factor) + "px"; 
		bild.style.width = (bildw * factor) + "px"; 
		//bild.makePositioned();
		
	
		//bild.style.left = "50%";
		if (bildw > browserw) {
			bild.style.left = "50%";
		bild.style.marginLeft = Math.floor( (bildw) / 2 *-1) + "px"; 
		} else {
			bild.style.left = "0px";
			bild.style.marginLeft = "0px";
		}
		
		//$('date').update(bildw + ' ' + browserw + ' ');
	
}


/*
onresize = function () {
	resizebild ();
};*/


Event.observe(window, 'resize', function(event) {
			resizebild ();							 
});



/*onload = function () {
	resizebild ();
};*/

