// by Paul@YellowPencil.com and Scott@YellowPencil.com
// feel free to delete all comments except for the above credit
// http://www.paulbellows.com/getsmart/balance_columns/column.js

function setTall() {
	if (document.getElementById) {
		// the divs array contains references to each column's div element.  
		// Replace 'center' 'right' and 'left' with your own.  
		// Or remove the last one entirely if you've got 2 columns.  Or add another if you've got 4!
		//var divs = new Array(document.getElementById('center'), document.getElementById('right'), document.getElementById('left'));

    /* use this for our content div (BodyContent) and our sidebar (LeftSidebar) */
		var divs = new Array(document.getElementById('BodyContent'), document.getElementById('LeftSidebar'));
		
		// Let's determine the maximum height out of all columns specified
		var maxHeight = 0;
		for (var i = 0; i < divs.length; i++) {
			if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight; 
		} 
		
		// correct for when we have a body header image present in the main body area
		if(divs[0]&&divs[1]){
  		heightBody = divs[0].offsetHeight + (document.getElementById('BodyHeaderImage')?0:-22) ;
  		heightSidebar = divs[1].offsetHeight;
			maxHeight = (heightBody > heightSidebar) ? heightBody : heightSidebar;
    }
	  
		// compare the current maxHeight with that of the MeasuringStick, the height of the visible window, for interior pages
		//  this pushes the copyright and marque down to the bottom of the visible window if content is short.
	  if(document.getElementById('MeasuringStick')){
		  maxHeightStick = document.getElementById('MeasuringStick').offsetHeight - 140 ; /* but don't also include the logo, nav, etc. */
		  if(maxHeightStick > maxHeight) { maxHeight = maxHeightStick; }
		}
		//alert(maxHeight);
		
		// Let's set all columns to that maximum height
		for (var i = 0; i < divs.length; i++) {
			divs[i].style.height = maxHeight + 'px'; 

			// Now, if the browser's in standards-compliant mode, the height property
			// sets the height excluding padding, so we figure the padding out by subtracting the
			// old maxHeight from the new offsetHeight, and compensate!  So it works in Safari AND in IE 5.x
			if (divs[i].offsetHeight > maxHeight) {
				divs[i].style.height = (maxHeight - (divs[i].offsetHeight - maxHeight)) + 'px';
			}
		}
		
		// now set the position of the site marque which lives in the left-hand sidebar, bottom
    var sbf = new Array(document.getElementById('SiteMarque'))
		if(sbf[0])
		{
			var bottomTop = maxHeight - 270; /* 110 */
			//var bottomTop = maxHeight;
			//alert(bottomTop);
			//sbf[0].style.top = bottomTop + 'px';
			//alert(sbf[0].style.top);
		}

		// now set the position of the site copyright which lives in the BodyContent, bottom
    var cbf = new Array(document.getElementById('BodyFooter'))
		if(cbf[0])
		{
			var bottomTop = maxHeight - 475; /* 270 w/o the body header image */
			//var bottomTop = maxHeight;
			//alert(bottomTop);
			//cbf[0].style.top =  bottomTop + 'px';
			//alert(cbf[0].style.top);
		}
		
		// now even up the site marque and the site copyright, because
		//  site marque is positioned at the very bottom (bottom:0px) 
		//  and the copyright looks better right next to it.
		if(sbf[0] && cbf[0]) { 
		
		  //alert (cbf[0].style.type); 
		  //cbf[0].style.top = sbf[0].style.top;
		
		}

		
		
	}
}

addOnLoadEvent(function() {
	setTall();
});

addOnResizeEvent(function() {
	setTall();
});

/*window.onload = function() {
	setTall();
}

window.onresize = function() {
	setTall();
}*/