function balanceColumns() {
	/*
	// performance testing
	var now = new Date();
	var startTime = now.getTime();	
	*/

    if (document.getElementById) {
        // get handles to the elements we care about
        var column1 = document.getElementById('homeColumn1');
		var column2 = document.getElementById('homeColumn2');
		var column2Text = document.getElementById('homeColumn2Text');

		if (column1 && column2 && column2Text) {			
			var col2Offset = 20; // to account for the spacing that the 2nd column is pushed down by the header images

			var colHeight1 = column1.offsetHeight;
			var colHeight2 = column2.offsetHeight+col2Offset;					

			if (colHeight1 > colHeight2) {  // if column 1 is bigger, move words from it into column 2
				var prevColHeight1 = colHeight1;
				while (colHeight2 < colHeight1) {
					if(!moveWord(column1, column2Text, "forward")) {
						break;
					}
					// and check the column heights again
					colHeight1 = column1.offsetHeight;
					colHeight2 = column2.offsetHeight+col2Offset;
				}
			}
			else if (colHeight2 > colHeight1) {		// if column 2 is bigger, move words from it into column 1
				var prevColHeight2 = colHeight2;
				while (colHeight1 < colHeight2) {
					if(!moveWord(column2Text, column1, "backward")) {
						break;
					}
					// and check the column heights again
					colHeight1 = column1.offsetHeight;
					colHeight2 = column2.offsetHeight+col2Offset;
				}
			}			
		}
		else {
			alert('Error - cannot find necessary DOM elements');
		}
    }

	/*
	// performance testing
	now = new Date();
	var endTime = now.getTime();
	test("Elapsed time: " + (endTime-startTime-0)/1000);
	*/
}

function moveWord(fromElement, toElement, direction) {
	// get the contents of the 2 elements
	var fromInnerText = fromElement.innerHTML;
	var toInnerText = toElement.innerHTML;
	
	if(fromInnerText == '') {
		return false;
	}

	// ...and break these contents into arrays of words
	var fromTextArray = fromInnerText.split(" ");
	var toTextArray = toInnerText.split(" ");

	if (direction == "forward") { // this will move from the tail for 1 to the head of 2
		// remove 1st array element from the fromTextArray...
		var singleWord = fromTextArray.pop();
		// ...and add it to the toTextArray
		toTextArray.unshift(singleWord);
	}
	else if (direction == "backward") {	// this will move from the head of 2 to the tail of 1
		// remove 1st array element from the fromTextArray...
		var singleWord = fromTextArray.shift();
		// ...and add it to the toTextArray
		toTextArray.push(singleWord);
	}
	
	
	singleWord = singleWord.replace("<", "&lt;");
	singleWord = singleWord.replace(">", "&gt;");

	// join the arrays back into strings
	fromInnerText = fromTextArray.join(" ");
	toInnerText = toTextArray.join(" ");

	// and update the innerHTML of the elements
	fromElement.innerHTML = fromInnerText;
	toElement.innerHTML = toInnerText;
	
	return true;
}


function test(newText) {
	var test = document.getElementById('test');
	if (test) {
		var innerHTML = test.innerHTML;
		innerHTML += newText + "<br/>";
		test.innerHTML = innerHTML;
	}
}
