  (function ($)
  {
    $.fn.extend(
    {
      itemsFader: function (options)
      {
        var defaults = {
          queueSelector: '.ifQueue',
          containerSelector: '.ifContainer',
          itemSelector: '.ifItem',
          delay: 5000,
          speed: 'slow'
        };

        var options = $.extend(defaults, options);

        function swapItems(context)
        {
          if (!context || !context.queue || !context.containers || context.queue.children().length <= 0) return;

          context.containerIndex = (context.containerIndex > 0) ? context.containerIndex - 1 : context.containers.length - 1;
          var containerCell = $(context.containers[context.containerIndex]);
          var currentDisplayItem = containerCell.children().first();

          $(currentDisplayItem).fadeOut(options.speed, function () { $(currentDisplayItem).appendTo(context.queue); });

          var nextDisplayItem = $(context.queue.children().first());
          nextDisplayItem.css('display', 'none');
          nextDisplayItem.appendTo(containerCell);
          nextDisplayItem.fadeIn(options.speed);
        }

        function setPause(context, paused)
        {
          if (paused)
            clearInterval(context.interval);
          else
            context.interval = setInterval(function () { swapItems(context); }, options.delay);
        }

        return this.each(function ()
        {
          var obj = $(this);

          var context = { containerIndex: 0, queue: $(options.queueSelector, obj), containers: $(options.containerSelector, obj), paused: false, interval: 0 };

          $(options.itemSelector, obj).bind('mouseover', function () { setPause(context, true); });
          $(options.itemSelector, obj).bind('mouseout', function () { setPause(context, false); });

          for (var i = 0; i < context.containers.length; i++)
          {
            var item = context.queue.children().first();
            if (!item)
              break;
            $(item).appendTo(context.containers[i]);
          }

          setPause(context, false);

        });
      }
    });
  })(jQuery);
