  /*
    ================================================================================================
		ScrollingLayer object by Elias B. <elias@hostrix.com> , 09/10/01, 10:08:27AM 

		History:
		--------
		11/10/01, 03:06:26PM, localized dx, dx variables in the ScrollingLayer constructor
		24/10/01, 01:28:31PM, fixed a in the lockscrollTimer() that would prevent scrolling
		24/10/01, 01:31:44PM, added the isvisible in the object constructor
    ================================================================================================
  */
  function ScrollingLayer(positionImageName, layerName, isVscroll, resolution, isvisible)
  {
		var dx, dy;

    this.layer = getLayer(layerName);
    this.scrollStopped = false; // 
    this.vscroll = isVscroll; // if TRUE then vertical scrolling, else horizontal scrolling
    this.scrollResolution = (resolution) ? resolution : 100;
    this.bounce = false; // allow bouncing when limits reached?

    // get positioning image object
    img = getImage(positionImageName);

    // Layer positioning differ from browser to browser and OS to OS ...make the difference
    if (navigator.appVersion.match(/macint/i)) { dx = 13; dy = 15; } else { dx = dy = 0; }

    // move the layer according to the position Image
    moveLayerTo(this.layer, getImagePageLeft(img) + dx, getImagePageTop(img) + dy); 

    // clip the layer
    clipLayer(this.layer, 0, 0, img.width, img.height);

		// show the layer
		if (isvisible)
      showLayer(this.layer);
  }

  // Signal scrolling stop
  ScrollingLayer.prototype.stopScroll = function() { this.scrollStopped = true; }

  // Scroll the layer
  ScrollingLayer.prototype.scroll = function (dir)
  {
    if (this.vscroll)
      scrollLayerBy(this.layer, 0, dir, true);
    else
      scrollLayerBy(this.layer, dir, 0, true);
  }

  /*
    ================================================================================================
    LOCKED SCROLLING CODE
    ================================================================================================
  */
  curObj = null, curDir = null;

  function lockscroll(obj, dir)
  {
    curObj = obj;
    curDir = dir;
    lockscrollTimer();
  }

  function lockscrollTimer()
  {
//		document.title = 'scrolled ' + Math.random() + ' dir=' + curDir + ' bounce=' + curObj.bounce;
    // bouncing code
    if ( (((getClipRight(curObj.layer) == getWidth(curObj.layer)) && (curDir > 0)) ||
            ((getClipLeft(curObj.layer) == 0) && (curDir < 0))) &&
          curObj.bounce
       )
      curDir *= -1;

		curObj.scroll(curDir);

    if (!curObj.scrollStopped)
      setTimeout("lockscrollTimer()", curObj.scrollResolution);
    else
    {
      curObj.scrollStopped = false;
    }
  }

