
var NAVIGATOR_IS_IE = navigator.appName == "Microsoft Internet Explorer";

var BODY_ELEMENT_ID = 'body';
var BODY_WRAPPER_ELEMENT_ID = 'body-wrapper';
var BREAD_CRUMBS_ELEMENT_ID = 'bread-crumbs';
var TOP_MENU_ELEMENT_ID = 'top-menu';

var MIN_WIDTH = 800; // pixels
var MAX_BODY_WIDTH = 0.9; // percentage, float, 0 < n <= 1

var BODY_HEIGHT; // will be determined at runtime
var BODY_VERTICAL_PADDING = 50; // pixels
var BODY_HORIZONTAL_PADDING = 6; // pixels


function getBreadCrumbsElement()
{
	return document.getElementById(TOP_MENU_ELEMENT_ID);
}

function getTopMenuElement()
{
	return document.getElementById(BREAD_CRUMBS_ELEMENT_ID);
}

function getBodyElement()
{
	return document.getElementById(BODY_ELEMENT_ID);
}

function getBodyWrapperElement()
{
	return document.getElementById(BODY_WRAPPER_ELEMENT_ID);
}

function getDocHeight()
{
	return NAVIGATOR_IS_IE ? document.body.clientHeight : document.documentElement.clientHeight;
}

function getDocWidth()
{
	return NAVIGATOR_IS_IE ? document.body.clientWidth : document.documentElement.clientWidth;
}

function resize()
{
	//getBodyElement().style.height = "0px";
	//getBodyElement().style.height = getNewBodyHeight() + "px";
	if ( RESIZE_HORIZONTAL )
	{
		getBodyWrapperElement().style.width =  getNewBodyWidth() + "px";
		var bodyWidth = getBodyWrapperElement().clientWidth;
		getTopMenuElement().style.width = bodyWidth + "px";
		getBreadCrumbsElement().style.width = bodyWidth + "px";
	}
}

function getNewBodyHeight()
{
	var height = getDocHeight();
	var newHeight = ( height - TOP_HEIGHT ) - BODY_VERTICAL_PADDING;
	return newHeight < BODY_HEIGHT ? BODY_HEIGHT : newHeight;
}

function getNewBodyWidth()
{
	var width = parseInt(getDocWidth() * MAX_BODY_WIDTH);
	return width < MIN_WIDTH ? MIN_WIDTH : width;
}

function initResize()
{
	BODY_HEIGHT = getBodyElement().clientHeight - BODY_VERTICAL_PADDING;
	window.onresize = resize;
	resize();
}

if ( window.attachEvent )
{
	window.attachEvent('onload', initResize);
}
else
{
	window.addEventListener('load', initResize, true);
}