/***********************************************
* Fading Scroller- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
function cFadeScroller( strOutputDivID, intDelay, intMaxSteps, intStepDelay,
	intStartColorRed, intStartColorGreen, intStartColorBlue,
	intEndColorRed, intEndColorGreen, intEndColorBlue,
	strXmlData
	 )
{
	this.m_strOutputDivID = strOutputDivID;
	this.m_ctrlOutputDiv = null;
	this.delay = intDelay; //set delay between message change (in miliseconds)
	this.maxsteps = intMaxSteps; // number of steps to take to change from start color to endcolor
	this.stepdelay = intStepDelay; // time in miliseconds of a single step
	//**Note: maxsteps*stepdelay will be total time in miliseconds of fading effect
	this.startcolor = new Array(intStartColorRed,intStartColorGreen,intStartColorBlue);
	this.endcolor = new Array(intEndColorRed,intEndColorGreen,intEndColorBlue);
	this.m_strXmlData = strXmlData;
	this.m_intCountItems = 0;

	this.fcontent=new Array();

	this.fadelinks=1;  //should links inside scroller content also fade like text? 0 for no, 1 for yes.

	///No need to edit below this line/////////////////
	this.ie4=document.all&&!document.getElementById;
	this.DOM2=document.getElementById;
	this.faderdelay=0;
	this.index=0;

	/*Rafael Raposo edited function*/
	//function to change content
	this.changecontent = function()
	{
		var strContent;

		if (this.index>=this.fcontent.length)
			this.index=0;

		if( this.m_intCountItems > 0 )
		{
			strContent = this.fcontent[this.index];
		}
		else
		{
			strContent = ' ';
		}

        // Prevent flicker effect??
        this.m_ctrlOutputDiv.style.color=this.getstepcolor(0);
		var valOpacity = this.getstepopacity(0);
		this.m_ctrlOutputDiv.style.opacity = valOpacity;

		if (this.DOM2)
		{
			this.m_ctrlOutputDiv.style.color="rgb("+this.startcolor[0]+", "+this.startcolor[1]+", "+this.startcolor[2]+")";
			this.m_ctrlOutputDiv.innerHTML = strContent;
			if (this.fadelinks) this.linkcolorchange(1);
			this.colorfade( 1 );
		}
		else if (this.ie4)
		{
			this.m_ctrlOutputDiv.innerHTML = strContent;
		}

		this.index++;
	};

	// colorfade() partially by Marcio Galli for Netscape Communications.  ////////////
	// Modified by Dynamicdrive.com
	this.linkcolorchange = function(step)
	{
		var obj=this.m_ctrlOutputDiv.getElementsByTagName("A");
		if (obj.length>0){
			for (i=0;i<obj.length;i++)
			obj[i].style.color=this.getstepcolor(step);
		}
	};

	this.recurseSetAlpha = function( parent, intOpacity )
	{
		if( parent.children )
		{
			for( var i=0; i < parent.children.length; i++ )
			{
				parent.style.filter = 'alpha(opacity=' + intOpacity + ')'; 
				this.recurseSetAlpha( parent.children[i], intOpacity );
			}
		}
	}


	/*Rafael Raposo edited function*/
	this.fadecounter;
	this.colorfade = function(step) 
	{
		if(step<=this.maxsteps) 
		{
			this.m_ctrlOutputDiv.style.color=this.getstepcolor(step);
			// Added this to make images fade in
			var valOpacity;

			valOpacity = this.getstepopacity(step);
			this.m_ctrlOutputDiv.style.opacity = valOpacity;

			var valFilterOpacity = valOpacity * 100.0;
			this.recurseSetAlpha( this.m_ctrlOutputDiv, valFilterOpacity );

			if (this.fadelinks)
				this.linkcolorchange(step);
			step++;
			this.fadecounter=setTimeout(this.selfName+".colorfade(" + step + ")",this.stepdelay);
		}
		else
		{
			if( this.m_intCountItems > 1 )
			{
				clearTimeout(this.fadecounter);
        		this.m_ctrlOutputDiv.style.color="rgb("+this.endcolor[0]+", "+this.endcolor[1]+", "+this.endcolor[2]+")";
				setTimeout(this.selfName+".changecontent()", this.delay);
			}
		}
	};

	/* Mitzi's new function */
	this.getstepopacity = function(step)
	{
		var diff = 1.0;

		return newopacity = (diff/this.maxsteps) * step;
	}

	/*Rafael Raposo's new function*/
	this.getstepcolor = function(step) 
	{
		var diff;
		var newcolor=new Array(3);
		for(var i=0;i<3;i++) 
		{
			diff = (this.startcolor[i]-this.endcolor[i]);
			if(diff > 0) 
			{
				newcolor[i] = this.startcolor[i]-(Math.round((diff/this.maxsteps))*step);
			} 
			else 
			{
				newcolor[i] = this.startcolor[i]+(Math.round((Math.abs(diff)/this.maxsteps))*step);
			}
		}
		return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
	};

	// Function that runs when the page loads
	this.onLoad = function()
	{
		this.m_ctrlOutputDiv = document.getElementById( this.m_strOutputDivID );

		var result = SharedUL.parseXML( this.m_strXmlData );
		var objThis = this;
		var objRoot = result.firstChild;
		if( objRoot != null )
		{
			var objNodes = objRoot.getElementsByTagName( "item" );
			this.m_intCountItems = objNodes.length;
			for( ii = 0; ii < this.m_intCountItems; ii++ )
			{
				this.fcontent[ii] = objNodes[ii].firstChild.nodeValue;
			}
			this.changecontent();
		}
	};
	
	return this;
}
