/**
  @author Diogo "Mr. Fogg" Goes <fileasfogg@gmail.com>
  @copyright Creative Commons Share-Alike
  @license http://creativecommons.org/licenses/by-sa/2.5/br/
  @classDescription Projetor randômico de imagens/texto
  @since 2008-04-09
  @version 1.0
*/

function projetor(e) {
 var sL = e;                                          // Slides
 var sL_t = sL.getElementsByTagName("div").length;    // total de Slides
 var iS = 0;                                          // Índice do Slide
 var tSL;                                             // temporizador dos Slides
 var time = 5000;                                     // 5 segundos de pausa 
 
 function nextSL() {
  iS++;
  return (iS >= sL_t) ? 0 : iS;
 };
 
 function changeSL(iDX, display, className){
  if (typeof(sL) != "object") { stop(); return void(0); }
   sL.getElementsByTagName("div")[iDX].style.display = display;
   sL.getElementsByTagName("li")[iDX].className = className;
 };
 
 function rotateSL() {
  changeSL(iS,"none","");
  iS = nextSL();
  changeSL(iS, "block", "ativo");
  tSL = window.setTimeout(rotateSL, time);
 }

 this.start = function () {
  changeSL(iS,"block","ativo");
  tSL = window.setTimeout(rotateSL, time);
 };

 function stop() {
  if (tSL != "")
   window.clearTimeout(tSL);
  tSL = "";
 };
  
 this.readingSL = function (iDX) {
  stop(); 
  for (i = 0; i < sL_t; i++) {
   changeSL(i, "none", "");
  }
  changeSL(iDX, "block", "ativo");
  iS = iDX;
  tSL = window.setTimeout(rotateSL, time*2);
 };
}
