jQuery(function($) {
	$.validator.addMethod("defaultInvalid", function(value, element) {
		switch (element.value) {
			case "Name":
				return false;
			case "Message":
				return false;
		}
		return true;
	}, "Required");
	
	$("#mailing-list-email").toggleVal({
		populateFrom: "label"
	});
	$("#search-field").toggleVal({
		populateFrom: "label"
	});
	$("#mailing-list-form").validate();
	
	$("#contact-form").find("input[type=text], textarea").each(function() {
		$("#" + $(this).attr("id")).toggleVal({
			populateFrom: "label"
		});
	});
	
	$("#contact-form").validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit({
				beforeSerialize: function() {
					showLoader();
				},
				success: function(data) {
					$("#contact-form").hide('slow').after(data);
				},
				url: '/includes/contact-form.php'
			});
			return false;
		},
		rules: {
			sender_name: { defaultInvalid: true },
			message: { defaultInvalid: true }
		}
	});
});
