$(document).ready(function($) {
	$('#tabs > ul').tabs({ fx: { opacity: 'show' } });

	$('#navigation li > ul').hover( function () {
		$(this).parents('#navigation > ul > li').addClass('current_page_item'); 
	}, function () {
		$(this).parents('#navigation > ul > li').removeClass('current_page_item');
	});
	
	$('#page_subnav li:last-child').addClass('last');
	
	$('#commentform input, #commentform textarea').each(function () {
		if ($(this).val() == '') {
			$(this).val($(this).attr('defaultvalue'));
		}
	}).focus(function () {
		$(this).removeClass('inputerror');
		if ($(this).val() == $(this).attr('defaultvalue')) {
			$(this).val('');
		}
	}).blur(function () {
		if ($(this).val() == '') {
			$(this).val($(this).attr('defaultvalue'));
		}
	});
	$('#commentform').submit(function () {
		$('#submiterror').remove();
		var errors = 0;
		$(this).find('textarea, input').each(function () {
			if ($(this).val() == $(this).attr('defaultvalue')) {
				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('defaultvalue'));
				}
			});
			$(this).prepend('<div id="submiterror">Please complete the highlighted fields.</div>');
			return false;
		}
		return true;
	});
	
});
