
//--------------------------------------------------------------------------------
//FUNCIONES PARA MOSTRAR UN BOCADILLO Y UN MENSAJE
//
// Únicamente es necesario llamar a la función MuestraMensaje con los parámetros deseados.
//
//script Original por Clarence Eldefors http://www.cerebuswebmaster.com

var speed = new Array();
var step = new Array();
var hide = new Array();
var moveto = new Array();
var posy = new Array();
var left = 0;
var mensajePopUp = '';
var rutaImagenes = "../Images/Bocadillo/";
var nuevo = 0;
var actual = 0;
var mensajes = new Array();

function MuestraMensaje(velocidad, paso, posicionFinal, posicionY, tiempoOcultar, inicio, mensaje, tipoBocadillo, posicionRelativa)
{
	
	speed[nuevo] = velocidad;
	step[nuevo] = paso;
	hide[nuevo] = tiempoOcultar;	
	
	if ( posicionRelativa == 1 )
		moveto[nuevo] = posicionFinal;
	else
		moveto[nuevo] = document.body.clientWidth - posicionFinal;		
	
	posy[nuevo] = posicionY;		

	mensajes[nuevo]	= mensaje;	
		
//	if ( tipoBocadillo == 1 )
//	{
//		CrearBocadilloSuperiorIzquierda(mensaje);
//	}

	nuevo = nuevo + 1;	
	
	if ( tipoBocadillo == 1 )
	{
		setTimeout('left = moveto[actual] - 50; CrearBocadilloSuperiorIzquierda(mensajes[actual]); movein();', inicio);
	}
	else if ( tipoBocadillo == 2 )
	{
		setTimeout('left = moveto[actual] - 50; CrearBocadilloSuperiorDerecha(mensajes[actual]); movein();', inicio);
	}
}

function CrearBocadilloSuperiorIzquierda(mensaje)
{
	mensajePopUp = "<table cellpadding='0' cellspacing='0' width='250px'>";
	
	mensajePopUp = mensajePopUp + "<tr>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "esqSI.gif);background-repeat:no-repeat;background-position:bottom;' width='35px' height='35px'></td>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "flechaSI.gif);background-repeat:no-repeat;' width='35px' height='35px'></td>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "bordeS.gif);background-repeat:repeat-x;background-position:bottom;' width='150px' height='35px'>&nbsp;</td>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "esqSD.gif);background-repeat:no-repeat;background-position:bottom;' width='35px' height='35px'></td>";
	mensajePopUp = mensajePopUp + "</tr>";
	
	mensajePopUp = mensajePopUp + "<tr>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "bordeIz.gif);background-repeat:repeat-y;' width='35px' height='16px'></td>";
	mensajePopUp = mensajePopUp + "<td colspan='2' bgcolor='#ffffaa' class='form_sec_in'><span class='form_texto'>" + mensaje + "</span>";
	mensajePopUp = mensajePopUp + "<p align='right'><a class='noticias_seccion_enlace' href='#' onclick='closemessage();'>Cerrar</a></p></td>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "bordeD.gif);background-repeat:repeat-y;' width='35px' height='35px'></td>";
	mensajePopUp = mensajePopUp + "</tr>";
	
	mensajePopUp = mensajePopUp + "<tr>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "esqII.gif);background-repeat:no-repeat;' width='35px' height='16px'></td>";
	mensajePopUp = mensajePopUp + "<td colspan='2' style='background-image:url(" + rutaImagenes + "bordeI.gif);background-repeat:repeat-x;' height='16px'></td>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "esqID.gif);background-repeat:no-repeat;' width='35px' height='16px'></td>";
	mensajePopUp = mensajePopUp + "</tr>";
	
	mensajePopUp = mensajePopUp + "</table>";
}

function CrearBocadilloSuperiorDerecha(mensaje)
{
	mensajePopUp = "<table cellpadding='0' cellspacing='0' width='250px'>";
	
	mensajePopUp = mensajePopUp + "<tr>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "esqSI.gif);background-repeat:no-repeat;background-position:bottom;' width='35px' height='35px'></td>";	
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "bordeS.gif);background-repeat:repeat-x;background-position:bottom;' width='150px' height='35px'>&nbsp;</td>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "flechaSD.gif);background-repeat:no-repeat;' width='35px' height='35px'></td>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "esqSD.gif);background-repeat:no-repeat;background-position:bottom;' width='35px' height='35px'></td>";
	mensajePopUp = mensajePopUp + "</tr>";
	
	mensajePopUp = mensajePopUp + "<tr>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "bordeIz.gif);background-repeat:repeat-y;' width='35px' height='16px'></td>";
	mensajePopUp = mensajePopUp + "<td colspan='2' bgcolor='#ffffaa' class='form_sec_in'><span class='form_texto'>" + mensaje + "</span>";
	mensajePopUp = mensajePopUp + "<p align='right'><a class='noticias_seccion_enlace' href='#' onclick='closemessage();'>Cerrar</a></p></td>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "bordeD.gif);background-repeat:repeat-y;' width='35px' height='35px'></td>";
	mensajePopUp = mensajePopUp + "</tr>";
	
	mensajePopUp = mensajePopUp + "<tr>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "esqII.gif);background-repeat:no-repeat;' width='35px' height='16px'></td>";
	mensajePopUp = mensajePopUp + "<td colspan='2' style='background-image:url(" + rutaImagenes + "bordeI.gif);background-repeat:repeat-x;' height='16px'></td>";
	mensajePopUp = mensajePopUp + "<td style='background-image:url(" + rutaImagenes + "esqID.gif);background-repeat:no-repeat;' width='35px' height='16px'></td>";
	mensajePopUp = mensajePopUp + "</tr>";
	
	mensajePopUp = mensajePopUp + "</table>";
}

function movein(){

  if (document.layers) {	
        document.layers['message'].pageX = window.pageXOffset + left;
        document.layers['message'].pageY = window.pageYOffset + posy[actual];
        left+=step[actual];        
        if(left<moveto[actual]){ setTimeout('movein()',speed[actual]); }
        else { setTimeout('closemessage()',hide[actual]); actual = actual + 1;}
    }
   
  else{
	document.getElementById('message').style.left=left+'px';
	document.getElementById('message').style.top=posy[actual]+'px';
		
	left+=step[actual];
	if(left<moveto[actual]){ setTimeout('movein()',speed[actual]); }
	else { setTimeout('closemessage()',hide[actual]); actual = actual + 1; }
  }
  
  	showmessage();
}
function closemessage(){
        if (document.layers) {document.layers['message'].visibility='hidden';}
        else{document.getElementById('message').style.visibility='hidden';}
}

function showmessage()
{
        if (document.layers) 
        {
			document.layers['message'].visibility = 'visible';
			document.layers['message'].innerHTML = mensajePopUp;
			
		}
        else
        {
			document.getElementById('message').style.visibility = 'visible';
			document.getElementById('message').innerHTML = mensajePopUp;
		}
}

function EncuentraPosicion ( control )
{		
	var controlPadre = document.getElementById(control);
	var i = 0;
	while ( controlPadre != null )
	{	
		i = i + controlPadre.style.left;	
		controlPadre = controlPadre.parentNode;				
	}
	
	alert ("A " + i);
}



//FIN FUNCIONES PARA MOSTRAR UN BOCADILLO Y UN MENSAJE
//--------------------------------------------------------------------------------


