//stretches the page to the bottom of the browser
function fillPage() {
	//get height of display area of browser window (i.e. non-toolbar, etc. area; supported by higher browsers --> lower browsers return "0")
	var winHeight = document.documentElement.clientHeight;
	if(document.getElementById && document.getElementsByTagName) {
		//gets height of web page itself (area btw body tags; this area may be smaller or larger than winHeight)
		var bodyHeight = document.getElementsByTagName("body")[0].clientHeight
		//gets height of content area
		var contentHeight = document.getElementById("content").offsetHeight;
		//only apply correction if page isn't already filling browser window
		if(bodyHeight < winHeight) {
			//gets the height difference to be added to the content div (minus 1/20, then 10px, as otherwise scrollbars appear)
			var newHeight = contentHeight + (winHeight-bodyHeight);
			newHeight = Math.floor(newHeight - newHeight/20) - 10;
			//adds difference calc'd above to the content div
			// minHeight used to ensure div can expand when other js fn's change size of elements w/in content div
			document.getElementById("content").style.minHeight = newHeight + "px";
			// adds support for IE6 (isltIE7 set to true in CC's)
			if(isltIE7) { document.getElementById("content").style.height = newHeight + "px"; }
		}
		
		
	}
}

//fits title text into div sideBar (if req'd; esp. for 800x600 browsers
textSize = 150; //text size in % (starting value)
counter = 0; //used to prevent infinite loop (fail-safe)
function checkTitleWidth() {
	if(document.getElementById && document.getElementsByTagName) {
		//gets widths of title and sideBar div
		//need to use "a", as "p" is always width of div
		//+15 accounts for margin-left
		var titleWidth = document.getElementById("ctl00_hcgSection").getElementsByTagName("a")[0].offsetWidth + 15;
		var divWidth = document.getElementById("sideBar").offsetWidth;
		//var textSize = document.getElementById("sideBar").getElementsByTagName("p")[0].style.fontSize; //this is not returning anything
		
		//if title wider than div, make text smaller
		if(titleWidth >= divWidth) {
			//decrement text size (+ increment fail-safe counter
			textSize -= 10;
			counter += 1;
			//fail-safe
			if(!(counter > 10)) {
				//decrease font size
				document.getElementById("ctl00_hcgSection").style.fontSize = textSize + "%";
				//recheck (loop until done)
				checkTitleWidth();
			}
		}
	}
}

//centres page vertically based on window height - js must be after <body> tag + body tag must have id (here, it's 'body')
function centrePageVert() {
	//get height of window (supported by higher browsers --> lower browsers return "0")
	var winHeight = document.documentElement.clientHeight;
	//pageBG is div w/ all content except Header. 80px is height of header
	var contentHeight = document.getElementById('pageBG').clientHeight + 80;
	if(winHeight > contentHeight) {
		//gets a little less than 1/2 the difference btw window height and page height to top (looks better w/o full 1/2 added
		var addTop = Math.floor((winHeight-contentHeight)/2.8);
		//adds difference calc'd above to top body margin (checks if getElementById supported 1st to avoid errors)
		if(document.getElementById){
			document.getElementById('body').style.marginTop = addTop + "px";
		}
	}	
}

/*inserts Flash onto the page (used to avoid IE "Click to activate..." nag	
ran = total # of random #'s to choose from (0 = always)
flaFile = path to swf
w = swf width
h = swf height
fv = flashVars
div = div containing swf
killTime = time to keep fla onscreen (0 = permanent) */
function insertFla(ran, flaFile, w, h, fv, div, killTime) {
	//randomly adds fla
	//setTimeout used to delay this slightly to let FlashVars load
	if(Math.floor(Math.random()*ran) == 0) { window.setTimeout('addFla("' + flaFile + '",' + w + ',' + h + ',"' + fv + '","' + div + '",' + killTime +')',1); }
	//addFla(flaFile, w, h, fv, div, killTime
}

//uses swfobject (downloaded online)
function addFla(flaFile, w, h, fv, div, killTime) {
	var so1 = new SWFObject(flaFile, "swfHeader", w, h, "7", "#FFFFFF");
	so1.addParam("movie", flaFile); 
	so1.addParam("wmode", "transparent");
	so1.addParam("FlashVars", fv);  
	so1.write(div);
	window.setTimeout("killFla('" + div + "'," + killTime + ")",killTime);	
}

//added so user can still click on header after killTime seconds in FF
function killFla(div, killTime) {
	if(killTime > 0) {
		document.getElementById(div).innerHTML = "";
	}
}
