$(document).ready(function() {

	$('#homePhoto, #headerPhoto').cycle({ 
		pager:  '#nav',
		slideExpr: 'img',
		speed:  2500,
		timeout: 9000
	
	});
	
	$('#b2, #page_b1').cycle({ 
		fx: 'scrollDown',
		slideExpr: 'img',
		speed:  400,
		timeout: 7000
	
	});
	
	$('#page_b2').cycle({ 
		fx: 'zoom',
		slideExpr: 'img',
		speed:  400,
		timeout: 9000
	
	});
	
	$('a.colorbox').colorbox({rel:'gallery', scalePhotos: true, maxWidth: '100%', maxHeight: '100%'});

	$('input[type="submit"]').click(function() {
		this.blur();
	});

	//Formularz kontaktowy
	$("form #contact_form_button").click(function(){

	$('#notice').fadeIn("normal").html('<div class="wait">Trwa wysyłanie...</div>');
	var parametry = $("form").serialize();
	
		$.ajax({
			type: "POST",
			url: "/classes/contact-process.php",
			data: parametry,
			cache: false,			
			success: function(html) {
				if (html == 'success')
				{
					$('#notice').fadeIn("normal").html('<div class="success">Dziękujemy! Twoja wiadomość została wysłana.</div>');
					$('#contact_form_name, #contact_form_phone, #contact_form_email, #contact_form_message').val("");
				}
				else if (html == 'error_mail')
				{
					$('#notice').fadeIn("normal").html('<div class="error">Podany adres e-mail jest niepoprawny!</div>');
				}					
				else if (html == 'error_send')
				{
					$('#notice').fadeIn("normal").html('<div class="error">Wystąpił nieoczekiwany błąd! Napisz na hotel@pod-lipami.com.pl</div>');
				}				
				else
					$('#notice').fadeIn("normal").html('<div class="error">Wypełnij wszystkie wymagane pola!</div>');
			}
		});
		
		return false; 
	});

	//Formularz rezerwacji
	$("form #reservation_form_button").click(function(){

	$('#notice').fadeIn("normal").html('<div class="wait">Trwa wysyłanie...</div>');
	var parametry = $("form").serialize();
	
		$.ajax({
			type: "POST",
			url: "/classes/reservation-process.php",
			data: parametry,
			cache: false,			
			success: function(html) {
				if (html == 'success')
				{
					$('#notice').fadeIn("normal").html('<div class="success">Dziękujemy! Twoja wiadomość została wysłana.</div>');
					$('#reservation_form_name, #reservation_form_company, #reservation_form_date_from, #reservation_form_date_to, #reservation_form_room_type, #reservation_form_room_count, #reservation_form_phone, #reservation_form_fax, #reservation_form_email, #reservation_form_message').val("");
					$('input').attr('checked', false);
				}
				else if (html == 'error_mail')
				{
					$('#notice').fadeIn("normal").html('<div class="error">Podany adres e-mail jest niepoprawny!</div>');
				}					
				else if (html == 'error_send')
				{
					$('#notice').fadeIn("normal").html('<div class="error">Wystąpił nieoczekiwany błąd! Napisz na hotel@pod-lipami.com.pl</div>');
				}				
				else
					$('#notice').fadeIn("normal").html('<div class="error">Wypełnij wszystkie wymagane pola oznaczone gwiazdką!</div>');
			}
		});
		
		return false; 
	});	

	//Newsletter
	$("form #emailSubmit").click(function(){

	$('#notice_newsletter').fadeIn("normal").html('<div class="wait">Trwa wysyłanie...</div>');
	var parametry = $("form").serialize();
	
		$.ajax({
			type: "POST",
			url: "/classes/newsletter-process.php",
			data: parametry,
			cache: false,			
			success: function(html) {
				if (html == 'success')
				{
					$('#notice_newsletter').fadeIn("normal").html('<div class="success">Dziękujemy! Twój adres został zapisany.</div>');
					$('#emailAddress').val("");
				}
				else if (html == 'error_mail')
				{
					$('#notice_newsletter').fadeIn("normal").html('<div class="error">Podany adres e-mail jest niepoprawny!</div>');
				}					
				else if (html == 'error_exist')
				{
					$('#notice_newsletter').fadeIn("normal").html('<div class="error">Podany adres znajduje się już w naszej bazie!</div>');
				}				
				else
					$('#notice_newsletter').fadeIn("normal").html('<div class="error">Wprowadź swój adres e-mail!</div>');
			}
		});
		
		return false; 
	});		

});
