var   scrollerAll = new Array();   
var   isNS4 = 0;

function scrollerAdd(me)
{
var i = scrollerAll.length;   
scrollerAll[i] = me;   
if (i == 0)
   setInterval('scrollerRun()', 100);
//   scrollerRun();
}

function scrollerRun()
{
for (i = 0;i < scrollerAll.length;i++) {
   scrollerAll[i].scroll();
   }
}

function Scroller(Target,Name,Type,Width,Height)
{
if (document.layers) {
   isNS4 = 1;
   }
else if (document.getElementById)
   ;
else return;
   
this.target   = Target;
this.name     = Name;
this.type     = Type;
this.w        = Width;
this.h        = Height;
this.len      = 0;
this.paused   = 0;
this.step     = 5;
this.create   = scrollerCreate;
this.createin = isNS4? scrollerCreate4 : scrollerCreate5;
this.install  = scrollerInstall;
this.installin= isNS4? scrollerInstall4: scrollerInstall5; 
this.setRange = scrollerSetRange;
this.setSpeed = scrollerSetSpeed;
this.setText  = scrollerSetText;
this.start    = scrollerStart;
this.stop     = scrollerStop;
}

function scrollerCreate()
{
this.create = scrollerNoop;
this.img = document.images[this.name];
if (this.img == null) {
   alert('null ' + this.name);
   return;
   }
var img = this.img;   
if (isNS4 == 1) {
   if (img.container != null) {
      this.x = img.container.pageX + img.x;
      this.y = img.container.pageY + img.y;
      }
   else {
      this.x = img.x;
      this.y = img.y;
      }
   }
else {
   this.x = this.y = 0;
   var obj = img;
   while (obj.offsetParent != null) {
      this.x += obj.offsetLeft;
      this.y += obj.offsetTop;
      obj = obj.offsetParent;
      }
   this.x += obj.offsetLeft;
   this.y += obj.offsetTop;
   }   
if (this.type == 'left') {
   this.curX = this.w;
   this.scroll   = scrollerLeft;
   }
else if (this.type == 'up') {
   this.curY = this.h;
   this.scroll   = scrollerUp;
   }
else {
   alert("type? " + this.type);
   }
this.createin();
scrollerAdd(this);
//alert("create");
}

function scrollerCreate4()
{
this.baseLayer   = new Layer(this.w);
//this.baseLayer.bgColor = '#ff0000';
this.scrollLayer = new Layer(this.w, this.baseLayer);
//this.scrollLayer.bgColor = '#00ff00';
this.baseLayer.moveTo(this.x, this.y);
this.baseLayer.clip.left     = this.baseLayer.clip.top =
this.scrollLayer.clip.left   = this.scrollLayer.clip.top = 0;
this.baseLayer.clip.right    = this.scrollLayer.clip.right  = this.w;
this.baseLayer.clip.bottom   = this.scrollLayer.clip.bottom = this.h;
this.scrollLayer.document.writeln(this.body);
this.scrollLayer.document.close();
if (this.type == 'left') {
   if (this.len == 0)
      this.len = this.w;
   this.scrollLayer.clip.right = this.len;
   this.scrollLayer.moveTo(this.curX, 0);
   this.scrollin = scrollerLeft4;
   }
else if (this.type == 'up') {
   if (this.len == 0)
      this.len = this.h;
   this.scrollLayer.clip.bottom = this.len;
   this.scrollLayer.moveTo(0, this.curY);
   this.scrollin = scrollerUp4;
   }
this.baseLayer.visibility    = this.scrollLayer.visibility  = "show";
}

function scrollerCreate5()
{
var el = document.getElementById('canvas');
var et = document.getElementById('canvasText');
this.scrollLayer = et;
el.style.width  = this.w + "px";
el.style.height = this.h + "px";
et.style.height = this.h + "px";
el.style.left   = this.x + "px";
el.style.top    = this.y + "px";

if (this.type == 'left') {
   et.style.top    = 0 + "px";
   et.style.left   = this.curX + "px";
   this.scrollin = scrollerLeft5;
   }
else if (this.type == 'up') {
   et.style.left   = 0 + "px"; 
   et.style.top    = this.curY + "px";
   this.scrollin = scrollerUp5;
   }   
el.style.visibility = 'visible';
}

function scrollerInstall()
{
document.writeln('<img src="blank.gif" name="' + this.name + '" width="' + this.w + '" height="'+ this.h + '"150">');//
var mo = 'onmouseover="' + this.target + '.stop()" onmouseout="' + this.target + '.start()"';
this.installin(mo);
//alert("install");
}

function scrollerInstall4(mo)
{
}

function scrollerInstall5(mo)
{
document.writeln('<div id="canvas" ' + mo + '><div id="canvasText">');
document.writeln(this.body);
document.writeln('</div></div>');
}

function scrollerLeft()
{
if (this.paused > 0)
   return;
this.curX -= this.step;
if (this.curX < - this.w)
   this.curX = this.w;
this.scrollin();
}

function scrollerLeft4()
{
this.scrollLayer.moveTo(this.curX, 0);
}

function scrollerLeft5()
{
this.scrollLayer.style.left = this.curX + "px";
}

function scrollerUp()
{
if (this.paused > 0)
   return;
this.curY -= this.step;   
//if (this.curY < - this.h)
if (this.curY < - this.len)
   this.curY = this.h;
this.scrollin();
}

function scrollerNoop()
{
  ;
}

function scrollerSetRange(r)
{
this.len = r;   
}

function scrollerSetSpeed(s)
{
this.step = s;   
}

function scrollerSetText(text)
{
this.body = text;   
//alert("settext");
}

function scrollerStart()
{
this.paused = 0;   
}

function scrollerStop()
{
this.paused = 1;   
}

function scrollerUp4()
{
this.scrollLayer.moveTo(0, this.curY);
}

function scrollerUp5()
{
this.scrollLayer.style.top = this.curY + "px";
}

