$(document).ready(function() {
	$('form#contact input, form#contact textarea').each(function () {
		if ($(this).val() == '') {
			$(this).val($(this).attr('title'));
		}
	}).focus(function () {
		//$(this).removeClass('error');
		if ($(this).val() == $(this).attr('title')) {
			$(this).val('');
		}
	}).blur(function () {
		if ($(this).val() == '') {
			$(this).val($(this).attr('title'));
		}
	});
	$('form#contact').submit(function () {
		$('.form-error').remove();
		var errors = 0;
		$(this).find('textarea, input').each(function () {
			if ($(this).val() == $(this).attr('title')) {
				$(this).val('');
			}
			if ($(this).hasClass('required') && $(this).val() == '') {
				$(this).addClass('error');
				errors++;
			}
			else {
				$(this).removeClass('error');
			}
		});

		if (errors > 0) {
			$(this).find('textarea, input').each(function () {
				if ($(this).val() == '') {
					$(this).val($(this).attr('title'));
				}
			});
			$(this).prepend('<div class="form-error">Please complete the highlighted fields.</div>');
			return false;
		}
		return true;
	});
});
