function cColorFader(StartRed, StartGreen, StartBlue, EndRed, EndGreen, EndBlue)
{
	this.StartRed	 	= StartRed;
	this.StartGreen	= StartGreen;
	this.StartBlue 	= StartBlue;
	this.EndRed 		= EndRed;
	this.EndGreen 	= EndGreen;
	this.EndBlue 		= EndBlue;
	
	this.steps = 40;
  this.speed = 10;
	
	this.aGoColorTimers = new Array();
	this.MouseOutTimer = null;
	this.bFadingIn = false;
}

cColorFader.prototype.FadeOut = function(obj)
{
	var _this = this;
  this.MouseOutTimer = setTimeout(function() { _this.FadeOutEx(obj) }, 400);
}

cColorFader.prototype.FadeOutEx = function(obj)
{
	this.bFadingIn = false;
	this.ClearTimers();
	this.Fade(obj, this.EndRed, this.EndGreen, this.EndBlue, this.StartRed, this.StartGreen, this.StartBlue);
}

cColorFader.prototype.FadeIn = function(obj)
{
	clearTimeout(this.MouseOutTimer);
	if(this.bFadingIn) {
	} else {
		this.bFadingIn = true;
		this.ClearTimers();
		this.Fade(obj, this.StartRed, this.StartGreen, this.StartBlue, this.EndRed, this.EndGreen, this.EndBlue);
	}
}

cColorFader.prototype.ClearTimers = function()
{
	for(var i = 0; i < this.aGoColorTimers.length; i++)
	{
		clearTimeout(this.aGoColorTimers[i]);	
	}
	this.aGoColorTimers = new Array();
}

cColorFader.prototype.Fade = function(obj, StartRed, StartGreen, StartBlue, EndRed, EndGreen, EndBlue, cbWhenDone)
{
  var steps = this.steps;
  var speed = this.speed;
  var bUp = true;
  if(EndRed < StartRed)
  {
  	bUp = false;
  }
  
   var EndColor = "rgb("+EndRed+", "+EndGreen+", "+EndBlue+")";
  //debug(obj.style.color.replace(/ /g, ""));
  if(obj.style.color.replace(/ /g, "") == EndColor.replace(/ /g, "")) {
  	this.bFadingIn = false;
  	return;
  }
  
  var redint 		= Math.round(Math.abs(StartRed		-	EndRed)/steps);
  var greenint 	= Math.round(Math.abs(StartGreen	-	EndGreen)/steps);
  var blueint 	= Math.round(Math.abs(StartBlue  -	EndBlue)/steps);
  if(redint == 0) { redint = 1 }
  if(greenint == 0) { greenint = 1 }
  if(blueint == 0) { blueint = 1 }
  //obj.style.color = 'rgb(' + StartRed+ ',' + StartGreen + ',' + StartBlue + ')';
  for(var tCounter = 0; tCounter <= steps; tCounter++)
  { 
  	if(bUp) {
  		this.GoColor(obj, (StartRed + (tCounter * redint)), (StartGreen + (tCounter * greenint)), (StartBlue + (tCounter * blueint)), (tCounter * speed));  
  	} else {
  		this.GoColor(obj, (StartRed - (tCounter * redint)), (StartGreen - (tCounter * greenint)), (StartBlue - (tCounter * blueint)), (tCounter * speed));  
  	}
  }
  this.aGoColorTimers.push(setTimeout( function() { ConvertColor(obj, 'rgb(' + EndRed+ ',' + EndGreen + ',' + EndBlue + ')'); }, steps * speed));
}

cColorFader.prototype.GoColor = function(obj, ColorRed, ColorGreen, ColorBlue, TimeOut)
{
	this.aGoColorTimers.push(setTimeout( function() { ConvertColor(obj, 'rgb(' + ColorRed+ ',' + ColorGreen + ',' + ColorBlue + ')'); }, TimeOut));
}

function ConvertColor(target, FontColor) 
{
	target.style.color = FontColor;
	var aSub = target.childNodes;
  	if(aSub.length > 0) {
  	 for(var i = 0; i < aSub.length; i++) {
  		 if(aSub[i].nodeType == 1) {
  		   if(aSub[i].nodeName == 'A') {
  		     aSub[i].style.borderColor = FontColor;     
  		   } 
  		   ConvertColor(aSub[i], FontColor);
  		 }
  	  }
  	}
}


function debug(value)

{

  document.getElementById("debug").innerHTML += value + "<br />";

}
