
/* If we are IE, do all the IE related junk */ 
if(typeof(isIE) != "undefined"){

	/* Suckerfish hovering for IE */
	sfHover = function() {
		var sfEls = document.getElementById("mainNav").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);

}

/* Courtesy of http://www.quirksmode.org/js/cookies.html */

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/*--------------------------------------------------------*/

function windowOnResize(){
	windowHeight = $(window).height();
	topMargin = (windowHeight/3)-(177);
	topMargin = (topMargin > 0)?topMargin:0;
	backgroundOffset = 374;
	backgroundOffset = ($.support.cssFloat)?backgroundOffset:backgroundOffset+0.7;
	$("#pagecontainer").css({marginTop:topMargin});
	$("#sitecontainer, body").css({backgroundPosition:"center "+(topMargin-backgroundOffset)+"px"});
	createCookie("topMargin",topMargin,90);
}

$(document).ready(function(){
	/* Add arrows to LIs with children */
	$("#mainNav li").each(function(){
		if($("ul", this).length > 0){ 
			$(">a:first-child", this).addClass("hasChildren");
		}
	});
	
	windowOnResize();
	$(window).resize(function(){
		windowOnResize();
	});

	
});
