$(document).ready( function() {
	
	initBGImage();
	$(window).resize( function() { initBGImage(); } );
});


initBGImage = function() {
	if ($("#backgroundImage").size() != 1) {
		$("body").css("background-image", "none");
		$("body").prepend('<img id="backgroundImage" src="images/Himmel.jpg" style="display:none;" alt="" />');
		$("#backgroundImage").data("ratio",  $("#backgroundImage").width() / $("#backgroundImage").height());
	}
	
	var isIE6 = false;
	if ($.browser.msie && $.browser.version == '6.0') {
		$("#backgroundImage").css("position", "absolute");
		isIE6 = true;
	}
	
	var _w = parseInt($(window).width()), _h = parseInt($(window).height()), _cssType = '', _cssStr = '';
	var ratio = $("#backgroundImage").data("ratio");
	var sratio = Math.round( parseFloat(_w / _h) * 100) / 100;
	
	if (sratio < ratio) {
		_cssType = 'height';
		_cssStr = parseInt(_w/sratio) + 'px';
		$("#backgroundImage").css("width", "");
		if (isIE6) {
			$("body").css("overflow-y", "hidden");
		}
	} else {
		_cssType = 'width';
		_cssStr = parseInt(_h*sratio) + 'px';
		$("#backgroundImage").css("height", "");
		if (isIE6) {
			$("body").css("overflow-x", "hidden");
		}
	}
	
	$("#backgroundImage").css(_cssType,_cssStr).css('display','block');
}
