(function ($) {
   $.fn.scroller = function (options) {

       var options = $.extend({}, {
           event:      "click",            // click | hover
           enabled:    "scroll-enabled",   // class to be applied to scrollable with scrolling enabled
           up:         "~ .up",            // selector (rel. to scrollable) defining "scroll up" button
           down:       "~ .down",          // selector (rel. to scrollable) defining "scroll down" button
           increment:  10,
           interval:   25
       }, options);

       this.each(function() {

           var self = this;

           var inner = $('<div class="inner"></div>').html($(this).html());
           $(this).html(inner);

           if (inner.height() > $(this).height()) {
               inner.addClass(options.enabled);

               var inc, timer = null;

               function scroll() {
                   var bottom = -inner.height() + $(self).height();
                   inner.css('marginTop', Math.max(bottom, Math.min(0, parseInt(inner.css('marginTop')) + inc)));
               }

               function on() {
                   $(this).addClass('active');
                   inc = (this == $(options.up, self)[0] ? 1 : -1) * options.increment;
                   timer = window.setInterval(scroll, options.interval);
               }

               function off() {
                   $(this).removeClass('active');
                   window.clearInterval(timer);
               }

               var actuators = $(options.up + ", " + options.down, this);
               actuators.show();

               if (options.event == 'click') {
                   actuators.mousedown(on).mouseup(off).mouseout(off).click(function() { return false; });
               } else {
                   actuators.hover(on, off);
               }
           }
       });
   }
})(jQuery);
