/*******************************************************************************
 * 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 FadingScroller(objName, idControl) {
	this.name = objName;
	this.idControl = idControl;
	this.control = document.getElementById(this.idControl);
	this.delay = 2000; // set delay between message change (in miliseconds)
	this.maxsteps = 30; // number of steps to take to change from start color to
						// endcolor
	this.stepdelay = 40; // time in miliseconds of a single step
	// **Note: maxsteps*stepdelay will be total time in miliseconds of fading
	// effect
	this.startcolor = new Array(255, 255, 255); // start color (red, green,
												// blue)
	this.endcolor = new Array(0, 0, 0); // end color (red, green, blue)
	this.fcontent = new Array();
	this.begintag = '<div>'; // set opening tag, such as font declarations
	this.closetag = '</div>';
	this.fadelinks = 1;// should links inside scroller content also fade like
						// text? 0 for no, 1 for yes.
	this.faderdelay = 0;
	this.index = 0;
	this.fadecounter;
	this.ie4 = document.all && !document.getElementById;
	this.DOM2 = document.getElementById;

	this.addcontent = function(content) {

		this.fcontent.push(content);
	}

	/* Rafael Raposo edited function */
	this.changecontent = function() {

		if (this.index >= this.fcontent.length)
			this.index = 0
			
		if (this.DOM2) {
			this.control.style.color = "rgb(" + this.startcolor[0] + ", "
					+ this.startcolor[1] + ", " + this.startcolor[2] + ")"
			this.control.innerHTML = this.begintag + this.fcontent[this.index]
					+ this.closetag
										
			if (this.fadelinks) {
				this.linkcolorchange(1);
			}

			this.colorfade(1, 15);
		} else if (this.ie4)
			this.control.innerHTML = this.begintag + this.fcontent[this.index]
					+ this.closetag;
		this.index++
		
	}

	// colorfade() partially by Marcio Galli for Netscape Communications.
	// ////////////
	// Modified by Dynamicdrive.com

	this.linkcolorchange = function(step) {
		var obj = this.control.getElementsByTagName("A");
		if (obj.length > 0) {
			for (i = 0; i < obj.length; i++)
				obj[i].style.color = this.getstepcolor(step);
		}
	}

	/* Rafael Raposo edited function */

	this.colorfade = function(step) {
		if (step <= this.maxsteps) {
			this.control.style.color = this.getstepcolor(step);
			if (this.fadelinks)
				this.linkcolorchange(step);
			step++;
			this.fadecounter = setTimeout(this.name + ".colorfade(" + step
					+ ")", this.stepdelay);
		} else {
			clearTimeout(this.fadecounter);
			this.control.style.color = "rgb(" + this.endcolor[0] + ", "
					+ this.endcolor[1] + ", " + this.endcolor[2] + ")";
			setTimeout(this.name + ".changecontent()", this.delay);
		}
	}

	/* 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] + ")");
	}
}
