$(document).ready(function(){
	scaleBackground();

	$(".background-image").each(function(){
		var img = $(this);
		var objImg = new Image();
		
		var src = ($(this).attr("src")).split(".");
	
		objImg.src = src[0]+"_big.jpg";
		img.attr("src", src[0]+"_big.jpg");
		scaleBackground();
	});

});

window.onload = function (){
	scaleBackground();

	$(window).resize(function(){
		scaleBackground();
	});

	$('#background').cycle({
		fx: 'fade', // Effekt
		timeout: 5000 // Wartezeit
	});

};

function scaleBackground()
{
	var windowHeight = $(window).height();
	var windowWidth = $(window).width();
	
	$(".background-image").each(function(){
	
		var imageHeight = $(this).height();
		var imageWidth = $(this).width();

		var newImageHeight = "";
		var newImageWidth = "";

		if(windowHeight/windowWidth <= imageHeight/imageWidth)
			{
				newImageWidth = windowWidth;
				newImageHeight = imageHeight * newImageWidth / imageWidth;
			}
		else
			{
				newImageHeight = windowHeight;
				newImageWidth = imageWidth * newImageHeight / imageHeight;
			}

		$(this).css({height: newImageHeight+"px", width: newImageWidth+"px"});
		
	});
}
