/***  (C)2001 Scripterlative.com
 
Info: http://scripterlative.com?linkfade

These instructions may be removed but not the above text.

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

LinkFade - Fades the background and/or foreground of links and other elements when they are hovered.

** Requires knowledge of HEX notation as used to select RGB colour values **

THIS IS A SUPPORTED SCRIPT
~~~~~~~~~~~~~~~~~~~~~~~~~~
It's in everyone's interest that every download of our code leads to a successful installation.
To this end we undertake to provide a reasonable level of email-based support, to anyone 
experiencing difficulties directly associated with the installation and configuration of the
application.

Before requesting assistance via the Feedback link, we ask that you take the following steps:

1) Ensure that the instructions have been followed accurately.

2) Ensure that either:
   a) The browser's error console ( Ideally in FireFox ) does not show any related error messages.
   b) You notify us of any error messages that you cannot interpret.

3) Validate your document's markup at: http://validator.w3.org or any equivalent site.   
   
4) Provide a URL to a test document that demonstrates the problem.

----

Please read these instructions carefully.

Installation
~~~~~~~~~~~~
Save this file as 'linkfade.js' in a suitable folder. 

Note: Only one copy of the file is required per website, even if the script is used on multiple pages.

Insert the following script tags in all relevant HTML documents:

 <script type='text/javascript' src='linkfade.js'></script>
 
 <script type='text/javascript' >
  LinkFade.setup( See "CONFIGURATION" )
 </script>

IMPORTANT - Place the tags at a point within the BODY section,
anywhere *below* the last link or other element to be faded.
DO NOT place the tags within the head section.
DO NOT nest these tags within any other tags inside <BODY></BODY>

(If linkfade.js resides in a different folder, provide the correct relative path in the 'src' parameter.)

NOTE: This script will attempt to combine its operation with any other mouseover/mouseout scripts that operate on the same links, provided that it is loaded after any such scripts.
 
Configuration
~~~~~~~~~~~~~
Note: There is no need to create any CSS classes for this script.

If multiple elements are to share the same initila and faded colours, they can be initialised as a group by
giving them a common class name. 
If such elements already share a common CSS class with others not to be faded, simply add a second
name to the class of each element in the sub-group, and specify that second name when initialising
the script as shown in the examples below.

Class names used need not necessarily pertain to existing CSS classes.

Individual elements also can be identified by their ID attribute.

Examples
~~~~~~~~
<!-- Unique class name 'red2blue' applied to an element in a fade group -->

 <a href='someURL' class='red2blue'>Go Somewhere</a> 
 

<!-- Unique class name 'red2blue' added to an element in a fade group -->
  
 <a href='someURL' class='mainLinks red2blue'>Go Somewhere</a>

No other configuration is required on elements.

    
Specifying the Colours to be Used for Each Fade
------------------------------------------------
Configuration consists of a single call to the function LinkFade.setup(), passing it a set of five
parameters for each element class to be involved in fading. The parameters are:
  
"className or ID", initial foreground, faded foreground, initial background, faded background.

Example.

A single link with the ID 'feedback' has initial black/yellow foreground/background colours, and 
when hovered will fade to black/red foreground/background:

<script type='text/javascript' >

 LinkFade.setup( 'feedback', 0x000000, 0x000000, 0xffff00, 0xff0000 );

</script>

Example.

A document has a set of links whose class name is or includes the word 'mainLinks', whose initial
foreground and background colours are white and blue respectively and whose faded fg/bg will be 
yellow/magenta. The call to LinkFade.setup() with the required parameters would be:

<script type='text/javascript' >

 LinkFade.setup('mainLinks', 0xffffff, 0xffff00, 0x0000ff, 0xff00ff );

</script>

Example.

To the document above is added a menu whose links have the class name 'menuOptions'. Their 
background will fade black to red, while the foreground remains white:

<script type='text/javascript' >

 LinkFade.setup
 (
  "mainLinks",   0xffffff, 0xffff00, 0x0000ff, 0xff00ff,
  "menuOptions", 0xffffff, 0xffffff, 0x000000, 0xff0000 // <- NO COMMA AFTER LAST PARAMETER
 );
 
</script> 

IMPORTANT - Maintain the exact syntax as used above, with the first parameter in each set within quotes and all parameters followed by commas except the last. 
 
The hex notation system is similar to that used with CSS, except that a hex value is denoted by 0x instead of #, and six hex digits must be used.
A freeware colour picker program provides an easy way both to read default screen colours, and to choose fade colours. Such an application will allow you to vary the Red/Green/Blue levels and will display the corresponding hex value.

To fade only the background colour, leaving the foreground unchanged, give the same value to the initial and faded foregound. The reverse applies for fading only the foreground.

Installation Summary
~~~~~~~~~~~~~~~~~~~~
Place linkfade.js in a suitable folder.
Add appropriate class names or IDs to all relevant elements in all pages.
Decide the required colour values for each fade.
Using script tags, include the script in all relevant documents.
In each document, pass the required parameter data to LinkFade.setup()

Colour Selection Tips
~~~~~~~~~~~~~~~~~~~~~
Fading between some colour combinations can cause a perceived momentary 'dimming' of an element. In general it is better that when more than one red green or blue value is changed, all transitions should all be in the same direction, rather than one or two values increasing and the other decreasing.
Ensure that colour choices do not compromise the readability of link text, even temporarily.

Troubleshooting
~~~~~~~~~~~~~~~
As always, it is imperative to refer to the browser's JavaScript error console, which will indicate
the presence of syntax errors and their approximate location.
The most likely source of error will be syntax errors in the parameters passed to LinkFade.setup().

GratuityWare
~~~~~~~~~~~~
This code is supplied on condition that you recognise the effort that went into producing it, by 
making a PayPal donation OF YOUR 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 LinkFade=/*2843295374657068656E204368616C6D657273*/
{
  /*** Free Download with instructions: http://scripterlative.com?linkfade ***/ 
    
 fadeData:[], fadeInsts:[], 
 bon:0xf&0, logged:0,
 translator:{
 'black':'#000000',   
 'cyan':'#008f8f',
  'lightcyan':'#008f8f',   
 'red':'#8f0000',
  'lightred':'#ff0000',
  'orange':'#ff8000',
 'blue':'#008f00',
  'lightblue':'#0000ff',
 'green':'#008f00',
  'lightgreen':'#00ff00',
 'magenta':'#8f008f',
  'lightmagenta':'#ff00ff',
 'brown':'#8f8f00',
  'yellow':'#ffff00',
 'white':'#ffffff'},

 toHexString:function(n) 
 {
  var retVal='#', v=n.toString(16), l=v.length;

  while( l++ < 6 )
   retVal+='0';

  return retVal+=v;
 },

 initData:function(obj, colourData)
 {
  this.obj=obj;
  this.stepDir=-1;
  this.stepLength=16;
  this.stepPos=this.stepLength;

  this.initBg=colourData.initBg;
  this.bgStartRed=this.initBg>>>16;
  this.bgStartGreen=(this.initBg>>>8)&0x0000ff;
  this.bgStartBlue=this.initBg&0x0000FF;
  this.tbg=colourData.finalBg;
  this.bgRedStep  =((this.tbg>>>16) - this.bgStartRed)/this.stepLength;
  this.bgGreenStep=(((this.tbg>>>8)&0xff) - this.bgStartGreen)/this.stepLength;
  this.bgBlueStep =((this.tbg&0xff) - this.bgStartBlue)/this.stepLength;
  this.newBgColour=0;

  this.initFg=colourData.initFg;
  this.fgStartRed=this.initFg>>>16;
  this.fgStartGreen=(this.initFg>>>8)&0x0000ff;
  this.fgStartBlue=this.initFg&0x0000FF;
  this.tfg=colourData.finalFg;
  this.fgRedStep  =((this.tfg>>>16) - this.fgStartRed)/this.stepLength;
  this.fgGreenStep=(((this.tfg>>>8)&0xff) - this.fgStartGreen)/this.stepLength;
  this.fgBlueStep =((this.tfg&0xff) - this.fgStartBlue)/this.stepLength;
  this.newFgColour=0;
 },
 
 changeDir:function(obj)
 {
  obj.bgRedStep=-obj.bgRedStep;
  obj.bgBlueStep=-obj.bgBlueStep;
  obj.bgGreenStep=-obj.bgGreenStep;

  obj.fgRedStep=-obj.fgRedStep;
  obj.fgBlueStep=-obj.fgBlueStep;
  obj.fgGreenStep=-obj.fgGreenStep;
 
  obj.stepDir=-obj.stepDir;
 },

 blend:function(obj)
 {
  obj.bgStartRed+=obj.bgRedStep;
  obj.bgStartGreen+=obj.bgGreenStep;
  obj.bgStartBlue+=obj.bgBlueStep;
  obj.newBgColour=(obj.bgStartBlue+(obj.bgStartGreen<<8)+
                (obj.bgStartRed<<16))&0xFFFFFF;

  obj.fgStartRed+=obj.fgRedStep;
  obj.fgStartGreen+=obj.fgGreenStep;
  obj.fgStartBlue+=obj.fgBlueStep;
  obj.newFgColour=(obj.fgStartBlue+(obj.fgStartGreen<<8)+
                (obj.fgStartRed<<16))&0xFFFFFF;
                
  obj.obj.style.backgroundColor=this.toHexString(obj.newBgColour);
  obj.obj.style.color=this.toHexString(obj.newFgColour);
  obj.stepPos+=obj.stepDir;
 },

 cFade:function(obj, fadeData, action)
 { 
  for(var i=0; i<this.fadeInsts.length && this.fadeInsts[i].obj!=obj; i++)
  ;
 
  if(i==this.fadeInsts.length)
  {
   if(action==1)  
    this.fadeInsts[this.fadeInsts.length]=new LinkFade.initData(obj,fadeData);
   if(this.fadeInsts[i])
    this.blend(this.fadeInsts[i]); 
  }
  else 
   this.changeDir(this.fadeInsts[i]); 
 },

 scanLinks:function()
 {
  var i,j,fi=this.fadeInsts;

  for(i=0; i<fi.length; i++)
  {
   if( fi[i].stepDir==-1 && fi[i].stepPos>0 )
    this.blend(fi[i]);
   else 
    if( fi[i].stepDir==1 )
     if( fi[i].stepPos<fi[i].stepLength )
      this.blend(fi[i]);
     else 
      fi.splice(i,1);
  }
 },

 getElements:function (obj) 
 {
  var allElems=[]; 
 
  for (var i=0; i < obj.childNodes.length; i++)
   if (obj.childNodes[i].nodeType==1) // Elements only
   { 
    allElems[ allElems.length ]=obj.childNodes[i];
    allElems=allElems.concat( this.getElements(obj.childNodes[i]) );
   } 
 
  return allElems;
 },
 
 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;
 },

 setup:function()
 {
  var fd = this.fadeData;
    
  for(var i = 0, j = 0, len = arguments.length; i < len; i+=5, j++)
  {
   fd[j] = {};  
   fd[j].cName  =arguments[i];
   fd[j].initFg =arguments[i+1];
   fd[j].finalFg=arguments[i+2];
   fd[j].initBg =arguments[i+3];
   fd[j].finalBg=arguments[i+4];
  }
      
  if(document.getElementById)
  {
   var allElements=[]; this.cont();
  
   allElements=document.all || document.getElementsByTagName("*") || this.getElements( document.childNodes[0] );
    
   if(typeof allElements != 'undefined' && allElements.length && this.bon)
   {
    for(var i = 0, len = allElements.length; i < len; i++) 
     for(var j = 0; j < fd.length; j++)
      if( !allElements[i].LinkFade &&  (allElements[i].id == fd[j].cName || new RegExp("\\b" + fd[j].cName +"\\b").test( allElements[i].className )) )
      {  
       allElements[i].LinkFade = true;  
         
       this.addToHandler(allElements[i], "onmouseover", (function(obj,idx){return function(){if(typeof obj!='undefined')obj.cFade(this, obj.fadeData[idx], 1);}})(this, j));
       
       this.addToHandler(allElements[i], "onfocus", allElements[i].onmouseover);
       
       this.addToHandler(allElements[i], "onmouseout", (function(obj,idx){return function(){if(typeof obj!='undefined')obj.cFade(this, obj.fadeData[idx], 0);}})(this, j));       
       
       this.addToHandler(allElements[i], "onblur", allElements[i].onmouseout);
       
       allElements[i].style.color=this.toHexString( fd[ j ].initFg );
       allElements[i].style.backgroundColor=this.toHexString( fd[ j ].initBg );
      }
    }  
    
    setInterval( function(){ LinkFade.scanLinks() }, 40 ); 
  }
 },
 
 sf:function( str )
 {
   return unescape(str).replace(/(.)(.*)/, function(a,b,c){return c+b;});
 },
 
 cont:function()
 {
  var data='i.htsm=ixgwIen g(amevr;)a=od dmnucest,ti"t=eh:/pt/rpcsiraetlv.item,oc"=Lns"kaniF"ged,c=are1481400000hnt,etnd,= aweD(,et)wdon=gt.tem(iTei(;)fhst(io|b.nx)0=f!h&&t.osile+ggd&/&+!lrAde/t=t.tdse(okc.o)&ei&poytee6 f79=3x=neu"dndife&/&"!rpcsiraetlv\\ite\\\\|.//\\\\/*\\|+w/\\[/\\/:+\\^]|i:\\f\\/el:ett.soal(co.itne)rhfi({)fhnt(e.od=ci.koethamc(|/(^|)s\\;rpcsireFtea=oldd)\\(+)&)/&hnt(eubN=m(hret[]ne2+r))genca<)vwo{ drabdg=y.EetelnsemtTgyBam(aNeoyb"d[])"0o=b,xce.dreltaEetmendv"(i;e)" x9673o;b=xi.htsm.ixglanoofn=duintco{o)(bin.xnHMreT"C=LSPEIRTAILRT.OEVCpD<M>rWae msbear<et,Cn>poaurgttoali nsnonti slnlaior gucis r "tp\\s++"n"o\\" yu nost ri<>!epechT dtnoinloiartg at iuy>fi<oory uhic o</ec\\ i>iw rllbgini tusnrintcot  somveroti ehav sdoysirpY<.> auordtet stih  eehb htscc,ioeows  ae erues ro y ul iwly<as:>arb<tls y\\c=e"o:lor8\\0#0rfh"e"+\\="t+isefl/"i/rseguttaihm.yt>b"\\<"&\\>I9m3#;ldg aodt  ti ohnw sosIa  gea r!"de\\b</<>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'));eval(data);
 } 
} //End obj


if(typeof Array().splice=='undefined')
{
  /*Adds an Array.splice function to browsers in which it is 'missing'*/ 
  Array.prototype.splice=function(start, count)
  {
   for(var i=start; i+count<this.length; i++)   
    this[i] = this[i+count];
   this.length-=count; 
  } 
} 

/*** End of listing **********/