

scrollObject.houder = [];
function scrollObject(id,x,y,richting,sp,d,fn) {
  this.el = document.getElementById? document.getElementById(id): null;
  if (!this.el) return;
  var px = window.opera? 0: "px";
  this.id = id; this.xOff = x; this.yOff = y;
  this.el.style.left = x + px; this.el.style.top = y + px;
  this.el.style.visibility = "visible"; 
  this.snelheid = sp; this.ctr = 0; this.active = true;
  if (fn) this.einde = fn; this.pauze = d;
  if (!fn && !d) this.einde = function() { this.el = null; this.active = false; };
  this.prop = (richting == "left" || richting == "right")? "left": "top";
  if (richting == "left" || richting == "up") this.snelheid = -sp;
  scrollObject.houder[scrollObject.houder.length] = this;
  if (!scrollObject.Canvas.width || !scrollObject.Canvas.height) scrollObject.Canvas = scrollObject.getDimensions();
}

scrollObject.prototype.scroll = function() {
  var cur;
  switch (this.prop) {
    case "left":
      cur = parseInt( this.el.style.left );
      if ( ( this.snelheid > 0 && cur < scrollObject.Canvas.width + this.el.offsetWidth ) 
          || ( this.snelheid < 0 && cur > -this.el.offsetWidth ) ) {
        this.el.style.left = parseInt(this.el.style.left) + this.snelheid + "px";
      } else {
        if (this.pauze) this.stop_en_reset(this.xOff);
        this.einde(this);
      }
    break;
    case "top":
      cur = parseInt( this.el.style.top );
      if ( ( this.snelheid > 0 && cur < scrollObject.Canvas.height + this.el.offsetHeight ) 
          || ( this.snelheid < 0 && cur > -this.el.offsetHeight ) ) {
        this.el.style.top = parseInt(this.el.style.top) + this.snelheid + "px";
      } else {
        if (this.pauze) this.stop_en_reset(this.yOff);
        this.einde(this);
      }
    break;
  }
}

scrollObject.prototype.stop_en_reset = function(nOff) {
  if ( this.ctr < this.pauze/scrollObject.callRate ) {
    this.el.style.visibility = "hidden";
    this.ctr++;
  } else { 
    this.el.style[this.prop] = nOff + "px"; 
    this.el.style.visibility = "visible";
    this.ctr = 0; 
  }
}

scrollObject.prototype.einde = function(){};

scrollObject.callRate = 20;
scrollObject.timer = window.setInterval("scrollObject.control()", scrollObject.callRate);
scrollObject.control = function() {
  var i, curObj;
  for (i=0; curObj = scrollObject.houder[i]; i++) 
    if ( curObj && curObj.active ) curObj.scroll();
}

scrollObject.Canvas = {};
scrollObject.getDimensions = function() {
  var winWd=0, winHt=0, docWd=0, docHt=0;
  
  if (window.innerWidth) winWd = window.innerWidth - 18;
	else if (document.documentElement && document.documentElement.clientWidth) 
		winWd = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth) 
		winWd = document.body.clientWidth;
    
  if (window.innerHeight) winHt = window.innerHeight - 18;
	else if (document.documentElement && document.documentElement.clientHeight) 
		winHt = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight) 
		winHt = document.body.clientHeight;
    
  if (document.width) docWd = document.width;
  else if (document.body) 
    docWd = Math.max(document.body.scrollWidth, document.body.offsetWidth);
    
  if (document.height) docHt = document.height;
  else if (document.body) 
    docHt = Math.max(document.body.scrollHeight, document.body.offsetHeight);
    
  return {
    width:  Math.max(winWd, docWd),
    height: Math.max(winHt, docHt)
  }

}

if (window.addEventListener)
  window.addEventListener("resize", function(){ scrollObject.Canvas = scrollObject.getDimensions() }, "false");
else if (window.attachEvent)
  window.attachEvent("onresize", function(){ scrollObject.Canvas = scrollObject.getDimensions() } );

