$(document).ready(function() {
	$("#searchsubmit").click(function() {
		$("#searchform").get(0).submit();
	});
	
	watermark("input[name=your-name]", "Name", "#93c7bb", "#93c7bb");
	watermark("textarea[name=your-message]", "Comments", "#93c7bb", "#93c7bb");
	watermark("input[name=email]", "Email", "#93c7bb", "#93c7bb");
	
	$(".contact-form .input-submit img").click(function(e) {

		var name = $("input[name=your-name]").val();
		var message = $("textarea[name=your-message]").val();
		var email = $("input[name=email]").val();
	
		if(name == "Name") name = "";
		if(message == "Comments") message = "";
		if(email == "Email") email = "";
	
		var errors = "";
		if(name == "") errors += "Please enter your name.\n";
		if(email == "") errors += "Please enter your email.\n";
	
		if(errors != "") {
			alert("The form could not be submitted.\nPlease correct the following errors below before continuing:\n\n" + errors);
			e.preventDefault();
			e.stopPropagation();
			return false;
		} else {
			$("textarea[name=your-message]").val(message);
			$(this).parents("form").get(0).submit();
		}
	});
		
	
	set_menus();
});

function watermark(id, watermarkText, watermarkColor, activeColor) {
	$(id).val(watermarkText).css('color', watermarkColor).focus( function() {
		if($(this).val() == watermarkText) {
			$(this).val('');
			$(this).css('color', activeColor);
		}
	}).blur( function() {
		if(!$(this).val()) {
			$(this).val(watermarkText).css('color', watermarkColor);
		}
	});
}
function set_menus() {
	// Define menu movements
	$("#nav-widgets li > div").each(function() {
		if($(this).find("ul").length > 0) {
			$(this).hover(function() {
				// mouse over
				var div_height = $(this).find("> div").outerHeight();
				var sub_menu_height = $(this).find("> ul").outerHeight();
				var new_height = div_height + sub_menu_height + 5;
				
				$(this).stop().animate({ height: new_height + 'px', bottom: new_height },250, "swing");
				
			}, function() {
				$(this).stop().animate({ height: '0px', bottom: '0px' },250, "swing");
				
			});
		}
	});
}
