$(document).ready(function() {
	
	$('.jos-polazaka').live("click", function() {
		link = $(this);
		var cene = link.prev();
		var smesob = link.attr("rel");
		var temp = smesob.split('-');
		var strana = parseInt(temp[3])+1;
		temp = temp[0] +'-'+ temp[1] +'-'+ temp[2] +'-'+ strana;
		link.attr('rel', temp);
		
		// brojac
		var preostalo = parseInt(link.children('.preostalo').text());
		
		link.hide().next('.loader').show();
		
		$.ajax({
			url: "/ajax.cenovnik.php",
			type: "GET",
			data: $('form.filter').serialize() +"&smesob="+ smesob,
			
			success: function(html) {
				cene.after(html);
				link.show().next('.loader').hide();
				if(preostalo <= 9) {
					link.hide();
				} else {
					link.children('.preostalo').html(preostalo-9);
				}
				
			}
		});
	});
});
