/* dhtml.js
 */

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 4);

var layerObj = (NS4) ? 'document' : 'document.all';
var styleObj = (NS4) ? '' : '.style';

var coleccionObjetosAnimados;

var show_visible = (NS4) ? 'show' : 'visible';
var hide_hidden  = (NS4) ? 'hide' : 'hidden';

function objetoCapa(nombreCapa) {

  objeto = eval(layerObj + '["' + nombreCapa + '"]' + styleObj);

  objeto.nombre = nombreCapa;
  objeto.mover = mover;
  objeto.mostrar = mostrar;
  objeto.ocultar = ocultar;

  objeto.getWidth = getWidth;
  objeto.getHeight = getHeight;

  objeto.actualizarContenido = actualizarContenido;
 
  objeto.recortar = recortar;
  objeto.recorte = new Array(4);
  objeto.recorte["top"] = -1;
  objeto.recorte["right"] = -1;
  objeto.recorte["bottom"] = -1;
  objeto.recorte["left"] = -1;
  coleccionObjetosAnimados[nombreCapa] = objeto;
  return objeto;
}

function animacion(ruta, bucle, velocidad) {
  this.ruta = ruta.split(',');
  this.indice_ruta = 0;
  this.bucle = bucle;
  this.velocidad = velocidad;
  this.animar = animar;
  this.fin = fin;
}

function mostrar() {
  eval('coleccionObjetosAnimados["'+ this.nombre + '"].visibility = show_visible');
}

function ocultar() {
  eval('coleccionObjetosAnimados["'+ this.nombre + '"].visibility = hide_hidden');
}

function mover(x,y) {
  eval('coleccionObjetosAnimados["'+ this.nombre + '"].left = x');
  eval('coleccionObjetosAnimados["'+ this.nombre + '"].top = y');
}

function getWidth() {
  widthPropertie = (NS4) ? '.document.width' : '.offsetWidth';
  currentWidth = eval('parseInt(' + layerObj + '["'+ this.nombre + '"]' + widthPropertie + ', 10)');
  return currentWidth;

}

function getHeight() {
  heightPropertie = (NS4) ? '.document.height' : '.offsetHeight';
  currentHeight = eval('parseInt(' + layerObj + '["'+ this.nombre + '"]' + heightPropertie + ', 10)');
  return currentHeight;
}

function actualizarContenido(contenido) {
  if (NS4) {
	eval(layerObj + '["' + this.nombre + '"]' + styleObj + '.document.open()');
	eval(layerObj + '["' + this.nombre + '"]' + styleObj + '.document.write(contenido)');
	eval(layerObj + '["' + this.nombre + '"]' + styleObj + '.document.close()');
  } else {
    eval(layerObj + '["' + this.nombre + '"].innerHTML = contenido');    
  }
}

function recortar(ntop, nright, nbottom, nleft) {
var cadena='';
  if (NS4) {
    eval('coleccionObjetosAnimados["' + this.nombre + '"]' + '.clip.top = ntop');
	eval('coleccionObjetosAnimados["' + this.nombre + '"]' + '.clip.right = nright');
	eval('coleccionObjetosAnimados["' + this.nombre + '"]' + '.clip.bottom = nbottom');
	eval('coleccionObjetosAnimados["' + this.nombre + '"]' + '.clip.left = nleft');
  } else {
    cadena += 'rect(' + ntop + ' ' + nright + ' ' + nbottom + ' ' + nleft +')';
    eval('coleccionObjetosAnimados["' + this.nombre + '"]' + '.clip = cadena');  
  }
  this.recorte["top"] = ntop;
  this.recorte["right"] = nright;
  this.recorte["bottom"] = nbottom;
  this.recorte["left"] = nleft;
}

function leerClipTop() {
  return this.recorte["top"];
}

function leerClipRight() {
  return this.recorte["right"];
}

function leerClipBottom() {
  return this.recorte["bottom"];
}

function leerClipLeft() {
  return this.recorte["left"];
}

function escribirClipTop(ntop) {
  this.recortar(ntop, this.recorte["right"], this.recorte["bottom"], this.recorte["left"]);
}

function escribirClipRight(nright) {
  this.recortar(this.recorte["top"], nright, this.recorte["bottom"], this.recorte["left"]);
}

function escribirClipBottom(nbottom) {
  this.recortar(this.recorte["top"], this.recorte["right"], nbottom, this.recorte["left"]);
}

function escribirClipLeft(nleft) {
  this.recortar(this.recorte["top"], this.recorte["right"], this.recorte["bottom"], nleft);
}


/***************************************************************************/

function escribirMarcador(que_marcador) {
   codHTML = '<TABLE>';
   codHTML += '<TR>';
   codHTML += '<TD VALIGN="MIDDLE">';
   codHTML += '<A HREF="#" NAME="#" onmouseover="self.status=\'' + marcadores[que_marcador] + '\'; return true" onmouseout="self.status=\'\'; return true" onclick="return arreglar(' + que_marcador + ')"><IMG NAME="img_marcador' + que_marcador + '" SRC="apuntador_right.gif" WIDTH="20" HEIGHT="20" BORDER=0></A>';
   codHTML += '</TD>';
   codHTML += '<TD VALIGN="MIDDLE">';
   codHTML += '<A HREF="#" NAME="#" onmouseover="self.status=\'' + marcadores[que_marcador] + '\'; return true" onmouseout="self.status=\'\'; return true" onclick="return arreglar(' + que_marcador + ')">';
   codHTML += marcadores[que_marcador] + '</A></TD>';
   codHTML += '</TR>';
   codHTML += '</TABLE>';
   
   return codHTML;
 }

/***************************************************************************/

function escribirEstilo() {
  cadena =  '<STYLE TYPE="text/css">';

  cadena += '.estilocapas {';
  cadena += 'position: absolute;';
  cadena += 'visibility: ' + hide_hidden + ';';
  if (NS4) {
    cadena += 'width: ' + ancho + 'px;';    
  }
  cadena += 'left: 0px;';
  cadena += 'top: 0px;';
  cadena += 'font-family: Tahoma;';
  cadena += 'color: #800080;';
  cadena += 'font-weight: bold;';
  cadena += 'font-size: 10pt;';
  cadena += '}';

  cadena += 'TD {';
  cadena += 'font-family: Tahoma;';
  cadena += 'color: #18bd00;';
  cadena += 'font-weight: bold;';
  cadena += 'font-size: 10pt;';
  cadena += '}';

  cadena += 'LI {';
  cadena += 'font-family: Tahoma;';
  cadena += 'color: #800080;';
  cadena += 'font-weight: bold;';
  cadena += 'font-size: 8pt;';
  cadena += '}';

  cadena += 'OL {';
  cadena += 'font-family: Tahoma;';
  cadena += 'color: #800080;';
  cadena += 'font-weight: bold;';
  cadena += 'font-size: 8pt;';
  cadena += '}';

  cadena += 'A {';
  cadena += 'font-family: Tahoma;';
  cadena += 'font-size: 10pt;';
  cadena += 'color: rgb(0,83,83);';
  cadena += 'font-weight: bold;';
  cadena += 'text-decoration: none;';
  cadena += '}';
    
  cadena += '</STYLE>';
  document.write(cadena);
}


/***************************************************************************/


function iniciar() {
  
    // Tamaņo de la ventana del navegador
    if (NS4) {
      ancho_ventana = window.innerWidth;
      alto_ventana = window.innerHeight;
    } else {
      ancho_ventana = document.body.clientWidth;
      alto_ventana = document.body.clientHeight;
    }
	
    posY = posY_inicial;
    a = ((ancho_ventana - ancho)/2);
	
    for(i=0;i<numero_segmentos;i++) {

	  eval('elmarcador' + i + ' = new objetoCapa("marcador' + i + '");');
	  
	  if (!NS4) {
	    eval('elmarcador' + i + '.width = ancho;');
	  }

	  eval('elmarcador' + i + '.left = a;');
	  eval('elmarcador' + i + '.top = posY;');
	  eval('elmarcador' + i + '.mostrar();');
	  

  	  eval('elsegmento' + i + ' = new objetoCapa("segmento' + i + '");');
	  if (!NS4) {
	    eval('elsegmento' + i + '.width = ancho;');
	  }
	  eval('elsegmento' + i + '.left = a + indentacion_segmento;');
	  eval('posY += separador + elmarcador' + i + '.getHeight();');
	}	
  }
  
  function arreglar(que_segmento) {
    if ((que_segmento_expandido == -1)||(que_segmento_expandido != que_segmento)) {

	  que_segmento_expandido = que_segmento;
	  
      posY = posY_inicial;
      for(i=0;i<numero_segmentos;i++) {
	    eval('elmarcador' + i + '.top = posY;');
		if (i==que_segmento) {
          if (!NS4) {
	        eval('document.images["img_marcador' + i + '"].src = "apuntador_down.gif";');
	      } else {
	        eval('elmarcador' + i + '.document.images["img_marcador' + i + '"].src = "images/apuntador_down.gif";');
	      }
		} else {
          if (!NS4) {
	        eval('document.images["img_marcador' + i + '"].src = "apuntador_right.gif";');
	      } else {
	        eval('elmarcador' + i + '.document.images["img_marcador' + i + '"].src = "images/apuntador_right.gif";');	  
	      }		
		}
	    eval('elmarcador' + i + '.mostrar();');
	    eval('posY += separador + elmarcador' + i + '.getHeight();');
	    if (i==que_segmento) {
	      eval('elsegmento' + i + '.top = posY;');
  	      eval('elsegmento' + i + '.mostrar();');
	      eval('posY += separador + elsegmento' + i + '.getHeight();');	  
	    } else {
  	      eval('elsegmento' + i + '.ocultar();');	  
	    }
	  }
	} else if (que_segmento_expandido == que_segmento) {
      que_segmento_expandido = -1;	
	  	  
      posY = posY_inicial;
      for(i=0;i<numero_segmentos;i++) {
	    eval('elmarcador' + i + '.top = posY;');
        if (!NS4) {
	      eval('document.images["img_marcador' + i + '"].src = "apuntador_right.gif";');
	    } else {
	      eval('elmarcador' + i + '.document.images["img_marcador' + i + '"].src = "images/apuntador_right.gif";');
	    }
	    eval('elmarcador' + i + '.mostrar();');
	    eval('posY += separador + elmarcador' + i + '.getHeight();');
		eval('elsegmento' + i + '.ocultar();');
	  }	  
	}
	return false;
  }