function fadecolor_colorloop()
{
   for (var i=0; i<fadecolor_objs.length; i++) fadecolor_objs[i].changecolor();
}

function fadecolor_one(id,fromRcolor,fromGcolor,fromBcolor,toRcolor,toGcolor,toBcolor,type) 
{
   this.id=id
   this.type=type;
   this.Rdirection = 0;
   this.Gdirection = 0;
   this.Bdirection = 0;
   this.fromRcolor = fromRcolor;
   this.toRcolor = toRcolor;
   this.Rcolor = fromRcolor; 
   this.fromGcolor = fromGcolor;
   this.toGcolor = toGcolor;
   this.Gcolor = fromGcolor; 
   this.fromBcolor = fromBcolor;
   this.toBcolor = toBcolor;
   this.Bcolor = fromBcolor; 
   this.changecolor=fadecolor_changecolor;
   this.setdirection=function(direction)
   {
      divi=1+Math.max(Math.abs(this.fromRcolor-this.toRcolor),Math.abs(this.fromGcolor-this.toGcolor),Math.abs(this.fromBcolor-this.toBcolor));
      if (this.fromRcolor-this.toRcolor!=0) this.Rdirection=direction/Math.abs(divi/(this.fromRcolor-this.toRcolor));
      if (this.fromGcolor-this.toGcolor!=0) this.Gdirection=direction/Math.abs(divi/(this.fromGcolor-this.toGcolor));
      if (this.fromBcolor-this.toBcolor!=0) this.Bdirection=direction/Math.abs(divi/(this.fromBcolor-this.toBcolor));
   }
}
function fadecolor_changecolor()
{
if (this.Rdirection+this.Gdirection+this.Bdirection==0) return;

   if (this.Rdirection!=0)
   if (this.fromRcolor<this.toRcolor) {
      this.Rcolor+=(this.Rdirection);
      if (this.Rdirection>0 && this.Rcolor>=this.toRcolor) {this.Rdirection=0;this.Rcolor=this.toRcolor;}
      if (this.Rdirection<0 && this.Rcolor<=this.fromRcolor) {this.Rdirection=0;this.Rcolor=this.fromRcolor;}
   } else {
      this.Rcolor-=(this.Rdirection);
      if (this.Rdirection>0 && this.Rcolor<=this.toRcolor) {this.Rdirection=0;this.Rcolor=this.toRcolor;}
      if (this.Rdirection<0 && this.Rcolor>=this.fromRcolor) {this.Rdirection=0;this.Rcolor=this.fromRcolor;}
   } 
   
   if (this.Gdirection!=0)
   if (this.fromGcolor<this.toGcolor) {
      this.Gcolor+=(this.Gdirection);
      if (this.Gdirection>0 && this.Gcolor>=this.toGcolor) {this.Gdirection=0;this.Gcolor=this.toGcolor;}
      if (this.Gdirection<0 && this.Gcolor<=this.fromGcolor) {this.Gdirection=0;this.Gcolor=this.fromGcolor;}
   } else {
      this.Gcolor-=(this.Gdirection);
      if (this.Gdirection>0 && this.Gcolor<=this.toGcolor) {this.Gdirection=0;this.Gcolor=this.toGcolor;}
      if (this.Gdirection<0 && this.Gcolor>=this.fromGcolor) {this.Gdirection=0;this.Gcolor=this.fromGcolor;}
   } 
   
   if (this.Bdirection!=0)
   if (this.fromBcolor<this.toBcolor) {
      this.Bcolor+=(this.Bdirection);
      if (this.Bdirection>0 && this.Bcolor>=this.toBcolor) {this.Bdirection=0;this.Bcolor=this.toBcolor;}
      if (this.Bdirection<0 && this.Bcolor<=this.fromBcolor) {this.Bdirection=0;this.Bcolor=this.fromBcolor;}
   } else {
      this.Bcolor-=(this.Bdirection);
      if (this.Bdirection>0 && this.Bcolor<=this.toBcolor) {this.Bdirection=0;this.Bcolor=this.toBcolor;}
      if (this.Bdirection<0 && this.Bcolor>=this.fromBcolor) {this.Bdirection=0;this.Bcolor=this.fromBcolor;}
   } 
   
   if (this.type=='bg') this.id.style.background="rgb("+Math.round(this.Rcolor)+","+Math.round(this.Gcolor)+","+Math.round(this.Bcolor)+")";
   if (this.type=='fg') this.id.style.color="rgb("+Math.round(this.Rcolor)+","+Math.round(this.Gcolor)+","+Math.round(this.Bcolor)+")";
   if (this.type=='bb') this.id.style.borderBottomColor="rgb("+Math.round(this.Rcolor)+","+Math.round(this.Gcolor)+","+Math.round(this.Bcolor)+")";
   if (this.type=='bo') this.id.style.borderColor="rgb("+Math.round(this.Rcolor)+","+Math.round(this.Gcolor)+","+Math.round(this.Bcolor)+")";
}

var fadecolor_objs=new Array();

function fadecolor_autoadd2fadecolor(idobj,fromRcol,fromGcol,fromBcol,toRcol,toGcol,toBcol,type)
{
   fadecolor_objs.push(new fadecolor_one(idobj,fromRcol,fromGcol,fromBcol,toRcol,toGcol,toBcol,type));
};

function fadecolor_fadecolor(idobj,direction,fromRcolor,fromGcolor,fromBcolor,toRcolor,toGcolor,toBcolor,type)
{
   var obj=0;
   for (var i=0; i<fadecolor_objs.length; i++)
      if (fadecolor_objs[i].id==idobj) break;
   if (i==fadecolor_objs.length) 
   {
      fadecolor_autoadd2fadecolor(idobj,fromRcolor,fromGcolor,fromBcolor,toRcolor,toGcolor,toBcolor,type);
      fadecolor_objs[i].setdirection(direction);
      return;
   }
   fadecolor_objs[i].setdirection(direction);
}

function fadecolor_init()
{
   setInterval("fadecolor_colorloop()",10);
   fadecolor_set('menu',36,1,0,0,0,236,0,0,'fg'); 
}

function fadecolor_set(classname, speed1, speed2, r1,g1 ,b1 ,r2, g2, b2, mode)   
{
   var navroot=document.getElementsByTagName('a');
   if (!navroot) return;
   if (navroot.length==0) return;
   if (speed1==0) speed1=1;
   if (speed2==0) speed2=1;
   if (speed1<0) speed1=-speed1;
   if (speed2>0) speed2=-speed2;
   for (i=0; i<navroot.length; i++) 
   {
      if (navroot[i].className==classname)
      {
         navroot[i].onmouseover=function() { fadecolor_fadecolor(this,speed1,r1,g1,b1,r2,g2,b2,mode); };
         navroot[i].onmouseout= function() { fadecolor_fadecolor(this,speed2,r1,g1,b1,r2,g2,b2,mode); };
      }   
   }   
}

function fadecolor_onloadpage(handler)
{
   if(window.addEventListener)
   {
      window.addEventListener("load",handler,false);
   }
   else if(window.attachEvent)
   {
      window.attachEvent("onload",handler);
   }
   else if(window.onload)
   {
      var oldHandler = window.onload;
      window.onload = function init()
      {
         oldHandler();
         handler();
      };
   }
   else
   {
      window.onload = handler;
   }
}
fadecolor_onloadpage(fadecolor_init);
