Convert Global Code to jQuery Function

Convert Global Code to jQuery Function

I'm new to jQuery but pretty familiar with JavaScript. I would like to convert the code below to a function that can be used like "$("#member-feedback li").rotateElements()". I've looked at some examples, but I'm not sure where to start. Thanks for your help.

  1. var els = [];
  2. var idx = 0;
  3. var num = 0;
  4. function rotateElements() {
  5.     els.eq(idx).hide();
  6.     idx++;
  7.     if(idx >= num) { idx = 0; }
  8.     els.eq(idx).fadeIn('slow');
  9. }
  10. $(function() {
  11.     els = $('#member-feedback li');
  12.     num = els.length;
  13.     idx = Math.floor(Math.random() * num)
  14.     els.eq(idx).show();
  15.     setInterval('rotateElements()', 7000);
  16. });