/***********************************************
* 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 = 8000; //set delay between message change (in miliseconds)
var maxsteps=30; // number of steps to take to change from start color to endcolor
var stepdelay=20; // 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(85,85,85); // end color (red, green, blue)

// PSR ADD_CODE ->
var startcolorTitle= new Array(255,255,255); // start color (red, green, blue)
var endcolorTitle=new Array(233,93,15); // PSR couleur: orange // end color (red, green, blue)

var startcolorLink= new Array(255,255,255); // start color (red, green, blue)
var endcolorLink=new Array(1,123,147); // PSR couleur: bleu // end color (red, green, blue)
// PSR ADD_CODE <-



var fcontent=new Array();
begintag='<div style="font: normal 14px Arial; padding: 5px;">'; //set opening tag, such as font declarations
begintag=''; // PSR

// fcontent[0]="<b>What\'s new?</b><br>New scripts added to the Scroller category!<br><br>The MoreZone has been updated. <a href='../morezone/index.htm'>Click here to visit</a>";
// fcontent[1]="Dynamic Drive has been featured on Jars as a top 5% resource, and About.com as a recommended DHTML destination.";
// fcontent[2]="Ok, enough with these pointless messages. You get the idea behind this script.</a>";

// fcontent[0]=document.getElementById("actu_une_n0").innerHTML;
// fcontent[1]=document.getElementById("actu_une_n1").innerHTML;
// fcontent[2]=document.getElementById("actu_une_n2").innerHTML;
// fcontent[3]=document.getElementById("actu_une_n3").innerHTML;

// fcontent[2]="2_Ok, enough with these pointless messages. You get the idea behind this script.</a>";
// fcontent[3]="3_Ok, enough with these pointless messages. You get the idea behind this script.</a>";
// fcontent[4]="4_Ok, enough with these pointless messages. You get the idea behind this script.</a>";

// PSR ADD_CODE : Init content  ->
for (i=0;i<infoCounter;i++)
  fcontent[i]=document.getElementById("actu_une_n"+i).innerHTML;
// PSR ADD_CODE <-


closetag='</div>';
 closetag='';// PSR

var fwidth='150px'; //set scroller width
var fheight='150px'; //set scroller height

var fadelinks=1;  //should links inside scroller content also fade like text? 0 for no, 1 for yes.
var fadeTitle=1;  // PSR ADD_CODE //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){

		// Mise a jour des couleurs par CCS
    // document.getElementById("fscroller").style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")" // PSR
    document.getElementById("actu_une_n0").style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")";  // PSR

		// Insertion contenu HTML dans le premier element de la liste Actu Une
    // document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag  // PSR
    document.getElementById("actu_une_n0").innerHTML=begintag+fcontent[index]+closetag;  // PSR

    if (fadelinks)
       linkcolorchange(1);

    if (fadeTitle)         // PSR ADD_CODE
      titlecolorchange(1);  // PSR ADD_CODE

    colorfade(1, 15); // PSR
    // colorfade(0, 15); // PSR

  }
  else if (ie4) {
    // document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag;  // PSR
    document.all.actu_une_n0.innerHTML=begintag+fcontent[index]+closetag;  // PSR
  }
  index++
}

// colorfade() partially by Marcio Galli for Netscape Communications.  ////////////
// Modified by Dynamicdrive.com

function linkcolorchange(step){
  // var obj=document.getElementById("fscroller").getElementsByTagName("A"); // PSR
 var obj=document.getElementById("actu_une_n0").getElementsByTagName("A");  // PSR

  if (obj.length>0){
    for (i=0;i<obj.length;i++)
      obj[i].style.color=getstepcolor(step);
  }
}

// PSR ADD_CODE ->
function titlecolorchange(step){
  // var obj=document.getElementById("fscroller").getElementsByTagName("A"); // PSR
 // var obj=document.getElementById("actu_une_n0").getElementsByTagName("A");  // PSR
var obj=document.getElementById("actu_une_n0").getElementsByTagName("DIV")[0].getElementsByTagName("DIV")[0];
var obj2=document.getElementById("actu_une_n0").getElementsByTagName("DIV")[0].getElementsByTagName("DIV")[2].getElementsByTagName("A")[0];

	// Titre Actu Une
	obj.style.color=getstepcolorTitle(step,'title');

	// Lien en savoir plus Actu Une
	obj2.style.color=getstepcolorTitle(step,'link');

  // if (obj.length>0){
  // 	alert('obj='+obj);
  //   for (i=0;i<obj.length;i++)
  //     obj[i].style.color=getstepcolor(step);
  //  }
}
// PSR ADD_CODE <-


function resetColor() {
    // Ajouter pour probleme de couleur de debut a la valeur de celle de fin
    document.getElementById("actu_une_n0").style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")";  // PSR
}

function resetLinkColor() {
    // Ajouter pour probleme de couleur de debut a la valeur de celle de fin
  var obj=document.getElementById("actu_une_n0").getElementsByTagName("A");  // PSR
  if (obj.length>0){
    for (i=0;i<obj.length;i++)
      obj[i].style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")";
  }
}

function resetTitleColor() {
    // Ajouter pour probleme de couleur de debut a la valeur de celle de fin
    // var obj=document.getElementById("actu_une_n0").getElementsByTagName("A");  // PSR
	 var obj=document.getElementById("actu_une_n0").getElementsByTagName("DIV")[0].getElementsByTagName("DIV")[0];
	 var obj2= document.getElementById("actu_une_n0").getElementsByTagName("DIV")[0].getElementsByTagName("DIV")[2].getElementsByTagName("A")[0];

	// Titre Actu Une
	obj.style.color="rgb("+startcolorTitle[0]+", "+startcolorTitle[1]+", "+startcolorTitle[2]+")";

	// Lien en savoir + Actu Une
	obj2.style.color="rgb("+startcolorLink[0]+", "+startcolorLink[1]+", "+startcolorLink[2]+")";


  // if (obj.length>0){
  //   for (i=0;i<obj.length;i++)
  //     obj[i].style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")";
  // }
}


/*Rafael Raposo edited function*/
var fadecounter;
var fadecounter1;
var fadecounter2;
var fadecounter3;
var fadecounter4; // PSR ADD_CODE

function colorfade(step) {
  if(step<=maxsteps) {
     // document.getElementById("fscroller").style.color=getstepcolor(step); // PSR
     document.getElementById("actu_une_n0").style.color=getstepcolor(step);   // PSR
    if (fadelinks)
       linkcolorchange(step);

    // PSR ADD_CODE ->
    if (fadeTitle)
      titlecolorchange(step);
    // PSR ADD_CODE <-

    step++;
    fadecounter=setTimeout("colorfade("+step+")",stepdelay);
  }else{

    clearTimeout(fadecounter);

    // document.getElementById("fscroller").style.color="rgb("+endcolor[0]+", "+endcolor[1]+", "+endcolor[2]+")"; // PSR
    document.getElementById("actu_une_n0").style.color="rgb("+endcolor[0]+", "+endcolor[1]+", "+endcolor[2]+")";  // PSR

    if(infoCounter>1) {
      fadecounter1=setTimeout("changecontent()", delay);
      fadecounter2=setTimeout("resetColor()", 7950);
      fadecounter3=setTimeout("resetLinkColor()", 7950); // fonctionne pas compltement Ajout couleur start dans CSS
      fadecounter4=setTimeout("resetTitleColor()", 7950); // PSR ADD_CODE// fonctionne pas compltement Ajout couleur start dans CSS
    }
  }
}


var flagRestart;
var restartcounter;

function stopChangecontent () {
  // alert('stopChangecontent');

  clearTimeout(fadecounter);
  document.getElementById("actu_une_n0").style.color="rgb("+endcolor[0]+", "+endcolor[1]+", "+endcolor[2]+")";  // PSR
  clearTimeout(fadecounter1);
  clearTimeout(fadecounter2);
  clearTimeout(fadecounter3);
  clearTimeout(fadecounter4); // PSR ADD_CODE
  clearTimeout(restartcounter);
  // flagRestart=0;
}

function armRestart() {
    flagRestart = 1;
    restartcounter=setTimeout("restartChangecontent()", 1000);
}


function restartChangecontent() {
    // alert('restartChangecontent');
    // if (flagRestart) {
      // alert('restartChangecontent');

      // index++;
      fadecounter1=setTimeout("changecontent()", 500);
      fadecounter2=setTimeout("resetColor()", 400);
      fadecounter3=setTimeout("resetLinkColor()", 400); // fonctionne pas compltement Ajout couleur start dans CSS
      fadecounter4=setTimeout("resetTitleColor()", 400); // PSR ADD_CODE// fonctionne pas compltement Ajout couleur start dans CSS
    // }
}


/*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] + ")");
}

// PSR ADD_CODE ->
function getstepcolorTitle(step,zone) {
  var diff
  var newcolor=new Array(3);

	if(zone=='title') {
		for(var i=0;i<3;i++) {
			diff = (startcolorTitle[i]-endcolorTitle[i]);
			if(diff > 0) {
				newcolor[i] = startcolorTitle[i]-(Math.round((diff/maxsteps))*step);
			} else {
				newcolor[i] = startcolorTitle[i]+(Math.round((Math.abs(diff)/maxsteps))*step);
			}
		}
	}
	if(zone=='link') {
		for(var i=0;i<3;i++) {
			diff = (startcolorLink[i]-endcolorLink[i]);
			if(diff > 0) {
				newcolor[i] = startcolorLink[i]-(Math.round((diff/maxsteps))*step);
			} else {
				newcolor[i] = startcolorLink[i]+(Math.round((Math.abs(diff)/maxsteps))*step);
			}
		}
	}
  return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
}
// PSR ADD_CODE <-



if (ie4||DOM2) {
  // document.write('<div id="fscroller" style="border:1px solid black;width:'+fwidth+';height:'+fheight+'"></div>'); // PSR
}

if (window.addEventListener) {
  window.addEventListener("load", changecontent, false)
  // window.addEventListener("mouseover", stopChangecontent, false)
  // window.addEventListener("mouseout", armRestart, false)

}
else if (window.attachEvent) {
  window.attachEvent("onload", changecontent)
  // window.attachEvent("onmouseover", stopChangecontent)
}
else if (document.getElementById) {
  window.onload=changecontent
  // window.onmouseover=stopChangecontent
}

document.getElementById('actu_une_n0').onmouseover = stopChangecontent ;
document.getElementById('actu_une_n0').onmouseout = armRestart ;
