//
// Layout of elements
//

/**
 * Layout the page by moving elements into place
 */
function Layout()
{
	// Valid element?
	if( document.body )
	{
		// Reveal the page?
		document.body.className = "";
	}

	//
	// Center the page and add a top margin
	//
	
	// Find the page element
	var page = document.getElementById( "page" );
	
	// Valid element?
	if( page )
	{
		// Use absolute positioning
		page.style.position = "absolute";
			
		// Top margin
		page.style.top = 16 + "px";

		// Left position required to centre page
		var left = ( document.body.clientWidth - page.clientWidth ) / 2;
		
		// Check that this is positive
		left = Math.max( left, 0 );

		// Centre horizontally
		page.style.left = left + "px";
	}
	
	//
	// Extend menu bar and page content so that they are as long as the longest
	//
	
	// Find the menu border element
	var menu = document.getElementById( "menu_border" );
	
	// Find the content border
	var content = document.getElementById( "content_border" );
	
	// Valid elements?
	if( menu && content )
	{
		// Menu height
		var menu_height = menu.offsetHeight;
		
		// Content height
		var content_height = content.offsetHeight + 12;
		
		// Find the max
		var maximum = Math.max( menu_height, content_height );
		
		// Use a minimum of 336
		maximum = Math.max( 336, maximum );
		
		// Set the maximum height on both elements
		menu.style.height = maximum + "px";
		content.style.height = maximum + "px";
	}

	//
	// Position the footer
	//
	
	// Find the footer element
	var footer = document.getElementById( "footer" );

	// Valid elements?
	if( footer && menu)
	{
		// Set the top of the footer
		footer.style.top =  (menu.offsetTop + menu.offsetHeight) + "px";
	}
}

/**
 * On load handler
 */
window.onload = function()
{
	Layout();
}

window.onresize = function()
{
	Layout();
}