$(document).ready(function() {
	resizeElements("bi");
});

$(window).bind("load", function(e) {
	resizeElements("bi");
});

$(window).bind("resize", function(e) {
	resizeElements("bi");
});


function resizeElements(id) {
	var objBackgroundImage = $("#" + id);
	var objWindow = $(window);
	var documentWidth = $(document).width();

	var windowWidth = objWindow.width();
	var windowHeight = objWindow.height() - 122;

	var imageRatio = objBackgroundImage.width() / objBackgroundImage.height();
	var backgroundWidth = windowWidth;
	var backgroundHeight = backgroundWidth / imageRatio;
	if (backgroundHeight < windowHeight) {
		backgroundHeight = windowHeight;
		backgroundWidth = backgroundHeight * imageRatio;
	}
	objBackgroundImage.width(backgroundWidth).height(backgroundHeight);

	if (documentWidth != $(document).width()) resizeBackgroundImage(id);
}

