var o = jQuery.fn.ticker = function(settings) 
{
  /*
    Functionlity for the 'ticker' on the home and about page
  */
  settings = jQuery.extend(
  {
    interval: 10000
  }
  , settings);
  return this.each(
    function()
    {
      var el = this;
      var lis = jQuery("li", el);
      var hide = -1;
      // find out which number item should be open
      for(var i = 0;i < lis.length;i ++) {
        if(lis.eq(i).hasClass("current")) {
          current = i;
        
        }
        // find out which items should be hidden, basically from class="hidden" onwards
        if(lis.eq(i).hasClass("hidden")) {
          hide = i;
          break;
        }
      }
      // save the settings I got above somewhere handy
      el.cfg = {
        items: jQuery(this).children().length,
        currentIndex: current,
        hideIndex: hide
        
      };
      // functionality to add a line into the ticker
      el.addLine = function(item)
      {
        if(item instanceof jQuery) {
          jQuery(this).append(item.get(0));
          return;
        }    
      };
      // functionality to remove a line from the ticker
      el.removeLine = function()
      {
        return jQuery("li:first", this).remove();
        
      };
      /*
        Moves the ticker on one.
        1. remove styles from previous 'opened' item in the ticker
        2. Remove the first item, using removeLine
        3. If some items are hidden, firstly hide everything, then unhide any items before hideIndex (which is the index of the first hidden item)
        4. Add the previously removed line onto the bottom
        5. No the order has changed slightly, re-open the correct number item using css
      */
      el.swap = function()
      {
        jQuery(el)
          .children(".previous").removeClass("previous").end()
          .children(".current").removeClass("current");
        
        var li = el.removeLine();
        if(el.cfg.hideIndex != -1) {
          li.addClass("hidden");
          jQuery(el).children().eq(el.cfg.hideIndex-1).removeClass("hidden");
        }
        
        el.addLine(li);
        jQuery(el).children().eq(el.cfg.currentIndex - 1).addClass("previous").end()
        jQuery(el).children().eq(el.cfg.currentIndex).addClass("current");
        
        
      };
      // call swap every so many milliseconds (can be changed in the html source, or above in the settings)
      setInterval(el.swap, settings.interval);
      
    }
  );
};