
///////////// DIVS CANNOT HAVE PADDING, MARGINS OR BORDERS FOR JAVASCRIPT REPOSITIONING!!! /////////////
///////////// MUST SPECIFY "px" OR "%" FOR MOZILLA SIZES ////////////

function AutoColumnLayout () {
	var columns_to_watch = new Array();
	var columns_to_resize = new Array();
	var footer = "";
	
	AutoColumnLayout.prototype.addColumnToWatch = function(col_id)
	{
		columns_to_watch[columns_to_watch.length] = col_id;
	}
	AutoColumnLayout.prototype.setColumnsToResize = function(cols) {
		columns_to_resize = cols;
	}
	AutoColumnLayout.prototype.setFooter = function(foot) {
		footer = foot;
	}
	AutoColumnLayout.prototype.update = function() {
		// Get the maximum height of the columns on the page
		var max_height = 0;
		var e;
		for (var i = 0; i < columns_to_watch.length; i++) {
			e = document.getElementById(columns_to_watch[i]);
			if (e) {
				if (e.offsetHeight) {
					if (columns_to_watch[i] == 'keyStage1' || columns_to_watch[i] == 'keyStage2') {
						// Add on height of 
						if ((document.getElementById('intro_panel').offsetHeight + e.offsetHeight) > max_height) {
							max_height = (document.getElementById('intro_panel').offsetHeight + e.offsetHeight);
						}
					} else {
						if ((e.offsetHeight) > max_height) {
							max_height = (e.offsetTop + e.offsetHeight);
						}
					}
				}
			}
		}
		//alert(max_height);
		if (max_height != 0) {
			// Adjust footer if specified
			if (document.getElementById(footer)) {
				// Position the footer
				document.getElementById(footer).style.top = max_height + "px";
			}
			
			// Resize columns if necessary
			document.getElementById('keyStage1').style.height = (max_height - document.getElementById('intro_panel').offsetHeight) + "px";
			document.getElementById('keyStage2').style.height = (max_height - document.getElementById('intro_panel').offsetHeight) + "px";
			document.getElementById('keyStage3').style.height = max_height + "px";
		
			/*if (columns_to_resize.length > 0) {
				for (var i = 0; i < columns_to_resize.length; i++) {
					e = document.getElementById(columns_to_resize[i]);
					if (e.offsetTop && e.offsetHeight && e.style) {
						if ((e.offsetTop + e.offsetHeight) < max_height) {
							e.style.height = max_height - e.offsetTop + "px";
						}
					}
				}
			}*/
		}
	}
}

