var tickers = [];
var ticker_indexes = [];

jQuery.fn.ticker = function() {
  var i = 0; // The current <ul> tag's index in the tickers[] list.
      
  return this.each(function() {
    
    if(jQuery('li', this).size() > 1) {
      
      // Initialize
      tickers[i] = this;
      ticker_indexes[i] = 0;
      jQuery('li',this).hide();
      jQuery('li',this).eq(0).show();
      jQuery(this).addClass('jqueryTicker');
      jQuery('#' + this.id + '_indicator').html('1 of ' + $('li', this).size());
      
      // Start iteration
      setTimeout('jQuery.tickerIterate(' + i + ');', 5000); // setInterval() would cause FF bug.
    } else {
      // Special case. Just activate the single element
      jQuery('li', this).show();
    }
    
    i++;
    
  });
};

jQuery.tickerIterate = function(i) {
  var ul_tag = tickers[i];
  jQuery('li',ul_tag).eq(ticker_indexes[i]).fadeOut('slow');
  ticker_indexes[i] = (ticker_indexes[i] + 1) % $('li',ul_tag).size();
  jQuery('li',ul_tag).eq(ticker_indexes[i]).fadeIn('slow');
  jQuery('#' + ul_tag.id + '_indicator').html((ticker_indexes[i] + 1) + ' of ' + $('li', ul_tag).size());
  
  // Size the UL to the same height as the LI
  // This was removed because it caused the display of the Handicapper's Edge area to have trouble.
  // jQuery(ul_tag).height(jQuery('li', ul_tag).eq(ticker_indexes[i]).height());
  setTimeout('jQuery.tickerIterate(' + i + ');', 5000); // setInterval() would cause FF bug.
};

$(document).ready(
  function(){
    $('ul.ticker').ticker();
  }
);

