$(document).ready(function(){

	$("a[rel=galeria]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">Zdjęcie ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
		$("a[rel=galeria-tytul]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'onComplete'	:	function() {
			$("#fancybox-wrap").hover(function() {
				$("#fancybox-title").show();
			}, function() {
				$("#fancybox-title").hide();
			});
		},

		'titleShow'				:	'true',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">' + (title && title.length ? '<b>' + title + '</b>' : '' ) + 'Zdjęcie ' + (currentIndex + 1) + ' z ' + currentArray.length + '</span>';
		
		}
	});

	
	$(".submit").click(function() {
		
		
		var fname = $("input#fname").val();
		if (fname == "") {
      $("span#fname_error").show();
      $("input#fname").focus();
      return false;
    }
		else {
			$("span#fname_error").hide();
		}
		
		var ftext = $("textarea#ftext").val();
		if (ftext == "") {
      $("span#ftext_error").show();
      $("input#ftext").focus();
      return false;
    }
		else {
			$("span#ftext_error").hide();
		}
		
		var dataString = $("#contact_form form").serialize();
		
		$('#contact_form').html("<div id='messagesend'><img id='checkmark' src='images/ajax-loader.gif' alt='Postęp' /><br /><p>Trwa wysyłanie.</p></div>");
				
		$('#messagesend')
			.fadeIn(1500, function() {
				$('#messagesend');
		});
		
		$.ajax({
      type: "POST",
      url: "_wyslij.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Wiadomość została wysłana.</h2>")
        .append("<p>Wkrótce otrzymasz odpowiedz.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message');
			 });
      }
     });
		 
    return false;
	});
		
});
