// always remove outlines
$("a").each(function(){
	this.onmouseup = this.blur();
});
$(document).ready(function() {
	// validate the comment form when it is submitted
	$("#contactform").validate({
		messages: {
			from_url: "Please enter a valid URL beginning with http://",
			from_email: "Your email address must be in the format of name@domain.com"
		}
	});

	// prevent double-clicking form submit
	$("form").submit(
	  function() {
		$("input.submit").attr("disabled","true");
	  }
	);

	// all external links in a new window
	var h = window.location.host.toLowerCase();
	$("a[href^='http']:not(.external-image):not(.sociable):not([href^='http://" + h + "']):not([href^='http://www." + h + "']):not([href^='https://" + h + "']):not([href^='https://www." + h + "']):not([href^='mailto']), a[href$='.pdf']").attr("target", "_blank").append(' &raquo;');

	// text labels
	$('input#s[title]').each(function() {
		if($(this).val() === '') {
			$(this).val($(this).attr('title'));
		}

		$(this).focus(function() {
			if($(this).val() == $(this).attr('title')) {
				$(this).val('').addClass('focused');
			}
		});
		$(this).blur(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('title')).removeClass('focused');
			}
		});
	});

	// new window on click for external links, with title tag
	$('a.external-title')
		.attr({
		target: "_blank",
		title: "Open In A New Window"
	}).append(' &raquo;');

	// new window for images
	$('a.external-image')
		.attr({
		target: "_blank"
	});
});
