var temporizador;

//------------------------------ VALORES QUE SE PUEDEN MODIFICAR ------------------------------------------------------------------------------
//var velocidad = 15; //A MENOR VALOR MAYOR VELOCIDAD DE DESPLAZAMIENTO DE LA CAPA Y VICEVERSA
//var margenSuperior = 50;	//MARGEN DE LA PARTE SUPERIOR DE LA VENTANA A LA QUE SE SITUARÁ LA CAPA
//var ocultarAltura = 752; //AJUSTAR AL DOBLE DEL VALOR DE LA ALTURA EN PIXELS DE LA CAPA
//var posHorizontal = 600; //AJUSTAR AL MISMO VALOR DEL ANCHO EN PIXELS DE LA CAPA. A MENOR VALOR MAYOR DESPLAZAMIENTO A LA DERECHA Y VICEVERSA
//------------------------------ A PARTIR DE AQUÍ NO MODIFICAR NADA ---------------------------------------------------------------------------

var difPosHorizontal = 7; //DIFERENCIA QUE SE AÑADE A LA POSICIÓN HORIZONTAL PARA "EXPLORER" 
                          //PARA QUE CENTRE BIEN EL POPUP

//FUNCIÓN QUE LLAMA A LAS FUNCIONES QUE PONEN EN MARCHA EL POPUP
function comenzarPopup(formato, velocidad, margenSuperior, ocultarAltura, anchura, posHorizontal, margenesBorde, transparencia, transpIntensidad, transpColor, bordeGrosor, bordeColor, colorFondo, tamanoTextoTitulo, tamanoTextoTexto, negritaTextoTitulo, negritaTextoTexto, colorTextoTitulo, colorTextoTexto, justifTextoTitulo, justifTextoTexto, imagen) 
{
  // SI EL FORMATO DEL POPUP ES FOTO O FOTO CON TEXTO ABAJO CALCULAMOS EL ANCHO
  // DE LA FOTO Y SE LO ASIGNAMOS AL ANCHO DEL POPUP Y A SU POSICIÓN HORIZONTAL
  if (formato == 5)
  {
    anchuraImagen = calcularAnchuraImagen(imagen);
    anchura = anchuraImagen;
    posHorizontal = anchuraImagen;
  }  

  posHorizontal += (margenesBorde * 2); 
  if (negritaTextoTitulo == 0) 
    negritaTextoTitulo = "normal";
  else 
    negritaTextoTitulo = "bold";
  if (negritaTextoTexto == 0) 
    negritaTextoTexto = "normal";
  else 
    negritaTextoTexto = "bold";
  
  if (transparencia == 1)
    mostrarFondoTransparente(transpIntensidad, transpColor);

  ocultarPopup(margenSuperior, ocultarAltura);
  calcularPos(posHorizontal);
  
  bordeGrosor = bordeGrosor + "px";
  bordeColor = "#" + bordeColor;
  bordeFormato = "solid" + " " + bordeGrosor + " " + bordeColor;

  if (justifTextoTitulo == 1)
    justifTextoTitulo = "left";
  if (justifTextoTitulo == 2)
    justifTextoTitulo = "right";
  if (justifTextoTitulo == 3)
    justifTextoTitulo = "center";
  if (justifTextoTitulo == 4)
    justifTextoTitulo = "justify"; 
    
  if (justifTextoTexto == 1)
    justifTextoTexto = "left";
  if (justifTextoTexto == 2)
    justifTextoTexto = "right";
  if (justifTextoTexto == 3)
    justifTextoTexto = "center";
  if (justifTextoTexto == 4)
    justifTextoTexto = "justify";
  
  mostrarPopup(velocidad, margenSuperior, anchura, bordeFormato, margenesBorde, colorFondo, tamanoTextoTitulo, tamanoTextoTexto, negritaTextoTitulo, negritaTextoTexto, colorTextoTitulo, colorTextoTexto, justifTextoTitulo, justifTextoTexto);
}

//FUNCIÓN QUE MUESTRA UN FONDO DE COLOR CON TRANSPARENCIA
function mostrarFondoTransparente(transpIntensidad, transpColor) //EXPLORER
{
  if (document.all)
  {
    transpIntensidad = transpIntensidad * 10;
    document.all.fondoTransparente.style.background = "#" + transpColor; 
    document.all.fondoTransparente.style.filter = "alpha(opacity = "+transpIntensidad+")";
  }
  else if (document.layers) //NETSCAPE ANTIGUO Y COMPATIBLES
  {
    transpIntensidad = "." + transpIntensidad;
    document.layers.popup.fondoTransparente.background = "#" + transpColor;
    document.layers.popup.fondoTransparente.opacity = transpIntensidad;
  }
	else if (document.getElementById) //OTROS NAVEGADORES
  {
    transpIntensidad = "." + transpIntensidad;
    document.getElementById("fondoTransparente").style.background = "#" + transpColor;
    document.getElementById("fondoTransparente").style.opacity = transpIntensidad;
  }
}

//FUNCIÓN QUE OCULTA EN EL MARGEN SUPERIOR LA VENTANA POPUP AL INICIO
function ocultarPopup(margenSuperior, ocultarAltura) 
{ 
  var ocultarAltura = - ocultarAltura  + margenSuperior; //AÑADIMOS LA SEPARACIÓN SUPERIOR
  
	posSuperior = ocultarAltura;
	if(posSuperior < margenSuperior) 
  { 
		posSuperior += 25;
		if (document.layers) 
      document.layers.popup.top = ocultarAltura + "px"; //NETSCAPE ANTIGUO Y COMPATIBLES
		else if (document.all) 
      document.all.popup.style.top = ocultarAltura + "px"; //EXPLORER
		else if (document.getElementById) 
      document.getElementById("popup").style.top = ocultarAltura + "px";
}
}

//FUNCIÓN QUE CALCULA LA POSICIÓN INICIAL DE LA VENTANA POPUP
function calcularPos(posHorizontal) 
{
  if (document.layers) 
    document.layers.popup.left = ((window.innerWidth - posHorizontal) / 2) + "px"; //NETSCAPE ANTIGUO Y COMPATIBLES
	else if (document.all) 
    document.all.popup.style.left = (((document.body.offsetWidth - posHorizontal) / 2) + difPosHorizontal) + "px"; //EXPLORER
	else if (document.getElementById) 
    document.getElementById("popup").style.left = ((window.innerWidth - posHorizontal) / 2) + "px"; //EL RESTO DE NAVEGADORES
}

//FUNCIÓN QUE DESLIZA Y POSICIONA LA VENTANA POPUP DESDE LA PARTE SUPERIOR DEL NAVEGADOR
function mostrarPopup(velocidad, margenSuperior, anchura, bordeFormato, margenesBorde, colorFondo, tamanoTextoTitulo, tamanoTextoTexto, negritaTextoTitulo, negritaTextoTexto, colorTextoTitulo, colorTextoTexto, justifTextoTitulo, justifTextoTexto) 
{ 
  if(posSuperior < margenSuperior) 
  { 
		posSuperior += 25;

		if (document.all) //EXPLORER
    {
      document.all.popup.style.display = "block";
      document.all.popup.style.top = posSuperior + "px";
      document.all.popup.style.width = anchura + "px";
      document.all.popup.style.border = bordeFormato;
      document.all.popup.style.padding = margenesBorde + "px";
      document.all.popup.style.background = "#" + colorFondo;
      document.all.popupTitulo.style.fontSize = tamanoTextoTitulo + "px";
      document.all.popupTexto.style.fontSize = tamanoTextoTexto + "px";      
      document.all.popupTitulo.style.fontWeight = negritaTextoTitulo;
      document.all.popupTexto.style.fontWeight = negritaTextoTexto;
      document.all.popupTitulo.style.color = "#" + colorTextoTitulo;
      document.all.popupTexto.style.color = "#" + colorTextoTexto;      
      document.all.popupTitulo.style.textAlign = justifTextoTitulo;
      document.all.popupTexto.style.textAlign = justifTextoTexto;      
    }
		else if (document.layers) //NETSCAPE ANTIGUO Y COMPATIBLES
    {
      document.layers.popup.style.display = "block"; 
      document.layers.popup.style.top = posSuperior + "px";
      document.layers.popup.style.width = anchura + "px";
      document.layers.popup.style.border = bordeFormato;
      document.layers.popup.style.padding = margenesBorde + "px";
      document.layers.popup.style.background = "#" + colorFondo;
      document.layers.popupTitulo.style.fontSize = tamanoTextoTitulo + "px";
      document.layers.popupTexto.style.fontSize = tamanoTextoTexto + "px";      
      document.layers.popupTitulo.style.fontWeight = negritaTextoTitulo;
      document.layers.popupTexto.style.fontWeight = negritaTextoTexto;
      document.layers.popupTitulo.style.color = "#" + colorTextoTitulo;
      document.layers.popupTexto.style.color = "#" + colorTextoTexto;
      document.layers.popupTitulo.style.textAlign = justifTextoTitulo;
      document.layers.popupTexto.style.textAlign = justifTextoTexto;      
    }
		else if (document.getElementById) //OTROS NAVEGADORES
    {
      document.getElementById("popup").style.display = "block"; 
      document.getElementById("popup").style.top = posSuperior + "px";
      document.getElementById("popup").style.width = anchura + "px";
      document.getElementById("popup").style.border = bordeFormato;  
      document.getElementById("popup").style.padding = margenesBorde + "px";
      document.getElementById("popup").style.background = "#" + colorFondo;
      document.getElementById("popupTitulo").style.fontSize = tamanoTextoTitulo + "px";
      document.getElementById("popupTexto").style.fontSize = tamanoTextoTexto + "px";
      document.getElementById("popupTitulo").style.fontWeight = negritaTextoTitulo;
      document.getElementById("popupTexto").style.fontWeight = negritaTextoTexto;      
      document.getElementById("popupTitulo").style.color = "#" + colorTextoTitulo;
      document.getElementById("popupTexto").style.color = "#" + colorTextoTexto; 
      document.getElementById("popupTitulo").style.textAlign = justifTextoTitulo;
      document.getElementById("popupTexto").style.textAlign = justifTextoTexto;
    }
	}
	if(temporizador != null) clearInterval(temporizador);
	temporizador = setTimeout("mostrarPopup("+velocidad+","+margenSuperior+","+anchura+",'"+bordeFormato+"',"+margenesBorde+",'"+colorFondo+"',"+tamanoTextoTitulo+","+tamanoTextoTexto+",'"+negritaTextoTitulo+"','"+negritaTextoTexto+"','"+colorTextoTitulo+"','"+colorTextoTexto+"','"+justifTextoTitulo+"','"+justifTextoTexto+"')",velocidad);
}

//FUNCIÓN QUE CIERRA LA VENTANA POPUP
function cerrarPopup() 
{ 
  if (document.layers) //NETSCAPE ANTIGUO Y COMPATIBLES
  {
    document.layers.fondoTransparente.style.display = "none";
    document.layers.popup.style.display = "none";
  }
	else if (document.all) //EXPLORER
  {
    document.all.fondoTransparente.style.display = "none"; 
    document.all.popup.style.display = "none";
  }
	else if (document.getElementById) //EL RESTO DE NAVEGADORES
  {
    document.getElementById("fondoTransparente").style.display = "none";
    document.getElementById("popup").style.display = "none";
  }
}

function calcularAnchuraImagen(imagen)
{
  // CALCULAMOS LA ANCHURA DE LA IMAGEN PARA ADAPTAR LA ALTURA DE LA CAPA
  tamanoImagen = new Image();
  tamanoImagen.src = imagen;
  tamanoImagen.width; // ANCHO
  //tamanoImagen.height; //Alto;
  //alert (tamanoImagen.width + "......." + tamanoImagen.height);
  return tamanoImagen.width;
}
