$(document).ready(function(){

	//Email address obfuscation
	$("a.email").each(function(){
		e = this.rel.replace("/","@");
		this.href = "mailto:"+e;
		$(this).text(e);
	});

	//Open link in new window
	$("a.external").click(function(){
		window.open(this.href);
		return false;
	});
	
	
	$('.subwin').each(function() {
		var $this 	=$(this),
			href  	=$this.attr('href');
			$this.attr('href', '#');
		$this.click(function() {
			var win =window.open(href, 'missionwin', 'width=768,height=900,location=0,status=0,menubar=0,scrollbars=1,resizable=0');
			win.focus();
		});
		
	
	});
	

	//Image rollovers
	$(".rollover").hover(
		function(){
			if($(this).attr("src").indexOf("-over")==-1) {
				var newSrc = $(this).attr("src").replace(".gif","-over.gif");
				newSrc = newSrc.replace(".jpg","-over.jpg");
				newSrc = newSrc.replace(".png","-over.png");
				$(this).attr("src",newSrc);
			}
		},
		function(){
			if($(this).attr("src").indexOf("-over")!=-1) {
				var oldSrc = $(this).attr("src").replace("-over.gif",".gif");
				oldSrc = oldSrc.replace("-over.jpg",".jpg");
				oldSrc = oldSrc.replace("-over.png",".png");
				$(this).attr("src",oldSrc);
			}
		}
	);
	
	//Define default text for each text field
	$(".input-text").each (function() {
		this.rel=this.value;
	});

	$(".input-text").focus(function() {
		if (this.value==this.rel) {
			this.value='';
		}
	});

	$(".input-text").blur(function() {
		if (this.value=='') {
			this.value=this.rel;
		}
	});
	
	//Table zebra striping
	$("#bodycontent #content-wrapper table tr:even").addClass("alt");
	
	//Landing page rollovers
	$("#landing .panel").hover(
		function(){
			$("span",this).fadeIn();
			$("h3",this).addClass("over");
		},
		function(){
			$("span",this).fadeOut();
			$("h3",this).removeClass();
		}
	);

});

function switchBackground($colour) {
	$("body").css("background-color",$colour);
	if($colour=='white') {
		$('#footer span a').css({'color': '#333'});
	}
	else {
		$('#footer span a').css({'color': '#999'});
	} 
}
