// presenta.js
// 11-10-2006
// Custom array object
function array(n) {
   for (var i =1; i <= n; i++) {
      this[i] = ""
   }
   this.length = n
   return this

}

// Custom button object
function click() {
  /*
   * Description: Method of button. Executes command for this button.
   * Arguments: None.
   */
   eval(this.command)
}

function button(name, file, alt, url, spacer, condition, command) {
  /*
   * Description: button object.
   * Arguments: 
   *   name - The name used as this button's HTML element name.
   *   file - The button image's source url.
   *   alt  - The alt attribute for the button.
   *   url - The url which can reference(across frames) the
   *         buttonSet that holds this button.
   *   spacer - number of pixels of horizontal spacing used
   *            after the button being added.
   *   condition - conditional statement that determines
   *               whether or not to display this button.
   *   commmand - The command to be executed by this button.
   */
   // Properties
   this.name = name
   this.file = file
   this.alt = alt
   this.url = url
   this.spacer = spacer
   this.condition = condition
   this.command = command
   // Methods
   this.click = click
   return this
}

// Custom buttonSet object
function print(dObj) {
  /*
   * Description: Method of buttonSet object.
   * Arguments: dObj - document object receiving buttonSet.
   */
   this.isBusy = true
   var spaceInt
   var DQUOTE = '\"'
   var topBase = ""
   var basePath = ""+window.location.pathname
   var baseDir = ""
   var baseFile = basePath.substring(basePath.length-10,basePath.length)

   baseDir = basePath.substring(0,basePath.length-12)
   topBase=window.location.protocol+"//"+window.location.host+baseDir

   dObj.open()
   dObj.bgColor = parent.frames[0].document.bgColor
   dObj.writeln('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">')
   dObj.writeln('<html><head>')
   dObj.writeln('<title>Toolbar</title>')
   dObj.writeln('<BASE href = '+DQUOTE+topBase+DQUOTE+'>')
   dObj.writeln('<SCRIPT LANGUAGE="JavaScript">')
   dObj.writeln('</SCRIPT>')
   dObj.writeln('</head>')
   dObj.writeln('<body bgcolor="'+parent.frames[0].document.bgColor.toUpperCase()+'">')
   dObj.writeln('<center>')
   dObj.writeln('<table width="100%" border="0">')
   dObj.writeln('<tr><td align="center">')

   //Print each button. Start at property index i.
   for(var i = this.startIndex; this.length > i; i++) {
      if(eval(this[i].condition)) {
         dObj.write('<A HREF = "'+this[i].url+'">')
         dObj.write('<img src="'+this[i].file+'" alt="'+this[i].alt+'" width="24" height="24" border=0>')
         dObj.write('</A>')
         // Add space if specified.
         spaceInt = 0 + this[i].spacer
         if(spaceInt != 0) {
            dObj.write('<img src="graphics/space.gif" width='+spaceInt+' height=24 border=0>')
         }
      }
   }
   dObj.writeln('</td></tr></table>')
   dObj.writeln('</center>')        
   dObj.writeln('</body></html>')        
   dObj.close()
   this.isBusy = false
}

function clear() {
  /*
   * Description: Method of buttonSet object. Used to reset any global
   *              variables on which any buttons in the buttonSet rely
   *              on for their condition statements.
   * Arguments: None.
   */
   gIsRunning=false
}

function addBtn(name,file,alt,spacer,condition,command) {
  /* Description: Method of the buttonSet object used to add a new button to
   *              the end of the button set.
   * Arguments: name - (string) The name used as this button's HTML element name.
   *            file - (string) The button image's source url.
   *            alt  - (string) The alt attribute for the button.
   *            spacer - (integer) number of pixels of horizontal spacing used
   *                     after the button being added.
   *            condition - (string) conditional statement determines
   *                        whether or not to display the button.
   *            commmand - (string) The command to be executed.
   *
   */
   var i = this.length
   this[i] = new button(
             name,
             file,
             alt,
             "javascript:parent."+this.name+"["+i+"]"+".click()",
             spacer,
             condition,
             command)
   this.length++
}

function buttonSet(name) {
  /*
   * Description: button object constructor.
   * Arguments: name - The variable name of the buttonSet.
   */
   // Properties
   this.name = name
   this.startIndex = 7
   this.length = 7
   this.isBusy = false
   // Methods
   this.addBtn = addBtn
   this.print = print
   this.clear = clear
   return this
}

// Custom slide object.
function slide(textURL,imageURL) {
  /*
   * Description: slide object constructor.
   * Arguments: textURL - URL of the description page for this slide.
   *            imageURL - URL of the image page for this slide.
   */
   this.textURL = textURL
   this.imageURL = imageURL
   return this
}

function startAuto() {
  /*
   * Description: Start a "slideshow".
   * Arguments: None.
   */
   changeSlide("forward")
   gTimer = setTimeout("startAuto()",6000)
}

function changeSlide(command) {
  /*
   * Description: Used to move through the array of slides.
   * Arguments: command - An action to take against the array of slides.
   */
   if(Toolbar.isBusy) {
      return
   }
   if(command == "first") {
      frames[0].location.href = slideArray[0].textURL
      frames[1].location.href = slideArray[0].imageURL
      currentSlide = 0
   }
   if(command == "back") {
      if(currentSlide == 0) {
         currentSlide = slideArray.length
      }
      frames[0].location.href = slideArray[currentSlide-1].textURL
      frames[1].location.href = slideArray[currentSlide-1].imageURL
      currentSlide--
   }
   if(command == "forward") {
      if(currentSlide == slideArray.length-1) {
         currentSlide = -1
      }
      frames[0].location.href = slideArray[currentSlide+1].textURL
      frames[1].location.href = slideArray[currentSlide+1].imageURL
      currentSlide++
   }
   if(command == "last") {
      frames[0].location.href = slideArray[slideArray.length-1].textURL
      frames[1].location.href = slideArray[slideArray.length-1].imageURL
      currentSlide = slideArray.length-1
   }
   if(command == "start") {
      gIsRunning = true
      Toolbar.print(window.frames[2].document)
      gTimer = window.setTimeout("startAuto()",1000)
   }
   if(command == "stop") {
      window.clearTimeout(gTimer)
      gIsRunning = false
      Toolbar.print(window.frames[2].document)
   }
}
/*
 * MAIN
 */

//Create an array of slides
var slideArray
maxslide = 65
slideArray = new array(maxslide-1)
//slideArray[0] = new slide("indice.htm","principal1.jpg")

var currentSlide = 0

function CreaslideArray()
{
  for (var i=1; i <= maxslide; i++) {
   nombre="clip"+i+".jpg";
   slideArray[i-1]=new slide("indice.htm",nombre);
  }
}

//Create a new buttonSet for use in the lower frame.
Toolbar = new buttonSet("Toolbar")
Toolbar.clear()

//Add each button to Toolbar
Toolbar.addBtn("First","graphics/first.gif","Primera imagen",0,"true","changeSlide('first')")
Toolbar.addBtn("Previous","graphics/back.gif","Imagen anterior",0,"true","changeSlide('back')")
Toolbar.addBtn("Next","graphics/forward.gif","Siguiente imagen",0,"true","changeSlide('forward')")
Toolbar.addBtn("Last","graphics/last.gif","Ultima imagen",7,"true","changeSlide('last')")
Toolbar.addBtn("Start","graphics/auto.gif","Comenzar presentación",0,"gIsRunning==false","changeSlide('start')")
Toolbar.addBtn("StartGrey","graphics/autoGrey.gif","Comenzar presentación",0,"gIsRunning==true","")
Toolbar.addBtn("Stop","graphics/stop.gif","Detener presentación",0,"gIsRunning==true","changeSlide('stop')")
Toolbar.addBtn("StopGrey","graphics/stopGrey.gif","Detener presentación",0,"gIsRunning==false","")
CreaslideArray();
