$(document).ready(function() {
	
	//External links 
	$(function() {
		$('a[rel=external]').attr('target', 'blank');
	});
	
	// Comments Form
	$('#commentform input, #commentform textarea').each(function () {
		if ($(this).val() == '') {
			$(this).val($(this).attr('title'));
		}
	}).focus(function () {
		$(this).removeClass('inputerror');
		if ($(this).val() == $(this).attr('title')) {
			$(this).val('');
		}
	}).blur(function () {
		if ($(this).val() == '') {
			$(this).val($(this).attr('title'));
		}
	});
	$('#commentform').submit(function () {
		$('#submiterror').remove();
		var errors = 0;
		$(this).find('textarea, input').each(function () {
			if ($(this).val() == $(this).attr('title')) {
				if ($(this).attr('name') != 'comment_post_ID') {
					$(this).val('');
				}
			}
			if ($(this).hasClass('required') && $(this).val() == '') {
				$(this).addClass('inputerror');
				errors++;
			}
		});

		if (errors > 0) {
			$(this).find('textarea, input').each(function () {
				if ($(this).val() == '') {
					$(this).val($(this).attr('title'));
				}
			});
			$(this).prepend('<p id="submiterror">Please complete the highlighted fields.</p>');
			return false;
		}
		return true;
	});
	
	// Toggle Navigation
	$(".side_nav > li > a").click(function(){
		if ($(this).next("ul").is(":hidden")) {
			$(this).next("ul").slideDown("fast");
			$(this).removeClass("closed");
			$(this).addClass("open");
			return false;
		} else {
			$(this).next("ul").slideUp("fast");
			$(this).removeClass("open");
			$(this).addClass("closed");
			return false;
		}
	});
	
	// Toggle Navigation
	$(".side_nav li.child > a").click(function(){
		if ($(this).next("ul").is(":hidden")) {
			$(this).next("ul").slideDown("fast");
			$(this).removeClass("closed");
			$(this).addClass("open");
			return false;
		} else {
			$(this).next("ul").slideUp("fast");
			$(this).removeClass("open");
			$(this).addClass("closed");
			return false;
		}
	});
		
});
