addEvent(window, "load", fluidWindow);
addEvent(window, "resize", fluidWindow);
var domCompat = (document.getElementById) && (document.documentElement); // essential DOM compatability

function fluidWindow() {
	/* fluidWindow
		ABOUT:				Calculates the screen height available to the main content area
							and calls attachFluidCSS to remove the existing style sheet that
							dictated the height and attaches a new one.
		BUGS:				none known
		TODO:				Find a workable way of attaching a stylesheet cross-browser so we
							don't have to browser sniff.
		PARAMETERS:			none
		RETURNED VALUES:	none
			CHANGE LOG:
		2005.??.??   JEM   Created.
		2006.04.27   JEM   Changed from directly applying the height to the element to using
						   attachFluidCSS, instead, to prevent print problems.
		2006.05.09   JEM   Added browser sniffing to work around IE's limitations.  :-(
	*/
	if (domCompat) { // DOM check & not Mac/IE
		try {
			var y;
			var isIE = true;
			if (self.innerHeight) { // all except Explorer
				y = self.innerHeight;
				isIE = false;
			}
			else if (document.documentElement && document.documentElement.clientHeight) {
				// Explorer 6 Strict Mode
				y = document.documentElement.clientHeight;
			}
			else if (document.body) { // other Explorers
				y = document.body.clientHeight;
			}
			var scrollingDiv = document.getElementById('content');
			var scrollHeightNew;
			if (y < 234) { // started the "locked" environment
				scrollHeightNew = "100px";
			} else { // start the "elastic" environment
				scrollHeightNew = y - 155 + "px";
			} // end if y < 600
			if (scrollingDiv) {
				if (isIE) {
					scrollingDiv.style.height = scrollHeightNew;
				} else {
					attachFluidCSS(scrollHeightNew);
				}
			}
		} catch(e) {
			// alert (e.message) // not sure why an object error is thrown in IE on occassion, so we'll just catch and ignore it...
		}
	} // end if domCompat
} // end fluidWindow

function attachFluidCSS(height) {
	/* attachFluidCSS
		ABOUT:				Removes the existing fluidCSS stylesheet and reattaches it
							using a new URL paramater for CF processing
		BUGS:				Causes IE<7 to crash.  Doesn't work on IE7.  Seems to be related
							to dynamically loading stylesheets.  Possibly related to IE's
							multiple-firing onWindowResize event.  Tried attaching both a link
							and a style tag, both via DOM node manipulation and innerHTML methods
							but to no avail in IE.
		TODO:				none
		PARAMETERS:			height - the desired height of the content div in CSS notation.
		RETURNED VALUES:	none
			CHANGE LOG:
		2006.04.27   JEM   Created.
		2006.05.09   JEM   Changed to append style tag rather than a link tag so as to prevent
						   an extra trip to the server.
	*/
	var parentNode = $('fluidCSS').parentNode;
	parentNode.removeChild($('fluidCSS'));
	var newCSS = document.createElement('style');
	newCSS.setAttribute('type','text/css');
	newCSS.setAttribute('id','fluidCSS');
	newCSS.setAttribute('media','screen');
	var innerCSS = document.createTextNode('#content {height:'+height+';}');
	newCSS.appendChild(innerCSS);
	parentNode.appendChild(newCSS);
}
