/* DISPLAY FLASH CONTENT */
function hmcFlash() {
	//TEMPORARILY REMOVED
	//This is to set everyone to view flash when the next
	//site is up and running
	writeCookie("flashon","true",365);
}
function flashLink() {
	//document.write('<a href="#" onclick="hmcFlash();return false;">View the FLASH site</a>');
}
function socialLinks() {
	document.write('<div class="footer_link">');
	document.write('<a href="http://del.icio.us/post" title="Post to del.icio.us" onclick="window.open(\'http://del.icio.us/post?v=4&noui&jump=close&url=\'+encodeURIComponent(location.href)+\'&title=\'+encodeURIComponent(document.title), \'delicious\',\'toolbar=no,width=700,height=400\'); return false;"><img src="http://www.hmcinteractive.co.uk/gui/del_icon.png" width="16" height="16" alt="del.icio.us" /></a>&nbsp;');
	document.write('<a href="http://digg.com/submit?phase=2&url='+window.location.href+'&title='+document.title+'" title="Digg this!"><img src="http://digg.com/img/badges/16x16-digg-guy.gif" width="16" height="16" alt="Digg!" /></a>');
	document.write('</div>');
}

/* READ / WRITE / ERASE COOKIES */
function readCookie(name) {
	var ca = document.cookie.split(';');
	var nameEQ = name + "=";
	for(var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}
function writeCookie(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 eraseCookie(name) {
	createCookie(name, "", -1);
}

/* Get URL Parameter values */
function getURLParam(strParamName) {
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 ) {
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for (var iParam = 0; iParam < aQueryString.length; iParam++) {
			if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ) {
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
}

/* Open popup window */
function launchWin(winurl,winname,W,H,X,Y,S) {

	X=X||Math.ceil((screen.width-W)/2);
	Y=Y||Math.ceil((screen.height-H)/2);
	features='directories=0,fullscreen=0,location=0,menubar=0,status=1,toolbar=0,scrollbars=1';
	
	myke = window.open(winurl,winname,'width='+W+',height='+H+',screenX='+X+',screenY='+Y+',left='+X+',top='+Y+','+features);
}

/* Add rollover functionality */
function sfHover() {
	var sfEls = document.getElementById("nav").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"), "");
		}
	}
}

//Fade In
function cardHoverOn(id) {
	var element = document.getElementById(id).getElementsByTagName("a");
	var object = element[0];
	var opacity = 100;
	changeOpac(object, opacity);
	fadeOut(object.style, opacity);
}
//Fade Out
function cardHoverOff(id) {
	var element = document.getElementById(id).getElementsByTagName("a");
	var object = element[0];
	var opacity = 10;
	changeOpac(object, opacity);
	fadeIn(object.style, opacity);
}
function fadeIn(object, opacity) {
	if (opacity < 100) {
		opacity += 10;
		changeOpac(object, opacity);
		window.setTimeout(function () { fadeIn(object,opacity); }, 15);
	}
}
function fadeOut(object, opacity) {
	if (opacity > 10) {
		opacity -= 10;
		changeOpac(object, opacity);
		window.setTimeout(function () { fadeOut(object,opacity); }, 15);
	}
}
//Change object opacity
function changeOpac(object, opacity) {
	object.opacity = (opacity / 100)-.001;
	object.MozOpacity = (opacity / 100)-.001;
	object.KhtmlOpacity = (opacity / 100)-.001;
	object.filter = "alpha(opacity=" + opacity + ")";
}