/*	
	Script written specifically for Silverbear by TWA Design
	Used by permission - TWA Design reserve all rights
	Author - Mark Jackson : January 2006
	http://www.twadesign.com
	
	This script automatically sets the height and widths of the
	three content columns depending on the content.
*/

twaColumnWidths = function () { // sets the center column width depending on right bar
	var container = document.getElementById('mainContainer');
	var leftCol = document.getElementById('contentLeft');
	var middleCol = document.getElementById('contentMain');

	if(document.getElementById('contentRightBar')) {
	var rightCol = document.getElementById('contentRightBar');
	var rightW = rightCol.offsetWidth;
	} else {
		var rightW = 0;
	}	
	
	if (rightW == 0) { // if right bar is not present then set the mainContainer to full width
		middleCol.className+='full';
	}
	
	if (rightW > 168) { // if right column expands too much then compensate by changing mainContainer width
	var contW = container.offsetWidth;
	var leftW = leftCol.offsetWidth;
	var middleW = middleCol.offsetWidth;
	var newWidth = ((contW-leftW)-rightW)-15; // 15 pixel buffer to allow for padding and margins
	middleCol.style.width = newWidth + "px";
	} else { // if rightbar is set and is normal width then change style of middle bar to set width
		if ((rightW > 0)&&(rightW <= 168)) {
		middleCol.className+='short';
		}
	}
	
	// Check for main content panels and resize as needed
}

twaColumnHeight = function () { // sets all column heights the same as the highest
	var elm = document.getElementById('mainContainer');
	var leftCol = document.getElementById('contentLeft');
	var middleCol = document.getElementById('contentMain');
	if(document.getElementById('contentRightBar')) {
	var rightCol = document.getElementById('contentRightBar');
	}
	// put heights into variable to alert for debugging
	var setAlertText = elm.offsetHeight+" - "+leftCol.offsetHeight+" - "+middleCol.offsetHeight;  // DEV
	
	// find the highest column
	var highest = (leftCol.offsetHeight+73);
		if (middleCol.offsetHeight>highest) {
			var highest = middleCol.offsetHeight;
		}
		if((rightCol)&&(rightCol.offsetHeight>highest)) {
			var highest = rightCol.offsetHeight;
		}
	
	var highest = (highest-10);  // offset to allow for margins/padding
	
	elm.style.height = highest + "px";
	leftCol.style.height = (highest-63) + "px";  // offset to allow for margins/padding
	middleCol.style.height = highest + "px";
	
	if(rightCol) {
	var setAlertText = setAlertText+" - "+rightCol.offsetHeight  // DEV
	rightCol.style.height = (highest+6) + "px"; // offset to allow for margins/padding
	}
	//alert(setAlertText); 	 // DEV
	//alert(highest);		 // DEV
}

if(window.addEventListener) window.addEventListener("load", twaColumnWidths, false); // for non IE browsers
else if(window.attachEvent) window.attachEvent("onload", twaColumnWidths);			 // for IE

// opera is not quick enough to handle the columnHeight script 
// so check if the browser is not opera and append body attribute
if(navigator.userAgent.indexOf("Opera")==-1){
if(window.attachEvent) window.attachEvent("onload", twaColumnHeight);			 // for IE
}



 
