var nn4 = (document.layers) ? true : false;
var ie = (document.all) ? true : false;
var dom = (document.getElementById && !document.all) ? true : false;

function obtenerObjeto (nombre)
{
	if (dom)
	  return document.getElementById (nombre);
	if (ie)
	  return document.all[nombre];
    if (nn4)
	  return document.layers[nombre];
}

function Capa (nombre)
{
    this.pasoArriba = 5;
    this.tiempoArriba = 100;

	this.capa = obtenerObjeto (nombre);
	if (this.capa != null)
	{
	  this.y = this.capa.style.pixelTop;
	  this.x = this.capa.style.pixelLeft;
	  this.h = this.capa.style.pixelBottom;
	  this.w = this.capa.style.pixelRight;
	  this.desplazamientoArriba = 0;
	  this.posicionVerticalInicial = this.y;
	  this.continuarMovimiento = true;
	  
	  this.moverArribaRepetido = Capa_moverArribaRepetido;
      this.mover = Capa_mover;
	  this.colocar = Capa_colocar;
	}
}


function Capa_mover (x, y)
{
	this.x += x;
	this.y += y;
	this.capa.style.pixelLeft = this.x;
	this.capa.style.pixelTop = this.y;
}

function Capa_colocar (x, y)
{
	this.x = x;
	this.y = y;
	this.capa.style.pixelLeft = this.x;
	this.capa.style.pixelTop = this.y;
}

function moverArriba (nombre)
{
	capa = eval (nombre);
	capa.continuarMovimiento = true;
	moverArribaRepetido (nombre);
}

function moverArribaRepetido (nombre)
{
	capa = eval (nombre);
//	alert (capa.y + ' ' + capa.h);
	if (capa.y <= -capa.h + 200)
	{
	  return;
	}
	if (capa.continuarMovimiento)
	{
      capa.mover (0, -capa.pasoArriba);
//	  window.status = "Y= " + capa.y;
	  capa.desplazamientoArriba += capa.pasoArriba;
	  setTimeout ("moverArribaRepetido ('" + nombre + "')", capa.tiempoArriba);
	}
}

function moverAbajo (nombre)
{
	capa = eval (nombre);
	capa.continuarMovimiento = true;
	moverAbajoRepetido (nombre);
}

function moverAbajoRepetido (nombre)
{
	capa = eval (nombre);
	if (capa.y >= 0)
	{
	  return;
	}
	if (capa.continuarMovimiento)
	{
      capa.mover (0, capa.pasoArriba);
//	  window.status = "Y= " + capa.y;
	  capa.desplazamientoArriba += capa.pasoArriba;
	  setTimeout ("moverAbajoRepetido ('" + nombre + "')", capa.tiempoArriba);
	}
}

function detenerCapa (nombre)
{
	eval (nombre + ".continuarMovimiento = false");
}

function Capa_moverArribaRepetido ()
{
	this.mover (0, -this.pasoArriba);
	setTimeout ("this.moverArribaRepetido ()", this.tiempoArriba);
}

function centrarCapa (nombre)
{
	var capa, ventana;
    ventana = new Ventana ();
	capa = obtenerObjeto (nombre);
//	alert (capa.style.pixelWidth);
	if (ventana.anchoVisible - capa.style.pixelWidth > 0)
	  capa.style.pixelLeft = (ventana.anchoVisible - capa.style.pixelWidth) / 2;
	else
	  capa.style.pixelLeft = 0;
	if (ventana.altoVisible - capa.style.pixelHeight > 0)
	  capa.style.pixelTop = (ventana.altoVisible - capa.style.pixelHeight) / 2;
	else
	  capa.style.pixelTop = 0;
}

function Ventana ()
{
	this.anchoVisible = 0;
	this.altoVisible = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    this.anchoVisible = window.innerWidth;
    this.altoVisible = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    this.anchoVisible = document.documentElement.clientWidth;
    this.altoVisible = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    this.anchoVisible = document.body.clientWidth;
    this.altoVisible = document.body.clientHeight;
  }
}
