/*<![CDATA[*/
// Continious ScrollerII (14-December-2007)
// by: Vic Phillips http://www.vicsjavascripts.org.uk


// Application Notes
// The effect is initialised and controlled by event calls to function
// zxcScroller('h','tst2','start',1,100,200);
// where:
// parameter 0 = the mode, for vertical 'v', for horizontal 'h'.                     (string 'v' or 'h');
// parameter 1 = the unique id name of the scroll container.                         (string);
// parameter 2 = start or stop.                                                      (string 'start' or 'stop');
// parameter 3 = to scroll up/left = negative digit or down/right = positive digit.  (digit);
//               may also be used to control the scroll speed.
// parameter 4 = the scroll speed (milli seconds).                                   (digits);
// parameter 5 = the initial delay before scrolling (milli seconds).                 (digits);
//
// The first call will initialise the effect.
// Subsequent calls may be used control the effect by updating parameters 2, 3 and 4.
// If parameters 2 or 3 are not specified the parameter will be toggled.
// Examples
//<input type="button" name="" value="Toggle Direction" onclick="zxcScroller('h','tst2','start');"/>
//<input type="button" name="" value="Toggle Stop/Start" onclick="zxcScroller('h','tst2');"/>

// Functional Code size = 2.4k

function zxcScroller(zxcmde,zxcid,zxcrun,zxcud,zxcspd,zxcsrt){
 var zxcp=document.getElementById(zxcid);
 if (!zxcp[zxcmde+'scroll']) return zxcp[zxcmde+'scroll']= new zxcScrollerOOP(zxcmde,zxcp,zxcrun,zxcud,zxcspd,zxcsrt);
 var zxcoop=zxcp[zxcmde+'scroll']
 clearTimeout(zxcp.to);
 zxcoop.spd=zxcspd||zxcoop.spd;
 zxcoop.ud=zxcud||-zxcoop.ud;
 zxcp[zxcmde+'run']=(zxcrun=='stop'||zxcrun=='start')?zxcrun:(zxcp[zxcmde+'run']=='stop')?'start':'stop';
 if (zxcp[zxcmde+'run']=='start') zxcoop.scroll();
}

function zxcScrollerOOP(zxcmde,zxcp,zxcrun,zxcud,zxcspd,zxcsrt){
 this.p=zxcp;
 var zxcc=this.p.getElementsByTagName('DIV')[0]
 this.vh=(zxcmde.charAt(0).toLowerCase()=='v');
 this.mde=zxcmde;
 this.ary=[];
 this.ary[0]=[zxcc,0];
 var zxcmax=(((this.vh)?this.ary[0][0].offsetHeight:this.ary[0][0].offsetWidth))+((this.vh)?this.p.offsetHeight:this.p.offsetWidth);
 this.wh=(this.mde.charAt(0).toLowerCase()=='v')?this.ary[0][0].offsetHeight:this.ary[0][0].offsetWidth;
 var zxcpos=0;
 while (zxcpos<zxcmax){
  var zxc1=this.ary.length;
  this.ary[zxc1]=[this.ary[0][0].cloneNode(true),zxcpos+=this.wh];
  zxcES(this.ary[zxc1][0],{position:'absolute',left:((this.vh)?0:this.ary[zxc1][1])+'px',top:((this.vh)?this.ary[zxc1][1]:0)+'px'},this.p);
 }
 this.ud=zxcud||-1;
 this.spd=zxcspd||100;
 this.p.to=null;
 this.data=[zxcpos,-this.wh];
 this.p[this.mde+'run']=(zxcrun=='stop'||zxcrun=='start')?zxcrun:'start';
 if (this.p[this.mde+'run']) this.p.to=setTimeout(function(zxcoop){return function(){zxcoop.scroll();}}(this),zxcsrt||500);
}

zxcScrollerOOP.prototype.scroll=function(){
 if (this.p[this.mde+'run']=='start'){
  for (var zxc1=0;zxc1<this.ary.length;zxc1++){
   this.ary[zxc1][1]+=this.ud;
   zxcES(this.ary[zxc1][0],{position:'absolute',left:((this.vh)?0:this.ary[zxc1][1])+'px',top:((this.vh)?this.ary[zxc1][1]:0)+'px'});
   if ((this.ud<0&&this.ary[zxc1][1]<=this.data[1])||(this.ud>0&&this.ary[zxc1][1]>this.data[0])) this.ary[zxc1][1]=this.data[(this.ud<0)?0:1];
  }
 }
 this.p.to=setTimeout(function(zxcoop){return function(){zxcoop.scroll();}}(this),this.spd);
}

function zxcES(zxcele,zxcstyle,zxcp,zxctxt){
 if (typeof(zxcele)=='string'){ zxcele=document.createElement(zxcele); }
 for (key in zxcstyle){ zxcele.style[key]=zxcstyle[key]; }
 if (zxcp){ zxcp.appendChild(zxcele); }
 if (zxctxt){ zxcele.appendChild(document.createTextNode(zxctxt)); }
 return zxcele;
}


/*]]>*/
