// JavaScript Document

// get the height of each column in a set, determine the tallest, set the others to the same height
var d = document;
// sets of columns to balance
// note: I don't know that it makes a diff, but it seems safest to balance the sets from innermost to outermost...
var columnSets = new Array(
	// new Array( "column1", "column2" ),
	new Array( "c1", "c2", "c3" ),
	new Array( "col1", "col2", "col3" )
);
function setHeight() {
	// loop over the array of column sets to balance
	for( i=0; i<columnSets.length; i++ ){
		// get the heights
		var box =  columnSets[i];
		var h = 0;
		for(x=0;x<box.length;x++){
			if( d.getElementById(box[x]) ){
				div = d.getElementById(box[x]);
				// unset height and scrollHeight
				div.style.height = "auto";
				div.style.scrollHeight = "auto";
				// determine the tallest div
				test_h = div.offsetHeight;
				// alert( box[x] + ": " + test_h );
				if( test_h > h ){
					h = test_h;
				}
			}
		}
		// set the height of all divs to the tallest
		for(x=0;x<box.length;x++){
			if( d.getElementById(box[x]) ){
				div = d.getElementById(box[x]);
				div.style.height = h +"px"; 
				div.style.scrollHeight = h +"px";
			}
		}		
	} // end loop over columnSets
	// zero the margins and padding on the footer
	d.getElementById("footer").style.margin = "0";
	d.getElementById("footer").style.padding = "0";
}

// call a function onload, but keep track of others so all can be successfully called
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

// call setHeight() onload using addLoadEvent()
addLoadEvent(setHeight);

// call setHeight() onresize
window.onresize = function() {
	setHeight();
}