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('value', $(this).val())
			.bind("focus", function(){
				console.log($(this).val() + ":" + $(this).data('value'))
				if($(this).val() === $(this).data('value')) {
					$(this).val("");
					
				}
			})
			.bind("blur", function(){
				if($(this).val() === "") {
					$(this).val($(this).data('value'));
				}
			});
	});
}

$(function(){
	// init prettyPhoto
	//$(".photo-box .photo-holder a").prettyPhoto();
	$('input[type="text"], input[type="password"], textarea').hideInputText();
	
	// init fancybox
	$("a.btn-download-now").fancybox({
		'speedIn'		 : 600, 
		'speedOut'		 : 200, 
		'overlayShow'	 : true,
		'showCloseButton': true
	});
	$("a.please-register").fancybox({
		'speedIn'		 : 600, 
		'speedOut'		 : 200, 
		'overlayShow'	 : true,
		'showCloseButton': true
	});
	
	// validation
	var validator = $("#form-contact, #form-reserve").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") {
								status
									.html("Thank you!<br /> We will get back to you as soon as possible.")
									//.show()
									.removeClass("error");
								$form.find("fieldset").fadeOut(400);
							} 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('value'); 
	}, "Please enter something!");
	// init hidden text
	
});

