$(document).ready(function() {
	
		$('.fbbox').hover(function(){
			$('.fbbox').stop(true, false).animate({right:'0'},'medium');
		},function(){
			$('.fbbox').stop(true, false).animate({right:'-185'},'medium');
		},500);
	



	$("ul#menu_top a.parent").hover(function(){
		$(this).addClass("jqhover");
		$(this).parent().find("ul.subnav").slideDown(80).show();
		$(this).parent().hover(
			function(){},
			function(){
				$(this).parent().find("ul.subnav").slideUp(80);
				$(this).parent().find("a.parent").removeClass("jqhover");
			}
		);
	},function(){
		//$(this).removeClass("selected");
	});
	
	
	
	
	$("#cform #submit").click(cform);
	
	$("#cform input").keypress(function(event) {
		if (event.keyCode == '13') {
			event.preventDefault();
			$(this).blur();
			cform();
		}
	});
	
	function cform() {
		$.ajax({
			type: "POST",
			url: "e.php",
			data:
				"action=" + $("input[name='action']").attr('value') +
				"&email=" + $("input[name='email']").attr('value') +
				"&imie=" + $("input[name='imie']").attr('value') +
				"&nazwisko=" + $("input[name='nazwisko']").attr('value') +
				"&wiadomosc=" + $("textarea[name='wiadomosc']").attr('value'),
			beforeSend: function(){},
			error: function(){},
			success: function(response){
				if (response == "success") {
					alert('Wiadomość została wysłana. Dziękujemy!');
					$("#cform ul input").attr('value', '');
					$("#cform ul textarea").val('');
				} else if (response == "bad_data") {
					alert('Nie wypełniono adresu e-mail i treści lub podany adres e-mail jest nieprawidłowy. Prosimy o poprawienie formularza.');
				} else {
					alert('Wystąpił błąd serwera poczty podczas wysyłania wiadomości, prosimy spróbować ponownie za jakiś czas. Przepraszamy za nieudogodnienia.');
				}
			},
			complete: function(){}
		});
	}
});
