// JavaScript Document
/***********************************************
* 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 = 5000; //set delay between message change (in miliseconds)
var maxsteps=30; // 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(255,255,255); // start color (red, green, blue)
var endcolor=new Array(0,0,0); // end color (red, green, blue)

var fcontent=new Array();
begintag=''; //set opening tag, such as font declarations
fcontent[0]="<span>Central Vermont Construction, Inc. did an outstanding job for us in replacing our roof.  We called 5 contractors for quotes and chose Central Vermont Construction, Inc. because their customer service was better than the competition. We are completely satisfied with our experience and highly recommend their services.</span><strong>Dave & Kim F.<br />Hinesburg, VT.</strong>";
fcontent[1]="<span>Thank you so much for the fabulous job your crew did on our house. Our roof looks great and we could not have been more pleased with your team. Professional, kind and considerate. We will recommend your company happily!!</span><strong>The Pruitts<br />Montpelier, VT<br />November 9, 2007</strong>";
fcontent[2]="<span>Just a note to let you know how impressed we are with your company. The communication, quality and scheduling have all been topnotch. We\'ve all enjoyed working with all of you.</span><strong>Jen and Dan M.<br />Putnamville, VT</strong>";
fcontent[3]="<span>Great Job. We are very pleased. It\'s great to deal with a contractor that shows up when they said they would and does a professional job.</span><strong>Jim and Donna F.<br />Montpelier, VT</strong>";
fcontent[4]="<span>You are an amazing team. The new roofs are wonderful and your guys did a great job-they even cleaned up. Thank you so very much!</span><strong>Jen T.<br />Barre, VT.</strong>";
fcontent[5]="<span>My family and I want to thank you very much for the nice job you did sealing my driveway. It looks so nice.</span><strong>Donna C.<br />Montpelier, VT<br /></strong>";
fcontent[6]="<span>My driveway was done yesterday...it looks GREAT! I asked some questions as they worked...all very helpful & explained their work. They're expertise & talents are surprisingly good. I watched it all develop in about 2 hrs. The wait was definitely worth it. Thanks again for the great pave job.</span><strong>John</strong>";
fcontent[7]="<span>Happy with both the driveway and roof. Your roofing crew did an exceptional job moving items out of the way, safety considerations, and left the place immaculate. You'd never know they were there!</span><strong>Ed P.</strong>";
fcontent[8]="<span>..I was immediately able to reach Mike, who stated he would take my information and get back to me with a response time. You did as promised. Your foreman Joe quickly assessed the problem and set into motion an immediate plan to solve my roofing emergency. Joe was very professional, honest with great attention to detail and accuracy. He is clearly a very skilled and gifted craftsmen.</span><strong>Mike - Duxbury, VT</strong>";
closetag='';
;

var fwidth='100%'; //set scroller width
var fheight='187px'; //set scroller height

var fadelinks=1;  //should links inside scroller content also fade like text? 0 for no, 1 for yes.

///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(){
  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);
  }
  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){
  var obj=document.getElementById("fscroller").getElementsByTagName("A");
  if (obj.length>0){
    for (i=0;i<obj.length;i++)
      obj[i].style.color=getstepcolor(step);
  }
}

/*Rafael Raposo edited function*/
var fadecounter;
function colorfade(step) {
  if(step<=maxsteps) {	
    document.getElementById("fscroller").style.color=getstepcolor(step);
    if (fadelinks)
      linkcolorchange(step);
    step++;
    fadecounter=setTimeout("colorfade("+step+")",stepdelay);
  }else{
    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) {
  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/maxsteps))*step);
    } else {
      newcolor[i] = startcolor[i]+(Math.round((Math.abs(diff)/maxsteps))*step);
    }
  }
  return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
}

if (ie4||DOM2)
  document.write('<div id="fscroller" style="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