
function Ccol( blockSrc, colorStart, colorEnd, pause, blockDest )
{
	if( !document.getElementById( blockSrc ) ) { return false; }

	this.stopTimer			= false;
	this.blockSrc			= document.getElementById( blockSrc );
	this.pause				= ( pause && pause != ""  ) ? pause : 4000 ;
	this.colorStart			= ( colorStart && colorStart != "" ) ? colorStart : "#ffffff" ;
	this.colorEnd			= ( colorEnd && colorEnd != "" ) ? colorEnd : "#000000" ;
	this.blockDest			= ( blockDest && blockDest != "" ) ? document.getElementById( blockDest ) : this.blockSrc ;

	this.texts				= this.parser( this.blockSrc ).split( "null" );
	this._removeNode( this.blockSrc );
	this.timer("this.controler()", this.pause);
};

Ccol.prototype.controler = function()
{
	this._removeNode( this.blockDest );
	this.blockDest.appendChild( this._createNode( this.getText() ) );
	this.initFader(this.colorStart, this.colorEnd);
	this.timer('this.fader()', 50);
};

Ccol.prototype.timer = function(command, t)
{
	eval(command);
	if( !this.stopTimer ) {
		tm = this;
		window.setTimeout('tm.timer("' + command + '", ' + t + ')', t);
	} else {
		this.stopTimer = false;
	}
}

Ccol.prototype.parser = function(node)
{
	var n = node.childNodes.length;
	var str = "";
	if ( n == 0 ) { return node.nodeValue; }
	else {
		for (var i = 0; i < n; i++) { str += this.parser( node.childNodes[i] ); }
		return str;
	}
}

Ccol.prototype.initFader = function(c1, c2)
{
	this.divresultfrom = new Array(this.hexToDec(c1.substr(1,2)), this.hexToDec(c1.substr(3,2)), this.hexToDec(c1.substr(5,2)));
	this.stepRVB = new Array(
		((this.hexToDec(c2.substr(1,2))-this.divresultfrom[0])/20),
		((this.hexToDec(c2.substr(3,2))-this.divresultfrom[1])/20),
		((this.hexToDec(c2.substr(5,2))-this.divresultfrom[2])/20)
	);
	this.steps = 0;
};
	
Ccol.prototype.fader = function()
{
	this.blockDest.childNodes[0].style.color = "rgb(" + parseInt(this.divresultfrom[0]+(this.steps*this.stepRVB[0])) +","+ parseInt(this.divresultfrom[1]+(this.steps*this.stepRVB[1])) +","+ parseInt(this.divresultfrom[2]+(this.steps*this.stepRVB[2])) +")";	
	this.steps++;
	if( this.steps >= 20 ) { this.stopTimer = true; }
};

Ccol.prototype.getText = function()
{
	this.texts.push(this.texts.shift());
	return this.texts[0];
};

Ccol.prototype._createNode = function(string)
{
	elm = document.createElement( "span" );
	str = document.createTextNode( string );
	elm.style.color = this.colorStart;
	elm.appendChild( str );
	return elm;
};

Ccol.prototype._removeNode = function(node)
{
	while( node.childNodes.length > 0 ) node.removeChild( node.childNodes[0] );
};

Ccol.prototype.hexToDec = function(hex)
{
	return parseInt( hex, 16 );
};
