(function($) {
  $.fn.simple_carousel = function(obj) {
      obj = $.extend({
        next: '.next',
        previous: '.previous',
        show: 4,
        loop: false,
        disabled_class: 'disabled'
      }, obj || {});

      return this.each(function() {
        var show = obj.show;
        var loop = obj.loop;
        var disabled_class = obj.disabled_class;

        var $list = $(this).find('ul, ol');
        var $next = $(this).find(obj.next);
        var $previous = $(this).find(obj.previous);

        var list_items = $list.find('li');

        var start = 0;

        function update() {
          list_items.each(function() {
            $(this).hide();
          });

          for (var i = start; i <= end(); i++)
            $(list_items[i]).show();

          if (loop)
            return;

          if (start == 0)
            $previous.addClass(disabled_class);
          else
            $previous.removeClass(disabled_class);
          if (end() == list_items.length - 1)
            $next.addClass(disabled_class);
          else
            $next.removeClass(disabled_class);
        }

        function end() {
          return Math.min(start + show , list_items.length) - 1;
        }

        update();

        $next.click(function() {
          if ($(this).hasClass(disabled_class))
            return false;

          if (loop && end() == list_items.length - 1)
            start = 0;
          else
            start = Math.min(end() + 1, list_items.length - show);

          update();

          return false;
        });

        $previous.click(function() {
          if ($(this).hasClass(disabled_class))
            return false;

          if (loop && start == 0)
            start = Math.max(list_items.length - show, 0);
          else
            start = Math.max(start - show, 0);

          update();

          return false;
        });

      });
  };
})(jQuery);