$(document).ready(function(){
	$("div#menu ul li").hover(
		function(){
			$(this).addClass("active");
	
		}, function(){
			$(this).removeClass("active");
	});
	
	$(".realizacje_galeria .next").hover(
		function() { $(this).css("cursor", "pointer"); },
		function() { $(this).css("cursor", "auto"); }
	);
	
	$(".realizacje_galeria .prev").hover(
		function() { $(this).css("cursor", "pointer"); },
		function() { $(this).css("cursor", "auto"); }
	);
	
	$(".realizacje_galeria_zdjecia").jCarouselLite({
	    btnNext: ".realizacje_galeria .next",
	    btnPrev: ".realizacje_galeria .prev",
	    circular: false,
	    mouseWheel: true,
	    speed: 500,
	    afterEnd : function(elements) { 
			if ($(elements[2]).attr("id") == $(".realizacje_galeria_zdjecia li:last").attr("id")) {
				$(".realizacje_galeria .next img").css("display","none");
			} else {
				$(".realizacje_galeria .next img").css("display","block");
			}
			if (elements[0].className == "first") {
				$(".realizacje_galeria .prev img").css("display","none");
			} else {
				$(".realizacje_galeria .prev img").css("display","block");
			}
		}
	});

	$("#contactForm input#send").bind("click", function(){
		$("#contactForm").submit();
	});
	
	if ($("#contactForm").length > 0)
		$("#contactForm").ajaxSubmit();
	
	$("#lightbox_photos a").lightbox();
	
	$("#lightbox-imageBox").corner();
	
	setTimeout("bannerRotator();", 10000);
});

function bannerRotator() {
	var current = $(".banner:visible");
	var next = $(".banner:visible").next();
	
	if (!$(next).hasClass("banner")) {
		next = $("#top-banners .banner").get(0);
	}
	
	$(current).effect("drop", { direction: "down" }, 1000);
	$(next).effect("slide", { direction: "up" }, 1000, function() {  });
	
	setTimeout("bannerRotator();", 10000);
}

$.fn.ajaxSubmit = function(e) 
{
	this.submit(function()
	{
		var params = {};
		$(this).find("input:checked, input[type=text], input[type=hidden], input[type=password], input[type=submit], option:selected, textarea").filter(":enabled").each(function() 
		{
			params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
		});
		
		params["ajax"] = true;
		$("body").addClass("curWait"); 
		
		$.post(this.getAttribute("action") + "", params, function(xml)
		{
			$("body").removeClass("curWait");
			strError = null;
			oFocus = null;
			
			$("AjaxResponse", xml).each(function() 
			{
				strError = this.getAttribute("error");
				oFocus = this.getAttribute("focus");
			}); 
			
			if (strError.length == 0) 
			{
				$("form").html("<div style='background: #BBFFAF; border: 1px solid #47BF0B; color: #47BF0B; margin: 20px; padding: 10px; font-weight: bold; font-size: 1.2em; text-align: center;'>Zapytanie zostało poprawnie wysłane.</div><p>Dziękujemy za zainteresowanie naszą ofertą i wypełnienie formularza kontaktowego. Państwa zgłoszenie zostało wysłane do nas, odpowiedź zostanie wysłana na adres e-mail podany w formularzu.</p><p dlass='right'>Pozdrawiamy serdecznie,<br />zespół syso.pl</p>");
				$("div#formErrors").removeClass("formErrors");
				$("div#formErrors").addClass("formInfo");
				$("div#formErrors").css("display", "none");
			}
			else
			{
				$("div#formErrors").removeClass("formInfo");
				$("div#formErrors").addClass("formErrors");
				$("div#formErrors").html("<div class='header'>Błędy w formularzu<\/div><ul>" + strError + "<\/ul>").filter(":hidden").fadeIn("normal");
				
				if (oFocus)
				{
					$("#" + oFocus).get(0).focus(); 
				}
			}
		}); 
		
		return false; 
	});
	
	return this; 
}
