var Scroller = {

  init: function() {

    this.element = $("#scroll-content");
    this.oHeight = $("#scroll")[0].offsetHeight;

    $("#scroll").after('<div id="scrollbar"><span id="scroll-top" href="#"><img src="client/images/arrow_top.gif" /></span><span id="scroll-bottom" href="#"><img src="client/images/arrow_bottom.gif" /></span></div>');

    $(document).mouseup(
      function() {
        Scroller.reset();
      }
    );

    $("#scroll-top").mousedown(
      function() {
        Scroller.scrollUp();
      }
    );

    $("#scroll-bottom").mousedown(
      function() {
        Scroller.scrollDown();
      }
    );

    $("#scroll-top").mouseup(
      function() {
        return Scroller.reset();
      }
    );

    $("#scroll-bottom").mouseup(
      function() {
        return Scroller.reset();
      }
    );

  },

  scrollUp: function() {

    this.timer = setInterval(
      function() {

        var limit = Scroller.element[0].offsetTop >= 0;

        if (limit) {
          Scroller.element.css( { top: "0px" } );
          Scroller.reset();
        }
        else {
          Scroller.element.css( { top: (Scroller.element[0].offsetTop + 5) + "px" } );
        }

      }, 25
    );

  },

  scrollDown: function() {

    this.timer = setInterval(
      function() {

        var limit = (parseInt(Scroller.element[0].offsetHeight - parseInt(Scroller.oHeight)) * -1) >= Scroller.element[0].offsetTop;

        if (limit) {
          Scroller.reset();
        }
        else {
          Scroller.element.css( { top: (Scroller.element[0].offsetTop - 5) + "px" } );
        }

      }, 25
    );

  },

  reset: function() {

    if (this.timer) {
      clearInterval(this.timer);
    }

    return false;

  }


}
