/***************************

	fixHomePageFooter.js

	Fixes the footer on homepages by calculating the 
	heights of various columns and moving the footer
	accordingly.
	
	Necessary due to the particular positioning used
	to avoid tables.

***************************/

if (document.getElementById || document.all) { // minimum dhtml support required
  document.write("<"+"script type='text/javascript' src='js/x_core.js'><"+"/script>");
  document.write("<"+"script type='text/javascript' src='js/x_event.js'><"+"/script>");
  document.write("<"+"style type='text/css'>#footer{visibility:hidden;position:absolute;left:0px;top:0px;width:100%;clear:both;}<"+"/style>");
  window.onload = winOnLoad;
}
function winOnLoad() {

  var ele = xGetElementById('leftColumn');
  if (ele && xDef(ele.style, ele.offsetHeight)) { // another compatibility check
    adjustLayout();
    xAddEventListener(window, 'resize', winOnResize, false);
  }
}
function winOnResize()
{
  adjustLayout();
}
function adjustLayout() {
	// Get content heights and work out the bottom points of the three columns
	var headerHeight = xHeight('header');
	var leftColumnBottom = xHeight('leftColumn') + headerHeight;
	var rightColumnBottom1 = xHeight('content') + headerHeight;
//	var rightColumnBottom2 = xHeight('sidebar') + headerHeight;
	var rightColumnBottom2 = rightColumnBottom1;
	
//	alert('Left column bottom: ' + leftColumnBottom + ' Right column1 bottom: ' + rightColumnBottom1 + ' Right column2 bottom: ' + rightColumnBottom2);
	
	// Figure out which one is bigger
	
	if(leftColumnBottom > rightColumnBottom1 && leftColumnBottom > rightColumnBottom2) {
		var farthestBottom = leftColumnBottom;
	} else {
		var farthestBottom = Math.max(rightColumnBottom1, rightColumnBottom2);
	}
	
	
	//alert("Farthest down is: " + farthestBottom);
	
	//Reposition the footer and show it 
	xMoveTo('footer',0,farthestBottom);
	xShow('footer');
	
	// Change the height of the body column
	//var newBodyHeight = (farthestBottom-leftColumnBottom) + xHeight('body');
	
	var newColumnHeight = farthestBottom - headerHeight;
	//if(farthestBottom != leftColumnBottom) xHeight('leftColumn',newColumnHeight);
	
//	xHeight('body', newBodyHeight);
	//alert(newBodyHeight);
}