$(document).ready(function () {
	$('#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')) {
				$(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;
	});
});

$(document).ready(function() {
	$("#tabs").tabs({ fx: { opacity: 'toggle', speed: 'fast' } });
	$("#tabs2").tabs({ fx: { opacity: 'toggle', speed: 'fast' } });
});

$(document).ready(function() {
		$("div.features").addClass("includeme");
		$('.features > ul').tabs({ fx: { opacity: 'toggle' }, event: 'click' }).tabs('rotate', 5000);
		$('.features > ul li').addClass("show")
});

function initMenus() {
	$('ul.menu div.ele').hide();
	
	$.each($('ul.menu'), function(){
		$('#' + this.id + '.expandfirst div:first').show();
	});
	$('ul.menu li a').click(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;
			
			
			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('fast');
				return false;
			}
			if((checkElement.is('div.ele')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' div.ele:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('div.ele')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' div.ele:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}
$(document).ready(function() {initMenus();});
