jQuery.fn.sort = function() {
   return this.pushStack( [].sort.apply( this, arguments ), []);
};

function sort(master, cls) {
   var sort_func;
   if (cls != 'country') {
      sort_func = function (a, b){
         return $(a).find('.'+cls).text() > $(b).find('.'+cls).text() ? 1 : -1;
      }
   } else {
      sort_func = function (a, b) {
         return $(a).find('.'+cls+' img').attr('alt') > $(b).find('.'+cls+' img').attr('alt') ? 1 : -1;
      }
   }
   $(master).children().sort(sort_func).appendTo(master);
}
