/* http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/
   original just sorted ul based on whole li; I made it
   more generic (pass parent and child)
   faster (pre-set case for sorting)
   flexible (pass class to sort on)
*/
  function r5sort (sParent, sChild, sortClass, sortField) {
    var mylist = $(sParent);
    var aKids = mylist.children(sChild).get();
        
    /* sort field holds array # */
    if (sortField==undefined) {      
      aKids.sort (function(a, b) {
        var sA = $(sortClass, a).text(); /* get text of r5sort fields */
        var sB = $(sortClass, b).text();
        return (sA < sB) ? -1 : (sA > sB) ? 1 : 0;
      });
     
    } else {
      sf=sortField;
      aKids.sort (function(a, b) {
        var sA = $(sortClass, a).text(); /* get text of r5sort fields */
        var sA = sA.split(":")[sf];
        
        var sB = $(sortClass, b).text();
        var sB = sB.split(":")[sf];        
        return (sA < sB) ? -1 : (sA > sB) ? 1 : 0;
      });
    }
    
    $.each (aKids, function (idx, itm) {
      mylist.append (itm);
    });
  };
  
      /*
      $('#oSorter').change(function() {
        var sf=$("#oSorter option:selected").text(); // get sort field
        var mylist = $('ul');
        var listitems = mylist.children('li').get();
        
        listitems.sort(function(a, b) {
          var compA = $('.r5s'+sf, a).text(); // get text of r5sort fields 
          var compB = $('.r5s'+sf, b).text();
          return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
        });

        $.each(listitems, function(idx, itm) {
          mylist.append(itm);
        });
      });
    
    */

