/**
 * Obiekt do sortowania tabel.
 * 
 * @param string main_selector JQuery selector dla tabeli
 * @param string row_selector JQuery selector dla pojedynczego wiersza tabeli
 * @return void
 * 
 * @uses jQuery, jQuery TinySort
 */
function SortTable(main_selector, row_selector) {
	this.main_selector = main_selector;
	this.row_selector = row_selector;
	this.current_id = null;
	this.order = [];
	/**
	 * Funkcja sortująca.
	 * 
	 * @param string jquery selector
	 * @param array parametry sortowania
	 * @param element kliknięty odnośnik
	 * @param string umowne id (dla każdego elementu powinno być inne np. kolejne liczby)
	 * @return void
	 */
	this.sort = function(selector, param, element, id) {
		$(this.main_selector).find('a').each(function(i) {
			$(this).removeClass('desc');
			$(this).removeClass('asc');
		});
		
		if (this.order[id] == 'asc') {
			$(element).addClass('desc');
			this.order[id] = 'desc';
		}
		else {
			$(element).addClass('asc');
			this.order[id] = 'asc';
		};
		
		if (this.current_id != id) {
			this.order[this.current_id] = null;
			this.current_id = id;
		}

	    $(this.row_selector).tsort(selector, {'order' : this.order[id]});		
	};
};

