﻿$(document).ready(function() {
	
	var left = $("#content .left").height()+25;
	var right = $("#content .right").height()+25;
	var cheight = $("#content").height();
	
	
	if(left>right)  $("#content .right").height(left); else  $("#content .left").height(right);
	
	$("tbody tr").hover(
		function() {
			$(this).addClass("hover");
		},
		function() {
			$(this).removeClass("hover");
		});
		
	$(".admin .mark:odd").addClass("odd");
	
	$("a.tip").click(function() {
		var id= $(this).attr("rel");
		$("a.active").removeClass("active");
		$(".tips:visible").removeClass("show");
		$(this).addClass("active");
		$("#"+id).addClass("show");
		return false;
	});	
	
	var path = location.pathname;
	$('#top ul.menu a[@href$="' + path + '"]').addClass('active');
	
	$("#formularz").submit( function() {
		var errors = [];
		
		if($("#imie").val() == "") {
			errors.push("Pole 'Imię' jest obowiązkowe. \n\n");
		}
		
		if($("#nazwisko").val() == "") {
			errors.push("Pole 'Nazwisko' jest obowiązkowe. \n\n");
		}
		
		if($("#wyn").val() != "5") {
			errors.push("Proszę wpisać poprawny wynik działania zabezpieczającego przed spamerami. \n\n");
		}
		
		if(!$("#email").val().match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)) {
			errors.push("Format podanego adresu e-mail jest niepoprawny. \n");
		}
		
		var len = errors.length;
		if (len>0) {
			var tekst = "";
			for (var i=0; i < len; i++) {
				tekst += errors[i];
			}
			alert (tekst);
			return false;
		}
	});
	
	$("#desc").change( function() {
		if($("#desc").val() == "1") {
			$("#opis").val("Kurs homiletyczny - całkowity koszt (800 zł)");
			$("#kwota").val("800");
		}
		
		if($("#desc").val() == "2") {
			$("#opis").val("Kurs homiletyczny - przedpłata (160 zł)");
			$("#kwota").val("160");
		}
		
		if($("#desc").val() == "3") {
			$("#opis").val("Kurs homiletyczny - pozostała należność (640 zł)");
			$("#kwota").val("640");
		}
	});
	
	var li_number = $('ul.gallery').children().length;
	$("ul.gallery").css("width", li_number*520);
	var click = 0;
	$('.last_item').click(function() {
		if ( click < (li_number/2)-1 ) {
			click++;
  			$(".last_item").removeClass("none");
	   		$("ul.gallery").animate({ marginLeft: "-=620" }, 400);	
	  	} else { 
	   		$(this).addClass("none");
	  	 }
	    return false;
  	});
  	
  	$('.first_item').click(function() {
  		if ( click > 0 ) {
  			click--;
  			$(".first_item").removeClass("none");
    		$("ul.gallery").animate({ marginLeft: "+=620" }, 400);
    	} else { 
	   		$(this).addClass("none"); 
	   	}
	    return false;
  	});
  	
  	$("#find_field").focus(function() {
  		$(this).val("");
  	});
	
});


