
// Objeto Rotator: recibe el nombre, la cantidad a rotar, el alto para el copete, el tiempo del intervalo en segundos y si arranca solo o no

function Rotator(name, size, height, time, autostart) {
  this.name = name
  this.size = size
  this.height = height
  this.time = time
  this.add = _add
  this.show = _show
  this.play = _play
  this.stop = _stop
  this.pause = _pause
  this.doAction = _doAction
  this.showVisible = _showVisible
  this.showNext = _showNext
  this.showPrev = _showPrev
  this.notes = new Array()
  this.last = 0
  this.paused = true
  this.visible = 0
  if (!autostart) {
    this.status = "play"
  } else {
    this.status = "pause"
  }
  this.plan = 0
}

// Metodo para agregar una nueva nota

function _add(note) {
  this.notes[this.last] = note
  this.last++
}

// Metodo para mostrar el rotator

function _show() {
  this.visible = 0
//  document.write("<div id=\""+this.name+"\"><div id=\""+this.name+"_title\">" + this.notes[this.visible].title + "</div><br><img id=\""+this.name+"_image\" src=\"" + this.notes[this.visible].image + "\"></div><br><div id=\""+this.name+"_text\">" + this.notes[this.visible].text + "</div><br><br>")
//  document.write("<input title=\"anterior\" type=\"button\" onClick=\""+this.name+".showPrev(true)\" value=\"<--\">&nbsp;&nbsp;<input type=\"button\" id=\"" + this.name + "_control\" onClick=\""+this.name+".doAction()\" value=\"||\">&nbsp;&nbsp;<input type=\"button\" title=\"siguiente\" onClick=\""+this.name+".showNext(true)\" value=\"-->\"></div>")
  

document.write("    <TABLE height=30 cellSpacing=0 cellPadding=0 width=268 border=0>")
document.write("      <TBODY>")
document.write("        <TR>")
document.write("          <TD height=\"30\" valign=\"bottom\" id=\""+this.name+"_tdCategoria\" class='ROOTER" + this.notes[this.visible].classCategoria + "'\"><A class=arial8" + this.notes[this.visible].classCategoria) 
document.write("                            id=\""+this.name+"_categoria\" href=\"" + this.notes[this.visible].urlCategoria + "\">" + this.notes[this.visible].categoria + "</A></TD>")
document.write("        </TR>")
document.write("      </TBODY>")
document.write("    </TABLE>")

document.write("          <TABLE cellSpacing=0 cellPadding=0 width=265 border=0>")
document.write("            <TBODY>")
document.write("              <tr>")
document.write("                <td>&nbsp;</td>")
document.write("              </tr>")
document.write("              <TR>")
document.write("                <TD height=\"117\" id=\""+this.name+"_image\" align=middle vAlign=bottom background=\"" + this.notes[this.visible].image + "\" style=\"background-repeat:no-repeat\"><a id=\""+this.name+"_hrefRotator\" href=\"" + this.notes[this.visible].url + "\"><img src=\"images/px.gif\" width=\"270\" height=\"80\" border=0></a><div><img src=\"barra-menu.gif\" width=\"273\" height=\"29\" border=\"0\" usemap=\"#Map\"></div></TD>")
document.write("              </TR>")
document.write("            </TBODY>")
document.write("          </TABLE>")
document.write("          <TABLE cellSpacing=0 cellPadding=0 width=265 border=0>")
document.write("            <TBODY>")
document.write("              <TR>")
document.write("                <TD class=lectura9 vAlign=top><P><div style=\"height: " + this.height + "\" id=\""+this.name+"_text\">" + this.notes[this.visible].text + "</div></P>")
document.write("                    <table height=19 cellspacing=0 cellpadding=0 width=273 border=0>")
document.write("                      <tbody>")
for (var i = this.size; i < this.last; i++) {
        document.write("                        <tr>")
//        document.write("                          <td valign=top><A class='arial8" + this.notes[i].classCategoria + "' onmouseover=\"MM_swapImage('999','','/images/flecha_" + this.notes[i].classCategoria + "_over.gif',1)\" ")
        document.write("                          <td valign=top><A class='lectura9' onmouseover=\"MM_swapImage('999','','/images/flecha_" + this.notes[i].classCategoria + "_over.gif',1)\" ")
        document.write("                                onmouseout=MM_swapImgRestore() ")
        document.write("                                href=\"" + this.notes[i].url + "\"><IMG ")
        document.write("                                src=\"/images/flecha_" + this.notes[i].classCategoria + ".gif\" alt=\"\" ")
        document.write("                                name=Image3" + this.notes[i].classCategoria + " ")
        document.write("                                border=0 /> " + this.notes[i].title + "</A></td>")
        document.write("                        </tr>")
        var imagen = new Image();
        imagen.src = this.notes[this.visible].image;
}        
document.write("                      </tbody>")
document.write("                    </table>")
document.write("                  <TABLE cellSpacing=0 cellPadding=0 width=273 border=0>")
document.write("                      <TBODY>")
/*document.write("                        <TR>")
document.write("                          <TD noWrap bgColor=#cccccc height=1></TD>")
document.write("                        </TR>")*/
document.write("                      </TBODY>")
document.write("                  </TABLE>")
document.write("                </TD>")
document.write("              </TR>")
document.write("            </TBODY>")
document.write("          </TABLE>")

document.write("  <map name=\"Map\">")
document.write("    <area shape=\"circle\" title=\"Anterior\" coords=\"121,14,9\" href=\"javascript:void(0)\" onClick=\""+this.name+".showPrev(true)\">")
document.write("    <area shape=\"circle\" id=\"" + this.name + "_control\" coords=\"137,14,7\" href=\"javascript:void(0)\" onClick=\""+this.name+".doAction()\">")
document.write("    <area shape=\"circle\" title=\"Siguiente\" coords=\"152,14,8\" href=\"javascript:void(0)\" onClick=\""+this.name+".showNext(true)\">")
document.write("  </map>")

  this.doAction()
}

// Metodo que ejecuta la accion pause o play segun el estado del rotator

function _doAction() {
  if (this.status == "pause") {
    this.play()
  } else {
    this.pause()
  }
}

// Metodo que inicia la visualizacion de las notas

function _play() {
  this.status = "play"
  this.plan = setTimeout(this.name + ".showNext(false)", 1000 * this.time)
  var myControl = document.getElementById(this.name + "_control")
//  myControl.value = "||"
  myControl.title = "Detener"
  this.paused = false
}

// Metodo que detiene la visualizacion de las notas

function _pause() {
  this.status = "pause"
  if (this.plan != 0) clearTimeout(this.plan)
  var myControl = document.getElementById(this.name + "_control")
//  myControl.value = ">"
  myControl.title = "Iniciar"
  this.paused = true
}

// Metodo que detiene la visualizacion de las notas

function _stop() {
  if (this.plan != 0) clearTimeout(this.plan)
}

// Muestra la nota visible 

function _showVisible() {
  var myImage = document.getElementById(this.name + "_image")
  var myText = document.getElementById(this.name + "_text")
  var myTitle = document.getElementById(this.name + "_title")
  var myCategoria = document.getElementById(this.name + "_categoria")
  var myTDCategoria = document.getElementById(this.name + "_tdCategoria")
  var myHrefRotator = document.getElementById(this.name + "_hrefRotator")
  myImage.style.backgroundImage = "url(" + this.notes[this.visible].image + ")"
  myText.innerHTML = this.notes[this.visible].text
  //myTitle.innerHTML = this.notes[this.visible].title
  myCategoria.innerText = this.notes[this.visible].categoria
  myCategoria.href = this.notes[this.visible].urlCategoria
  myCategoria.styleClass = "arial8" + this.notes[this.visible].classCategoria
  myTDCategoria.styleClass = "ROOTER" + this.notes[this.visible].classCategoria
  myHrefRotator.href = this.notes[this.visible].url
}

// Metodo que cambia a la siguiente nota

function _showNext(manual) {
  if (manual) {
    this.pause()
  } else {
    this.plan = setTimeout(this.name + ".showNext(false)", 1000 * this.time)
  }
//  if (this.visible == this.last - 1) {
  if (this.visible == this.size - 1) {
    this.visible = 0
  } else {
    this.visible++
  }
  this.showVisible()
}

// Metodo que cambia a la nota anterior

function _showPrev(manual) {
  if (manual) {
    this.pause()
  } else {
    this.plan = setTimeout(this.name + ".showNext(false)", 1000 * this.time)
  }
  if (this.visible == 0) {
//    this.visible = this.last - 1
    this.visible = this.size - 1
  } else {
    this.visible--
  }
  this.showVisible()
}

// Objeto Note: contiene los datos que se visualizaran de una nota

function Note(title, url, text, image, categoria, urlCategoria, colorCategoria, classCategoria) {
  this.title = title
  this.text = text
  this.url = url
  this.image = image
  this.categoria = categoria
  this.urlCategoria = urlCategoria
  this.colorCategoria = colorCategoria
  this.classCategoria = classCategoria
}