/***********************************************
* 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
***********************************************/

var delay = 2000; //set delay between message change (in miliseconds)
var fadeInUntil = 20; // number of steps for fade in stage
var displayUntil = 60; // number of steps for image to be displayd
var maxSteps=80; // number of steps to take to change from start color to endcolor
var stepdelay=100; // time in miliseconds of a single step
//**Note: maxsteps*stepdelay will be total time in miliseconds of fading effect
var startcolor= new Array(0, 149, 218); // start color (red, green, blue)
var endcolor=new Array(0,0,0); // end color (red, green, blue)

var fcontent=new Array();
begintag='<div style="font: normal 12px Arial; padding: 5px;">'; //set opening tag, such as font declarations
fcontent[0]="<p>Did you know? There are four strokes in competitive swimming; freestyle, breaststroke, backstroke, and butterfly.</p>";
fcontent[1]="<p>Did you know? Swimming has been included in the Olympic Games since 1896 for men and 1912 for women.</p>";
fcontent[2]="<p>Did you know? Distances of races vary between 25 and 1,500 metres.</p>";
fcontent[3]="<p>Did you know? There are numerous references to swimming in Greek and Roman history and races were held in Japan as early as the 17th century.</p>";
fcontent[4]="<p>Did you know? Olympic-size pools are 50 m/55 yd long and have eight lanes.</p>";
fcontent[5]="<p>Did you know? In 2500 BC the Egyptians produced the first hieroglyphics which featured swimming.</p>";
fcontent[6]="<p>Did you know? The Amateur Swimming Association is the English national governing body for swimming, diving, water polo, open water and synchronised swimming.</p>";
fcontent[7]="<p>Did you know? The Paris Olympics involved races up the Seine, one where the point was to swim the whole distance under water!</p>";
fcontent[8]="<p>Did you know? On 24 August 1875, Captain Matthew Webb became the first person to swim the English Channel. He made the historic crossing in 21 hours 40 minutes.</p>";
fcontent[9]="<p>Did you know? The freestyle stroke (also known as front crawl) is the fastest stroke. It was developed by Australians from a South Sea island technique in the early 20th century.</p>";
closetag='</div>';

var fwidth='130px'; //set scroller width
var fheight='150px'; //set scroller height

var fadelinks=0;  //should links inside scroller content also fade like text? 0 for no, 1 for yes.

var debug = 0;
///No need to edit below this line/////////////////


var ie4=document.all&&!document.getElementById;
var DOM2=document.getElementById;
var faderdelay=0;
var index=0;


/*Rafael Raposo edited function*/
//function to change content
function changecontent(){
log("changeContent: index="+index);
  if (index>=fcontent.length)
    index=0
  if (DOM2){
    document.getElementById("fscroller").style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")"
    document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag
    if (fadelinks)
      linkcolorchange(1);
      
//    colorfade(1, 15);
      colorfade(1);
  }
  else if (ie4)
    document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag;
  index++
}

// colorfade() partially by Marcio Galli for Netscape Communications.  ////////////
// Modified by Dynamicdrive.com

function linkcolorchange(step, fadeSteps){
log("linkcolorchange");
  var obj=document.getElementById("fscroller").getElementsByTagName("A");
  if (obj.length>0){
    for (i=0;i<obj.length;i++)
      obj[i].style.color=getstepcolor(step, fadeSteps);
  }
}

/*Rafael Raposo edited function*/
var fadecounter;
function colorfade(step) {
//log("Check colour fade step="+step);
  if(step<fadeInUntil) {
  	// Fading in
	document.getElementById("fscroller").style.color=getstepcolor(step, fadeInUntil);
    	if (fadelinks)
      		linkcolorchange(step, fadeInUntil);
    	step++;
    	fadecounter=setTimeout("colorfade("+step+")",stepdelay);
  } else if (step<displayUntil) {
  	// Display
    	document.getElementById("fscroller").style.color=getstepcolor(1, 1);
    	step++;
    	fadecounter=setTimeout("colorfade("+step+")",stepdelay);
  } else if(step<=maxSteps) {
log("Fade out: step="+step);
  	// Fade out
    	document.getElementById("fscroller").style.color=getstepcolor(maxSteps-step, maxSteps-displayUntil);
    	if (fadelinks)
      		linkcolorchange(maxSteps-step, maxSteps-displayUntil);
    	step++;
    	fadecounter=setTimeout("colorfade("+step+")",stepdelay);
  }else{
log("Next message");
  	// Swap message
	clearTimeout(fadecounter);
//    	document.getElementById("fscroller").style.color="rgb("+endcolor[0]+", "+endcolor[1]+", "+endcolor[2]+")";
    	setTimeout("changecontent()", delay);
	
  }   
}

/*Rafael Raposo's new function*/
function getstepcolor(step, fadeSteps) {
log("getstepcolor: Step = " + step + ", fadeSteps = " + fadeSteps);
  var diff
  var newcolor=new Array(3);
  for(var i=0;i<3;i++) {
    diff = (startcolor[i]-endcolor[i]);
    if(diff > 0) {
      newcolor[i] = startcolor[i]-(Math.round((diff/fadeSteps))*step);
    } else {
      newcolor[i] = startcolor[i]+(Math.round((Math.abs(diff)/fadeSteps))*step);
    }
  }
  return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
}

function log(text) {
if (debug == 1) {
	if (confirm(text + " : Ok to stop debug")) debug = 0;
}
}

function fadeScroller() {
	if (ie4||DOM2)
		document.write('<div id="fscroller" style="border:0px solid black;width:'+fwidth+';height:'+fheight+'"></div>');

	if (window.addEventListener)
		window.addEventListener("load", changecontent, false)
	else if (window.attachEvent)
		window.attachEvent("onload", changecontent)
	else if (document.getElementById)
		window.onload=changecontent
}

