jQuery(function($) {
  var loc = document.location.href.split('?')[0];
  var params = document.location.href.indexOf('?') != -1 ? document.location.href.split('?')[1] : '';
  $(".paginated_sort thead tr th").each(function() {
    if ($(this).attr('id') != undefined)
      $(this).addClass('header');
    if (params.indexOf($(this).attr('id')) != -1)
      $(this).addClass(params.indexOf('asc') != -1 ? 'headerSortDown' : 'headerSortUp');
    $(this).click(function () {
      var sort_params = { sort:$(this).attr('id'), dir:$(this).hasClass('headerSortDown') ? 'desc' : 'asc' };
      document.location.href = loc + '?' + jQuery.param(sort_params);
    });
  });
});