/**
 * @author Krzysztof Sobieraj
 * 
 * @since 2010-04-20
 * @version 1.2.20100420.1508
 */
$.noConflict();

jQuery(document).ready(function(){
	addArrows();
	jQuery('.sortable').find('th').click(function(){	
		sort(jQuery(this));
	});
});

function addArrows() {
	jQuery('.sortable').find('th').append('<img class="sortArrow" src="http://www.parkiet.com/materialy/sr/sortowanie/imgs/arrows_light1.gif" alt="sortuj wg skrótu" />');
}

function sort(oActiveElement) {
	// usuniecie strzalki systemowej
	oActiveElement.children('#sorttable_sortrevind').remove();
	oActiveElement.children('#sorttable_sortfwdind').remove();
		
	// jezeli kliknieto element sortujacy rosnaco
	if(oActiveElement.hasClass('sortDown')) {
		// usuwamy klase
		oActiveElement.removeClass('sortDown');
		// dodajemy nowa
		oActiveElement.addClass('sortUp');
		// zmieniamy obrazek
		oActiveElement.children('img').attr('src', 'http://www.parkiet.com/materialy/sr/sortowanie/imgs/arrows_dark_top1.gif')
	}
	// jezeli kliknieto element sortujacy malejaco
	else if(oActiveElement.hasClass('sortUp')) {
		// usuwamy klase
		oActiveElement.removeClass('sortUp');
		// dodajemy nowa
		oActiveElement.addClass('sortDown');
		// zmieniamy obrazek
		oActiveElement.children('img').attr('src', 'http://www.parkiet.com/materialy/sr/sortowanie/imgs/arrows_dark_down1.gif')
	}
	else {
		// usuwamy klase z aktualnie sortujacego elementu
		jQuery('.sortable').find('th.sortDown').children('img').attr('src', 'http://www.parkiet.com/materialy/sr/sortowanie/imgs/arrows_light1.gif');
		jQuery('.sortable').find('th').removeClass('sortDown');
		jQuery('.sortable').find('th.sortUp').children('img').attr('src', 'http://www.parkiet.com/materialy/sr/sortowanie/imgs/arrows_light1.gif');
		jQuery('.sortable').find('th').removeClass('sortUp');
		oActiveElement.addClass('sortDown');
		oActiveElement.children('img').attr('src', 'http://www.parkiet.com/materialy/sr/sortowanie/imgs/arrows_dark_down1.gif');
	}
}

