$(document).ready(function(){

	$("a.email").each(function(){ //Email address obfuscation
		e = this.rel.replace("/","@");
		this.href = "mailto:"+e;
		$(this).text(e);
	});

	$("a.external").click(function(){ //Open link in new window
		window.open(this.href);
		return false;
	});

	$(".rollover").hover( //Image rollovers
		function(){
			if($(this).attr("src").indexOf("-over")==-1) {
				var newSrc = $(this).attr("src").replace(".gif","-over.gif");
				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.png",".png");
				$(this).attr("src",oldSrc);
			}
		}
	);
	
	$("input.input-text").each ( //Define default text for each input element
		function() {
			this.rel=this.value;
		}
	);

	$("input.input-text").focus(function() {
		if (this.value==this.rel) {
			this.value='';
		}
	});

	$("input.input-text").blur(function() {
		if (this.value=='') {
			this.value=this.rel;
		}
	});
	
	$("#details_form").submit(
		function() {
			var error=false;
			var response="There was an error submitting your details:\n";
			
			if (!isString($("#name",this).val()) || $("#name",this).val()=="Enter your name") {
				error=true;
				response+="Please enter your name\n";
			}

			if (!isString($("#phone",this).val()) || $("#phone",this).val()=="Enter your phone number") {
				error=true;
				response+="Please enter your phone number";
			}

			if (error) {
				alert(response);
				return false;
			}
		}
	);
});

//Data type validation
function isString(str) {
	if (str.length!="") {
		return true;
	} else {
		return false;
	}
};
