﻿addEvent(window, "load", initLayout);

function initLayout(){
	var siteLayout = new Layout();
	siteLayout.Adjust();
}

//This function is used to stretch each of the three columns to the max height of all three columns
function Layout(){
	var ch = $("channelHeading");
	var pc = $("primaryColumn");
	var cc = $("contentColumn");
	var sc = $("secondaryColumn");
	var maxHeight;
	var ccTopMargin = 12;

    this.Adjust = function(){with(this){
		if (GetHeight(pc) > GetHeight(cc)){
			maxHeight = GetHeight(pc);
		}else{
			maxHeight = GetHeight(cc);
		}
		if (maxHeight < GetHeight(sc)){
			maxHeight = GetHeight(sc);
		}
	      
		maxHeight += (ccTopMargin * 2);

		SetHeight(pc, maxHeight + ccTopMargin + 7); 
		SetHeight(cc, maxHeight - GetHeight(ch) + ccTopMargin + 1); 
		SetHeight(sc, maxHeight - GetHeight(ch) + ccTopMargin + 1);
	}}
	
	function GetHeight(id){
		if ( id != null ) return id.offsetHeight;
		else return 0;
	}

	function SetHeight(id, newHeight){
		if ( id != null ) id.style.height = newHeight + 'px';
	}
	
	function Cleanup(){
		ch = null;
		pc = null;
		cc = null;
		sc = null;
		removeEvent(window,"unload",Cleanup);
	}
	addEvent(window,"unload",Cleanup);
}