function bannerimg(src, width, link, title){
 this.src = src;
 this.width = width;
 this.link = link;
 this.title = title;
}


function addmethod(name,width,link,title) {
  this.pics.push(new bannerimg(name,width,link,title))
}


function runmethod() {
  this.piclen=this.pics.length;
  this.imgs = new Array(this.piclen);
  dispwidth=0;
  this.widthlen=0;
  for(ii=0;ii<this.piclen;ii++) {
    this.imgs[ii]= new Image();
    this.imgs[ii].src = this.pics[ii].src;
    this.imgs[ii].width = this.pics[ii].width-1;
    dispwidth=dispwidth+this.pics[ii].width;
    if( this.widthlen==0 && dispwidth > this.width ) {
      this.widthlen=ii;
    }
  }

  var myself = this;
  function callMethod(){
    myself.loadwait();
  }
  this.waitinterval = setInterval(callMethod,550);
}


function loadedmethod() {
  for(ii=0;ii<=this.widthlen;ii++) {
    if(this.imgs[ii].complete == false) {
      return false;
      break;
    }
  }
  return true;
}



function loadwaitmethod() {
   if( this.loaded() == true ) {
     window.clearInterval(this.waitinterval);
     this.popdiv();
     var myself = this;
     function callMethod(){
       myself.scroll();
     }
     this.scrollinterval = setInterval(callMethod,this.speed);
   }
}

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft: what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function popdivmethod() {
  this.lefts = new Array(this.piclen);
  oo = 0;
  hh="";
  for(ii=0;ii<this.piclen;ii++) {
    this.lefts[ii]=oo;
    hh=hh+'<a href="'+this.pics[ii].link+'" title="'+this.pics[ii].title+'"><img id="'+this.div+'i'+ii+'" space="0" hspace="0" vspace="0" vspace="0" border="0" width="'+(this.pics[ii].width+1)+'" height="'+this.height+'" style="position:absolute;left:'+oo+'px;" src="'+this.pics[ii].src+'" alt="'+this.pics[ii].title+'"></a>';
    oo = oo + this.pics[ii].width+this.gap;
  }
  this.maxwidth = oo - (this.pics[this.piclen-1].width+this.gap);
  d = document.getElementById(this.div);
  d.innerHTML=hh;

  var myself = this;
  function callMouseMove(ee) {
    var dsocx=(window.pageXOffset)? pageXOffset: ietruebody().scrollLeft,
        curposx=window.event? event.clientX : ee.clientX? ee.clientX: "";
    if (!ee) var ee = window.event;
    div = document.getElementById(myself.div);
    if(ee.target) {
      xx=getposOffset(div,'left');
    }
    else {
      xx=getposOffset(div,'left');
    }
    curposx-=xx-dsocx;
    curposx-=(myself.width/2);
    curposx = curposx/50;
    myself.scrolloffset = curposx;
  }

  if(this.mouse_flags==1) {
    d.onmousemove = callMouseMove;
  }

  function callMouseOut() {
    myself.mult=1;
    window.clearInterval(myself.scrollinterval);
    myself.scrollinterval = setInterval(callMethod,myself.speed*myself.mult);
  }

  d.onmouseout = callMouseOut;


  function callMethod(){
    myself.scroll();
  }
  function callMouseOver(){
    myself.mult=3;
    window.clearInterval(myself.scrollinterval);
    myself.scrollinterval = setInterval(callMethod,myself.speed*myself.mult);
  }

  if(this.mouse_flags==0) {
    for(ii=0;ii<this.piclen;ii++) {
      im = document.getElementById(this.div+"i"+ii);
      im.onmouseover = callMouseOver;
    }
  }
}



function scrollmethod() {
  if( this.scrolloffset < 0 ) {
    for (ii=0;ii<this.piclen;ii++) {
      this.lefts[ii] = this.lefts[ii] + this.scrolloffset;
      if(this.lefts[ii] <= -(this.pics[ii].width+this.gap)) {
        if( ii==0 ) {
          pleft = this.lefts[this.piclen-1]+this.pics[this.piclen-1].width;
        }
        else {
          pleft = this.lefts[ii-1]+this.pics[ii-1].width;
        }

        this.lefts[ii]=pleft+this.gap;
      }
      im=document.getElementById(this.div+"i"+ii);
      if(im) im.style.left=this.lefts[ii]+"px";
    }
    if( this.scrolloffset < -1 ) {
      this.scrolloffset += 0.02;
    }
  }

  if( this.scrolloffset > 0 ) {
    for (ii=this.piclen-1;ii>=0;ii--) {
      this.lefts[ii] = this.lefts[ii] + this.scrolloffset;
      if( this.lefts[ii] >= this.width ) {
        if( ii == this.piclen-1 ) {
          pleft = this.lefts[0];
        }
        else {
          pleft = this.lefts[ii+1];
        }
        this.lefts[ii] = pleft - (this.pics[ii].width+this.gap);
      }
      im=document.getElementById(this.div+"i"+ii);
      if(im) im.style.left=this.lefts[ii]+"px";
    }
    if( this.scrolloffset > 1 ) {
      this.scrolloffset -= 0.02;
    }
  }
}



function imgscroller(speed,dd,height,width,gap,mouse_flags) {
  this.div=dd;
  this.speed=speed;
  this.gap=gap;
  this.mouse_flags=mouse_flags;
  this.mult=1;
  this.height=height;
  this.width=width;
  this.pics = new Array();
  this.piclen=0;
  this.scrolloffset = -1;
  this.add = addmethod;
  this.run = runmethod;
  this.loaded = loadedmethod;
  this.popdiv = popdivmethod;
  this.scroll = scrollmethod;
  this.loadwait = loadwaitmethod;
  this.waitinterval=0;
}





