// IE sucks, so tell it that li has a :hover property //
sfHover = function() {
	var sfEls = document.getElementById("headernav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

// It also doesn't want to play with position: fixed; so don't even bother...
sfFixed = function(){
	if (navigator.appName == "Microsoft Internet Explorer") {
		document.getElementById("toplink").style.display="none";
	}
}
if (window.attachEvent) window.attachEvent("onload", sfFixed);

// Getting the available browser width, each step degrades browsers and get's a less accurate number.
function getBrowserWidth(){
	if (window.innerWidth){
		return window.innerWidth;
	}else if (document.documentElement && document.documentElement.clientWidth != 0){
		return document.documentElement.clientWidth;
	}else if(document.body.clientWidth){
		return document.body.clientWidth;
	}else{
		return window.screen.availWidth;
	}
}
	

function changeWidth(){
	var wAvail = getBrowserWidth();
	// Check how wide the window is, and select a style sheet accordingly
	if (wAvail < 997){
		setStylesheet("Optional Style");
	}else{
		setStylesheet("Default Style");
	}
}
		
function setStylesheet(styleTitle){
	var currTag;
	if (document.getElementsByTagName){
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++){
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title")){
				currTag.disabled = true;
				if(currTag.getAttribute("title") == styleTitle){
					currTag.disabled = false;
				}
			}
		}
	}	
	return true;
}

function correctFloat() {
	if(document.getElementById('modules')){
		var module = document.getElementById('modules');
		module.style.height = 'auto';
		var x = module.offsetHeight;
		var newheight = x + 110;
		var container = document.getElementById('container');
		container.style.minHeight = newheight + "px";
	}
}

/* Everything else */
changeWidth();

/* Opera and IE */
if (window.attachEvent) window.attachEvent("onload", changeWidth);

/* for Mozilla browsers */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", changeWidth, null);
}

/* If they resize, we'll need to change aswell */
window.onresize = changeWidth;

/* Finally correct the container div to correct height */
window.onload = correctFloat;

