$(document).ready(function() {

	/*
		klikniecie w belke panelu powoduje zaznaczenie/odznaczenie opcji
		dodatkowo utrzymuje aktualna tablice 'filter' z wybranymi opcjami
	*/

	var filter;
	var url = String(window.location);

	$(":checkbox").click(function() { 
		filter = $("#filters").serialize();
		start_ajax();
		$.ajax({
				type: "POST",
				url: url+"?showtemplate=false",
				data: filter,
				success: function(msg){
					$("#content").html(msg);
					stop_ajax();
				},
				statusCode: {
					404: function() {
						alert('Nieznaleziono strony');
						stop_ajax();
					}
				}
			});
	});

	function start_ajax() {
		$("#filters :checkbox").each(function() {
			$('.products li').fadeOut();
			$(this).attr("disabled", true);
		});
	}
	
	function stop_ajax() {
		$("#filters :checkbox").each(function() {
			$('.products li').fadeIn();
			$(this).attr("disabled", false);
		});
	}

});
