jQuery.fn.focusInput = function(options){
	var _options = $.extend({
		inputHolder: "",
		activeClass: "active"
	}, options);
	
	return $(this).each(function() {

		var inputHolder = $(this).parents(_options.inputHolder);
		$(this)
			.bind("focus", function(){
				inputHolder.addClass(_options.activeClass);
			})
			.bind("blur", function(){
				inputHolder.removeClass(_options.activeClass);
			});
	});
}
jQuery.fn.hideInputText = function(){
	return $(this).each(function() {
		$(this).data('uservalue', $(this).val());
		$(this)
			.bind("focus", function(){
				if($(this).val() === $(this).data('uservalue')) {
					$(this).val("");
				}
			})
			.bind("blur", function(){
				if($(this).val() === "") {
					$(this).val($(this).data('uservalue'));
				}
			});
	});
}

$(function(){
	$('input[type="text"], input[type="password"], textarea').hideInputText();
	// validation
	var validator = $("#form-contact").each(function(e, elem){
		$(elem)
			.submit(function(e){
				var $form = $(this);
				e.preventDefault();
				if($(this).valid())
					$.post(
						'mail.php?' + $(this).serialize(),
						function(data){
							var status = $form.find(".status-message");
							status.show();
							if(data === "true") {
								$form.find("fieldset").hide();
								status
									.html("Thank you!<br /> We will get back to you as soon as possible.")
									//.show()
									.removeClass("error");
							} else {
								status
									.html("Sorry, some error occured!")
									.addClass("error");
							}
						}
					);
			})
			.validate({
				errorPlacement: function(error, element) {
					error.appendTo( element.parent() );
				}
			});
	})
	// add default values handling	
	$.validator.addMethod("default", function(value, element) {
		return value != $(element).data('uservalue'); 
	}, "Please enter something!");
});

