// Script written by Drew Noakes -- http://drewnoakes.com
// from: http://www.drewnoakes.com/code/javascript/xhtmlExternalLinks.html

function initLinks() {
	for (i in document.links) {
		link = document.links[i];
		if (link.rel && link.rel.indexOf('external')!=-1) {
			link.onclick = onExternalLinkActivate;
			link.onkeypress = onExternalLinkActivate;
		}
	}
}

function onExternalLinkActivate() {
	window.open(this.href);
	return false;
}

window.onload = initLinks;

$(document).ready( function() {
	$('a.external').click( onExternalLinkActivate );
	$('a.external').keypress( onExternalLinkActivate );
	
	runBackgroundHack();
});

/**
 * This is a REALLY ugly hack
 * 
 * the background image & color is toggled based on the normal 'blue' site
 * or the casc 'green' site. When toggling to casc the background color is not
 * set on the body cause it's not tagged with casc.
 * 
 * The way the css works the div#body will not render the background down past the fold
 * if the page scrolls, so we use this to apply the background color to the main body element
 *
 * @return void
 */
function runBackgroundHack() {
	if( $('div#body').hasClass('casc') ) {
		var bgColor = $('div#body').css('background-color');
		$('body').css('background-color', bgColor);
	}
}