/*
* SCROLL
*
* Verwaltet SCROLL-Bibliothek
*
* @package  scroll.class.js
* @author   Sergej Müller
* @since    23.07.2007
* @change   23.07.2007
* @access   public
* @param    object  obj   Object, an dem Scrolling angewendet werden soll
* @param    object  attr  Object mit Attributen des Scrollings
*/

SCROLL = function(obj, attr) {

  /*
  * interval
  *
  * Interval des Loopings
  *
  * @access  private
  * @type    object
  */

  var interval;

  /*
  * offset
  *
  * Offset-eigenschaften des Objects
  *
  * @access  private
  * @type    object
  */

  var offset = {

    /*
    * top
    *
    * offsetTop des Objects
    *
    * @access  private
    * @type    integer
    */

    'top': obj.offsetTop || 0,

    /*
    * height
    *
    * offsetHeight des Objects
    *
    * @access  private
    * @type    integer
    */

    'height': (obj.offsetHeight + 50) || 0
  };

  /*
  * start
  *
  * Startet das Scrolling
  *
  * @package  scroll.class.js
  * @author   Sergej Müller
  * @since    23.07.2007
  * @change   23.07.2007
  * @access   public
  * @param    integer  amount  Anzahl der Pixel als Schritt der Bewegung
  */

  this.start = function(amount) {
    /* Default setzen */
    attr.top = attr.top || 0;
    attr.width = attr.width || "auto";
    attr.height = attr.height || "auto";

    /* Intervall starten */
    interval = setInterval(
                                 function() {
                                   move(amount);
                                 },
                                 attr.time
                                );
  };

  /*
  * stop
  *
  * Stoppt das Scrolling
  *
  * @package  scroll.class.js
  * @author   Sergej Müller
  * @since    23.07.2007
  * @change   23.07.2007
  * @access   public
  */

  this.stop = function() {
    if (interval) {
      clearInterval(interval);
    }
  }

  /*
  * move
  *
  * Bringt das Scrolling in Bewegung
  *
  * @package  scroll.class.js
  * @author   Sergej Müller
  * @since    23.07.2007
  * @change   23.07.2007
  * @access   private
  * @param    integer  amount  Anzahl der Pixel als Schritt der Bewegung
  */

  function move(amount) {
    /* Werte refreshen */
    attr.top += amount;
    attr.height += amount;
    offset.top -= amount;

    /* Grenze überschritten? */
    if (attr.top < 0 || attr.height > offset.height) {
      attr.top -= amount;
      attr.height -= amount;
      offset.top += amount;
      return;
    }

    /* Object bewegen */
    obj.style.clip = "rect(" + attr.top + "px " + attr.width + "px " + attr.height + "px 0)";
    obj.style.top = offset.top + "px";
  }
}
