$(function() {

	$("#first :input").live("change", function() {

		var dane = $("#first :input").serialize();

		$.ajax({
			type : "POST",
			url : "/policz.php",
			data : dane,
			success : function(suma) {
				$("#suma").html(suma + " zł");
			},
			error: function(msg) {
				alert(msg);
			}
		});
	});

	$("#add").live('click', function(){
		var tmp = $("#first .slct:first").clone();
		tmp.children().children('label').remove();
		tmp.children().children('input[type=text]').val('');
		$('<a href="#" class="del"></a>').appendTo(tmp);
		tmp.appendTo($("#first .selectroom"));
		
		var n = $("#first .slct").length;
		if (n > 3) {
			$('#add').fadeOut();
		}
		
	});
	
	$(".del").live('click', function (){
		$(this).parent().remove();
		
		var n = $("#first .slct").length;
		if (n < 4) {
			$('#add').fadeIn();
		}
	});
	
	$("#pokoje_strony, #konferencje_strony, #integracyjne_strony, #swietujemy_strony, #atrakcje_strony, #wesela_strony, #komunie_strony, #mlodziez_strony, #sale_strony, #rodzina_strony, #smaki_strony").wslide({
		width : 280,
		height : 360,
		duration : 500,
		pos : 1,
		horiz : true
	});
	$(".wslide-menu a").click(function() {
		$(".wslide-menu a").not(this).removeClass("selected");
		$(this).addClass("selected");
	});
	$(".wslide-menu a:first").click();

	//$("#od, #do").datepicker($.datepicker.regional['pl']);
	
	$("#od, #do").datepicker({minDate: 0 });
	
	
	$('#dane input[type="text"]').focus(function() {
		
		if (this.value == this.defaultValue){ 
			this.value = '';
			$(this).addClass('darker');
		}
		if(this.value != this.defaultValue){
			this.select();
			
		}
	});
	$('#dane input[type="text"]').blur(function() {
		
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
			$(this).removeClass('darker');
		}
	});
	$('#dane textarea').focus(function() {
		
		if (this.value == this.defaultValue){ 
			this.value = '';
			$(this).addClass('darker');
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('#dane textarea').blur(function() {
		
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
			$(this).removeClass('darker');
		}
	});
	
	$.validator.methods.NotEqual = function(value, element, param) {
   		return value != param;
	};
	
	$("#form").validate({
		rules: {
			imie: {
		    	NotEqual: "Imię *"
		   	},
		   	nazwisko: {
		   		NotEqual: "Nazwisko *"
		   	},
		   	telefon: {
		   		required: true,
      			digits: true,
      			NotEqual: "Telefon *"
		   	},
		   	email: {
		   		required: true,
		   		email: true
		   	}
		},
		messages: {
			imie: "To pole jest wymagane",
			nazwisko: "To pole jest wymagane",
			telefon: "Tylko cyfry np: 221234567",
			email: "Wprowadź poprawny adres e-mail"
		}
	});
	
});

$(window).load(function() {
    $('#slider').nivoSlider({
			pauseTime:10000,
			directionNav: false
		});
});

