$(document).ready(function() {
	$('table.tablesorter').each(function() {
		var $table = $(this);
		$('th', $table).each(function(column) {
			var $header = $(this);
			if ($header.is('.rad-znaky')) {
				$header.click(function() {
					var sort = 1;
					if ($header.is('.s-asc')) { sort = -1; }

					var rows = $table.find('tbody > tr').get();
					
					$.each(rows, function(index, row) {
						var $cell = $(row).children('td').eq(column);
						row.sortKey = $cell.text().toUpperCase();
					});

					rows.sort(function(a, b) {
						if (a.sortKey < b.sortKey) return -sort;
						if (a.sortKey > b.sortKey) return sort;
						return 0;
					});
					
					$.each(rows, function(index, row) {
						$table.children('tbody').append(row);
						row.sortKey = null;
					});

					$table.find('th').removeClass('s-asc')
									.removeClass('s-desc');
					
					if (sort == 1) { $header.addClass('s-asc'); }
					else { $header.addClass('s-desc'); }
				});
			}
		});
	});
});