function setupResizeElements()
{
	// install onresize function, perform some additional configuration
	var i, cfg;
	cfg = window.elementResizeConfig; // expects an array of object literals
	if (cfg)
	{
		for(i in cfg)
		{
			// DOM lookup is expensive, so do it in advance.
			cfg[i].element = document.getElementById(cfg[i].elementId);
			cfg[i].minPixels = (cfg[i].minPixels) ? cfg[i].minPixels : 0;
		}
	}
	window.onresize = setResizeTimeout;
	window.onresize();
}

function matchElementHeights()
{
	var i, cfg
	var bottom = 0;
	var offsets = new Array();
	var windowHeight = getWindowHeight();
	cfg = window.matchElementHeightsConfig;
	if (!cfg) return;
	for(i in cfg)
	{
		// first compute the lowest bottom
		var el = document.getElementById(cfg[i].elementId);
		if(!el) continue;
		el.style.height="auto";
		cfg[i].element = el; // store for later
		var offset = getAbsoluteOffset(el);
		var thisBottom = (offset + el.offsetHeight);
		bottom = Math.max(bottom, thisBottom);
		bottom = Math.max(bottom, windowHeight);
	}
	for(i in cfg)
	{
		// now set them all to match heights
		var el = cfg[i].element;
		if(!el) continue;
		var pad = cfg[i].bottomPadPixels;
		var offset = getAbsoluteOffset(el);
		el.style.height = bottom - (pad + offset);
	}
}

function setResizeTimeout(evt)
{
	if(window.resizeTimeoutHandle) window.clearTimeout(window.resizeTimeoutHandle);
	window.resizeTimeoutHandle = window.setTimeout("doResize();", 200);
}

function doResize()
{
	resizeElements();
	matchElementHeights();
}

function resizeElements()
{	//expand elemments from config array to fill the available height of the window.
	if(window.resizeTimeoutHandle) window.clearTimeout(window.resizeTimeoutHandle);
	var cfg = window.elementResizeConfig;
	if(!cfg) return;
	var el,i,offset;
	var windowHeight = getWindowHeight();
	for(i=0;i<cfg.length; i++)
	{
		el = cfg[i].element;
		if (!el) continue;
		el.style.height = "auto";
		offset = getAbsoluteOffset(el) + cfg[i].bottomPadPixels;
		el.style.height = cfg[i].minPixels;
		el.style.height = Math.max(windowHeight - offset, cfg[i].minPixels);
	}
}

function getAbsoluteOffset(el)
{
	// return the real rendered position of the object, accounting for nested positioning containers
	var offset = el.offsetTop;
	if (el.offsetParent)
		offset += getAbsoluteOffset(el.offsetParent)
	return offset;
}
function getWindowHeight()
{
	// get the inside height of the window in a platform-agnostic manner
	var h;
	if (self.innerHeight) // all except Explorer
		h=self.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight) //IE 6
		h=document.documentElement.clientHeight;
	else if (document.body) // other Explorers
		h=document.body.clientHeight
	// otherwise return null and deal with it later.
	return h;
}

