jQuery(document).ready(function() {
	jQuery('#ascending').click(function() {
		SORTER.sort('.notices');
	});
	jQuery('#descending').click(function() {
		SORTER.sort('.notices', 'desc');
	});
});

var SORTER = {};
SORTER.sort = function(which, dir) {
  SORTER.dir = (dir == "desc") ? -1 : 1;
  jQuery(which).each(function() {
    // Find the list items and sort them
    var sorted = jQuery(this).find("> a").sort(function(a, b) {
     return jQuery(a).text().toLowerCase() > jQuery(b).text().toLowerCase() ? SORTER.dir : -SORTER.dir; 
    });
    jQuery(this).append(sorted);
  });
};
