var scroll = function(obj) {
    this.obj = obj;
  this.move = function() {
    this.state;
    if(this.state==1) { return; }
    this.stop = 0;
    for(i=1; i<=2; i++) {
      this.divbox = eval(document.getElementById('wrap'+obj+'_'+i));
      this.wrap1 = document.getElementById('wrap'+obj+'_1');
      this.wrap2 = document.getElementById('wrap'+obj+'_2');
      this.wrap1_top = parseInt(this.wrap1.style.top);
      this.wrap1_left = parseInt(this.wrap1.style.left);
      this.wrap2_top = parseInt(this.wrap2.style.top);
      this.wrap2_left = parseInt(this.wrap2.style.left);
      for(k=0; k<this.stopPositionSize; k++) {
        if(this.direction=="up" || this.direction=="down") {
          if((this.stopPosition[k]==Math.abs(this.wrap1_top) || this.wrap1_top==0 || this.wrap1_top==this.realHeight) && this.delay!=this.delay_chk) {
            this.stop=1;
            if(this.wrap1_top>=0) this.wrap2.style.top = -this.realHeight + this.wrap1_top;
            if(this.wrap1_top<0) this.wrap2.style.top = this.realHeight + this.wrap1_top;
          }
        } else {
          if((this.stopPosition[k]==Math.abs(this.wrap1_left)  || this.wrap1_left==0 || this.wrap1_left==this.realWidth) && this.delay!=this.delay_chk) {
            this.stop=1;
            if(this.wrap1_left>=0) this.wrap2.style.left = -this.realWidth + this.wrap1_left;
            if(this.wrap1_left<0) this.wrap2.style.left = this.realWidth + this.wrap1_left;
          }
        }
      }
      if(this.stop) { this.delay_chk++; return; } else { this.delay_chk=0; }

      if(this.direction=="up") {
        this.divbox.style.top=parseInt(this.divbox.style.top) - 2;
        if(parseInt(this.divbox.style.top) < -this.realHeight) this.divbox.style.top = this.realHeight;
      }
      else if(this.direction=="down") {
        this.divbox.style.top = parseInt(this.divbox.style.top) + 2;
        if(parseInt(this.divbox.style.top) > this.realHeight) this.divbox.style.top = -this.realHeight;
      }
      else if(this.direction=="right") {
        this.divbox.style.left = parseInt(this.divbox.style.left) + 2;
        if(parseInt(this.divbox.style.left) > this.realWidth) this.divbox.style.left = -this.realWidth ;
      }
      else if(this.direction=="left") {
        this.divbox.style.left = parseInt(this.divbox.style.left) - 2;
        if(parseInt(this.divbox.style.left) < -this.realWidth) this.divbox.style.left = this.realWidth ;
      }
    }
  }


  this.start = function(direction) {
    this.direction = direction;
    if(!this.direction) this.direction = "left";

    this.cnt = document.getElementById("rolling"+this.obj).getElementsByTagName('td').length;

    this.delay_chk = 0;
    var self = this;

    if(!this.interval) this.interval = 1;
    if(!this.scrollWidth) this.scrollWidth = 300;
    if(!this.visibleWidth) this.visibleWidth = 300;
    if(!this.visibleHeight) this.visibleHeight = 30;
    if(!this.realHeight) this.realHeight = 120;
    if(!this.realWidth) this.realWidth = this.cnt*this.scrollWidth;

    this.stopPosition = new Array;
    for (i=1; i<this.cnt; i++) { this.stopPosition[i] = i*this.scrollWidth; }
    this.stopPositionSize = this.stopPosition.length;

    if(this.direction=="up" || this.direction=="down") { divleft=0;  divtop=this.realHeight; } else { divleft=this.realWidth;  divtop=0; }
    document.write("<div style='position:relative;width:" + this.visibleWidth + ";height:" + this.visibleHeight + ";overflow:hidden;' onmouseover='obj"+obj+".state=1' onmouseout='obj"+obj+".state=0'><div id='wrap"+obj+"_1' style='position:absolute;width:"+ this.realWidth + ";height:"+ this.realHeight +";left:0;top:0;'>"+document.getElementById('rolling'+obj).innerHTML+"</div><div id='wrap"+obj+"_2' style='position:absolute;width:"+ this.realWidth + ";height:"+ this.realHeight +";left:" + divleft +";top:" + divtop + ";'>"+ document.getElementById('rolling'+obj).innerHTML+"</div></div>");
    window.setInterval(function() {self.move()}, this.interval);
  }

}

