// http://jquery-howto.blogspot.com/2009/06/find-select-all-external-links-with.html
$.expr[':'].external = function(obj){
    return !obj.href.match(/^mailto:/)
            && (obj.hostname != location.hostname);
};

// http://www.java-scripts.net/javascripts/EMail-Address-Verification.phtml
function checkemail(str){
	var result;
	var filter=/^.+@.+..{2,3}$/;
	if (filter.test(str)) {
   		result=false
	} else {
		result=true
	}
	return (result)
}

$(document).ready(function(){
	if ( $("#message").length > 0 ) { $("#message").animate({opacity: 1.0}, 3000).fadeOut(); };
	$(".textinput:visible:enabled:first").focus();
	$("a.fancybox").fancybox();
	$(".moreinfo a").click(function () {
		$(this).hide();
		$(this).parent().find("span").show();
		return false;
	});
	$('.container a:external').addClass('external');
	$(".nav a").each(function(){
		if (window.location.href.indexOf($(this).attr("href")) !== -1) {
			$(this).addClass("current");
			$(this).siblings().removeClass("current");
		}
	})
	$(":text:visible:enabled:first").focus();
	$("#contact_form").submit(function(){
		$(".ohno").fadeOut();
		var valid = 1;
		$("#contact_form .textinput").each(function (i) {
			if ($(this).val() == "") {
				$("#ohno_required_"+$(this).attr("name")).fadeIn();
				valid = 0;
			};
		});
		if (checkemail($("#e").val()) && $("#e").val() !== "") {
			$("#ohno_email").fadeIn();
			valid = 0;
		};
		if ($("#c").val() !== "9" && $("#c").val() !== "") {
			$("#ohno_captcha").fadeIn();
			valid = 0;
		}
		if (valid == 1) {
			return true;
		} else {
			return false;
		}
	});

});