// Nejake constanty
// Vyska obrazku top background (bckText.jpg)
var BCK_HEIGHT = 803;

// Minimalni velikost od ktere se pak zacinaji elementy posouvat
var MIN_HEIGHT = 630;

function adjustPositions(){
	var h = $(window).height();

	// If there is some remaining space, split it by two
	// and add pixel rows on top and bottom
	var remainingSpace = h - MIN_HEIGHT;
	if (remainingSpace > 0) {
		var additionalSpaceTop = Math.round(remainingSpace / 2);
		var topBackgroundHeight = Math.min(MIN_HEIGHT + additionalSpaceTop, BCK_HEIGHT);
		additionalSpaceTop =  topBackgroundHeight - MIN_HEIGHT;

		var additionalSpaceBottom = remainingSpace - additionalSpaceTop;

		$("#topBackground")[0].style.height = topBackgroundHeight + "px";
		$("#middleBackground")[0].style.top = topBackgroundHeight + "px";

		$("#topContents")[0].style.top = 20 + Math.round(additionalSpaceTop / 2) + "px";
		$("#bottomContents")[0].style.top = 209 + additionalSpaceTop + "px";
	}

	// Also need to set the height of the container
	var winSize = $(window).height();
	var docSize = $(document).height();

	// For some reason, on IE document.height() returns additional 4 pixels
	if (
			(($.browser.msie) && (docSize - 4 > winSize))
			||
			((!$.browser.msie) && (docSize > winSize))
		)
	{
		$("#container")[0].style.height = docSize + "px";
	}
}


// First adjust when DOM is ready - most of the heights is already in (set on CSS)
$(window).ready(function(){
	// Adjust positions
	adjustPositions();

	// For some reason, this fixes IE7
	// ... need to set the container DIV's display to block onReady (although it's DIV)
	$("#container").css("display", "block")
});

// Might need to re-adjust after images are loaded
$(window).load(function(){
	// Adjust positions
	adjustPositions();
});
