
  // custom css expression for a case-insensitive contains()
  jQuery.expr[':'].Contains = function(a,i,m){
      return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0;
  };


  function listFilter(header, list) { // header is any element, list is an unordered list
    // create and add the filter form to the header
    var form = jQuery("<form>").attr({"class":"filterform","action":"#"}),
        input = jQuery("<input>").attr({"class":"filterinput","type":"text"});
    jQuery(form).append(input).appendTo(header);

    jQuery(input)
      .change( function () {
        var filter = jQuery(this).val();
        if(filter) {
          // this finds all links in a list that contain the input,
          // and hide the ones not containing the input while showing the ones that do
          jQuery(list).find("li:not(:Contains(" + filter + "))").hide();
          jQuery(list).find("li:Contains(" + filter + ")").slideDown();
          
          jQuery(list).find("li:Contains(" + filter + ")").show();
          jQuery(list).find("li:not(:Contains(" + filter + "))").hide();
          
        } else {
          jQuery(list).find("li").slideDown();
          jQuery(list).find("li div span").show();
        }
        return false;
      })
    .keyup( function () {
        // fire the above change event after every letter
        jQuery(this).change();
    });
  }


