function nextproject(){
  var $active = $('#new-projects .active');
  var $next = ($('#new-projects .active').next().length > 0) ? $('#new-projects .active').next() : $('#new-projects li:first');
  $active.fadeOut(function(){
    $active.removeClass('active');
    $next.fadeIn().addClass('active');
  });
}

function prevproject(){
  var $active = $('#new-projects .active');
  var $prev = ($('#new-projects .active').prev().length > 0) ? $('#new-projects .active').prev() : $('#new-projects li:last');
  $active.fadeOut(function(){
    $active.removeClass('active');
    $prev.fadeIn().addClass('active');
  });
}

/*
	Przesyłanie wiadomości kontaktowej
*/

$(function() {
	$("#contact-button").click(function() {
		var topic = $("#msg-topic").val();
		if (topic == "")
		{
			alert ("Nie podano tytułu wiadomości");
			$("#msg-topic").focus();
			return false;
		}

		var name = $("#msg-name").val();
		if (name == "")
		{
			alert ("Nie podano imienia i/lub nazwiska");
			$("#msg-name").focus();
			return false;
		}

		var phone = $("#msg-phone").val();
		var email = $("#msg-email").val();
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

		if ((email == "") || (reg.test (email) == false))
		{
			alert ("Nie podano zwrotnego adresu e-mail lub podany adres nie jest poprawny");
			$("#msg-email").focus();
			return false;
		}

		var content = $("#msg-content").val();
		if (content == "")
		{
			alert ("Nie podano treści wiadomości");
			$("#msg-content").focus();
			return false;
		}

		var datastring = 	'op=send&topic=' + topic + '&name=' + name + '&phone=' + phone + '&email=' + email + '&content=' + content;

		$.ajax({  
			type: "POST",  
			url: "/php/mail.php",  
			data: datastring,
			beforeSend: function() {
				$('#contact-form').html('<div class="centered"><br /><br /><br />Wysyłanie...</div>');
			},
			success: function(msg) {  
				$('#contact-form').html(msg).hide().fadeIn(500);
			}
		});

		return false;
	});
});


$(document).ready(function()
{
	$('.fade').append('<span class="hover"></span>').each(function () {
		var $span = $('> span.hover', this).css('opacity', 0);
		$(this).hover(function () {
			$span.stop().fadeTo("fast", 1);
		}, function () {
			$span.stop().fadeTo("slow", 0);
		});
	});

	// Lightbox

	$('a.lightbox').lightBox(); // Select all links with lightbox class

	setInterval('nextproject()', 10000);
});
