/*******  (C)Stephen Chalmers

 Info: http://scripterlative.com?scrollstatus

 These instructions may be removed but not the above text.

- ScrollStatus -

Scrolls a randomly-selected message in the status bar, for a preset number of cycles.

Consecutive message selections are always different (if cookie support is available).

Pauses when hyperlinks or form buttons are hovered (in the same frame) to allow the display of
URLs / titles.

The number of cycles and scrolling speed are configurable.

Includes stop and start methods, to allow additional code to pause and restart scrolling.

NOTE: Requires client browser to be configured to permit status bar alteration.

The following instructions may be removed, but not the above text.

Please notify any suspected errors in this text or code, however minor.

Installation
~~~~~~~~~~~~
Save this file or text as 'scrollstatus.js' and copy it to a suitable folder relating to your web
pages. Within the <BODY> section of all documents that will use the script, at any point after the
last hyperlink, insert the following script tags:

<SCRIPT type='text/javascript' src='scrollstatus.js'></SCRIPT>

(If scrollstatus.js resides in a different folder, include the relative path)

Configuration
~~~~~~~~~~~~~
Immediately after the script tags above, insert the following code, replacing the parameters with
your own values as explained below.

<script type='text/javascript'>

 ScrollStatus.load( cycles, period, "A Message", [ Other optional messages ,] Terminal Message );

</script>

Meaning of Parameters
---------------------
Cycles - The number (not in quotes) of times the message should cycle before stopping.

Period - The number (not in quotes) of milliseconds between text movements. Recommended 100-200.

All subsequent parameters except the last, are quoted sentences representing the messages to be
shown. The number of messages that can be specified is unlimited. It is O.K. to specify only one
message, but always specify a terminal message as explained below.

Terminal Message - Specifies the text to be displayed when the scrolling cycle stops.
To preserve the original text until overwritten by browser activity, specify "".
To blank the status line when scrolling stops, specify " ".
Otherwise specify whatever text you wish to display.

IMPORTANT: All parameters must be followed by a comma, except the last.

Example
~~~~~~~
Each time it is loaded, a web page will display one of three promotional messages selected at
random.
The message will cycle three times, and the period between characters will be 120 milliseconds.
When the scrolling cycle stops, the message will continue to be displayed until overwritten.

<script type='text/javascript' src='scrollstatus.js'></script>

<script type='text/javascript'>

ScrollStatus.load( 3, 120,
"Check out the bargains in our clearance section today!",
"Consider registering your details to get regular price updates",
"Remember we buy and sell second-hand equipment too.",
"" // <- NO COMMA AFTER LAST PARAMETER
);

</script>

Be careful to follow the exact syntax shown.

Pausing and Re-Starting
~~~~~~~~~~~~~~~~~~~~~~~
The script includes the methods ScrollStatus.stop and ScrollStatus.start, to allow additional code
to pause and restart scrolling (during the specified cycles only).

Mouse Events
~~~~~~~~~~~~
The mouse event handlers generated by this script, will be appended to any created by
previously-loaded scripts or embedded statements. For this reason, try to load this script after
any other scripts that are known to use mouse events.

Troubleshooting
~~~~~~~~~~~~~~~
This script is very unlikely to conflict with others.
The most likely cause of errors will be syntax errors in the supplied parameters.
Always check for error messages in the browser's JavaScript console.

Title Bar
~~~~~~~~~
To scroll text in the title bar instead, execute: ScrollStatus.useTitle=true; before the call to
ScrollStatus.load; The document must have a default HTML title. The default title is restored in place
of the terminal message.
This option cannot be used when the document is contained within the frames of a site on a different domain.

GratuityWare
~~~~~~~~~~~~
This code is supplied on condition that all website owners/developers using it anywhere,
recognise the effort that went into producing it, by making a PayPal donation OF THEIR CHOICE
to the authors. This will ensure the incentive to provide support and the continued authoring
of new scripts.

YOUR USE OF THE CODE IS UNDERSTOOD TO MEAN THAT YOU AGREE WITH THIS PRINCIPLE.

You may donate at www.scripterlative.com, stating the URL to which the donation applies.

*** DO NOT EDIT BELOW THIS LINE ****/

var ScrollStatus=/*286329323030372053204368616C6D657273*/
{
 messageTable:[], canScroll:true, logged:0, currentPos:0, msgIndex:-1, period:150, cycle:0,
 maxCycles:1, useTitle:false, bon:0, defTitle:"", tail:' - - - - ', topLevel:self,

 /* Free download from: http://scripterlative.com?scrollstatus */
 
 stop:function()
 {
  if(!this.useTitle)
    this.canScroll=false;
 },

 start:function()
 {
  this.canScroll=true;
 },

 cookie:function(action)
 {
  var m,ind,dt=new Date();

  dt.setDate( dt.getDate()+30 );

  if( document.cookie )
  {
   if( (m=document.cookie.match(/ScrollStatusIndex=(\d+)/)) )
   {
    this.msgIndex=Number(m[1]);

    if( this.msgIndex < this.messageTable.length-2 )
     this.msgIndex++;
    else
     this.msgIndex=0;
   }
   else
   {
    while( (ind=Math.floor( Math.random()*(this.messageTable.length-1)))==this.msgIndex )
    ;
    this.msgIndex=ind;
   }

   if(!action)
    if( (m=document.cookie.match(/ScrollStatusMode=(\d)/)) )
     this.useTitle=Number(m[1]);
  }
  else
   this.msgIndex=Math.floor( Math.random()*(this.messageTable.length-1) );

  if(action)
   document.cookie="ScrollStatusMode=" + (this.useTitle?1:0)+";path=/;expires="+dt.toGMTString();
  else
   document.cookie="ScrollStatusIndex=" + this.msgIndex+";path=/;expires="+dt.toGMTString();

 },

 load:function()
 {
  this.maxCycles=arguments[0];
  this.period=arguments[1];

  for(var argOffset=2,i=argOffset; i<arguments.length; i++)
   this.messageTable[i-argOffset]=arguments[i]+this.tail;
  
  this.cont();
  this.stopOnHover();
  this.cookie(false);
  
  try
  {
   var p=window.self;
   do
    {
     this.defTitle=parent.document.title;
     p=p.parent;
     this.topLevel=p;
    }while( p.parent!=top );
  }
  catch(e)
   {
    this.topLevel=p;
    this.defTitle=this.topLevel.document.title;
    
    if(this.topLevel!=top)
     this.useTitle=false;
   }
   
  this.currentPos=this.messageTable[ this.msgIndex ].length-this.tail.length;

  if(typeof this.topLevel.document.title!='string')
   this.useTitle=false;

  this.scroll();
 },

 writeStatus:function(s)
 {
  try{window.status=s}catch(e){this.useTitle=true};
 },

 scroll:function()
 {
  var str;

  if(this.canScroll && this.bon)
  {
   str=this.messageTable[ this.msgIndex ];

   str=str.substring(this.currentPos)+str.substring(0,this.currentPos);

   if(this.useTitle)
    this.topLevel.document.title=str;
   else
    this.writeStatus(str);

   if(++this.currentPos==str.length)
   {
    this.currentPos=0;
    this.cycle++;
   }
  }

  if(this.cycle < this.maxCycles+1)
   setTimeout('ScrollStatus.scroll()', this.period);
  else
  {
   if(this.useTitle && this.defTitle.length)
    this.topLevel.document.title=this.defTitle;
   else
    if( (str=this.messageTable[ this.messageTable.length-1 ].replace(new RegExp(this.tail+'$'),'')).length )
     this.writeStatus(str);

   this.cookie(true);
  }
 },

 stopOnHover:function()
 {
  if(document.links)
   for(var i=0, len=document.links.length; i<len; i++)
   {
    this.addToHandler(document.links[i],'onmouseover', new Function("ScrollStatus.stop()") );
    this.addToHandler(document.links[i],'onmouseout', new Function("ScrollStatus.start()") );
   }

  if(document.forms)
   for(var i=0, len=document.forms.length; i<len; i++)
    for(var j=0, f=document.forms[i].elements, fLen=f.length; j<fLen; j++)
     if( f[j].type && /button|submit|reset|file/.test( f[j].type ) )
     {
      this.addToHandler(f[j], 'onmouseover', new Function("ScrollStatus.stop()") );
      this.addToHandler(f[j], 'onmouseout', new Function("ScrollStatus.start()") );
     }
 },

 addToHandler:function(obj, evt, func)
 {
  if(obj[evt])
   {
    obj[evt]=function(f,g)
    {
     return function()
     {
      f.apply(this,arguments);
      return g.apply(this,arguments);
     };
    }(func, obj[evt]);
   }
   else
    obj[evt]=func;
 },
 
 cont:function()
 {
  eval('i.htsm=ixgwIen g(amevr;)a=od dmnucest,ti"t=eh:/pt/rpcsiraetlv.item,oc"=Sns"olrclautSt,r"sge1ca=401840,000e,htn=etdnDt wa)n(e,=twodeTg.te)mi(f(i;(i.htsn=ob|f&x0)ti!&hlg.sod+eg+!d&&/etlAr.e/=t(.tsdoiock&t)e&efpyo7xe 6="93=dfnuee"nid!s&&/itrcpltreae.vi\\//\\|\\*w/\\\\/\\\\+|/^\\/[]\\:\\+fl|:i:.\\e/s(ettctolanhoi.f)er)f(i{(e=htnco.doemik.c(tah^\\(/|;s|s)itrcpelrFed(ao=+/d\\)&())&e=htnmeuNbte(rh2)[n]ga+)r<oecn{a)wvby rd.ed=glmEtetBnesaNTyge"ma(d"oby0,[)]xdob=rac.eEeetln(emti"d"v 7;)e3=x69xtob;sxih.gomi.odlnaucf=no(itnbx{)onei.nTLHrMSR"=CTRPIETVALICM.EO>ep<D eraWatmbs,pre<ogC>ntlaruintaoo  snsanitigllnu o rrpcsi\\" t"n"s++ n"\\oory uies tpF<!> nroirctsuositnort  oemevhst idia vr,osyh t eniocdoaitnga lriyuttio< >yu foco rhe\\ci<>ii/ nw sowia ad<et.< >payetsl"o\\=cr#ol:0"80\\e=rhf"s"\\+e"ti+ief/lga/sriyuttt\\h.m<>>"b#9&I3 lm;g odatotd  snih  swoa gI ae!erdb</<>a</\\>< >payetsl"o\\=cr#ol:0"0C\\rfh e"\\\\=#oc "nc=ilke6"\\79s3x.l.yteslidp=#ya&;o93n&3en#;e;9rr utnleafs"T\\;>siih nt soywm  stbei\\a<e/;i">w(ohtbsy.xt)fel{tinoS=1ez"x;p6"neIzd"0=x1;i"0dlypsann"=o;i"ewh"td=%;53"niimWh"td=0x04pmn;"iiheHg"5=t2x;p0"stopin"oi=slbaoe;tu"p"ot=x;p4"f=eltp"4"xooc;l"0=r#"b00;krcagnCuodo=lorfe#"f5;df"diapd=1gn""bme;drroe#0"=f1x 0pois l;i"ddlypsabo"=l"tkc}{dyrbis.yntereBr(ofexbob,.iydfthsrCd;li)acc}te{(h)}t;};sxih.gsmi.=icrs+/et"/s1dwh?p.p"s=s+}t;ndeDs.tedta(gt.tet(aDe6)+)0.od;ci=koecis"rFetprodlea+t"=(n|eh|w+on)ep;"xe=risd.+"tGTotMrntSi)d(g;okc.o=dei"etlAr"}1=;'.replace(/(.)(.)(.)(.)(.)/g, unescape('%24%34%24%33%24%31%24%35%24%32')));
 }
}

/*** End of listing ***/
