var div_movil;
var uri="http://www.frai.es/";

function eliminaToolTip(obj)
{
var body=document.getElementsByTagName("body")[0];
body.removeChild(div_movil);
}
function creaToolTip(obj)
{
imagenhref=obj.href;
if(obj.firstChild.tagName=="STRONG")
{

imagenalt = obj.previousSibling.firstChild.firstChild.attributes.alt.value;
}else
{
imagenalt = obj.firstChild.attributes.alt.value;
}
div_movil=document.createElement("div");
div_movil.setAttribute("id","tooltip_capa");
div_movil.style.display="none";
var imagen=document.createElement("img");
imagenhref = imagenhref.split("/");
imagenhref=imagenhref[imagenhref.length-1]
//alert ("http://oficina2.kaplan.di:81/frai/utils/imagen.php?ancho=335&alto=255&archivo="+imagenhref);
imagen.setAttribute("src",uri+"utils/imagen.php?ancho=335&alto=255&archivo="+imagenhref);
var texto=document.createElement("p");
var alt= document.createTextNode(imagenalt);
texto.appendChild(alt);
div_movil.appendChild(texto);
div_movil.appendChild(imagen);
document.getElementsByTagName('body')[0].appendChild(div_movil);
}
var offsetfrommouse=[15,15];
var displayduration=0;
var currentimageheight = 100;
function truebody(){return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;}
function controlaventana(e)
{
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
if (typeof e != "undefined"){
		if (docwidth - e.pageX < 300){
			xcoord = e.pageX - xcoord - 286; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 110)){
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 300){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 286; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	if (div_movil.style.display=="none")div_movil.style.display="block";
	div_movil.style.left=xcoord+"px";
	div_movil.style.top=ycoord+"px";
}
function manejaToolTip(obj)
{

window.onmousemove=controlaventana;
document.onmousemove=controlaventana;
}
function abreToolTip(obj)
{
	imagenhref=obj.href;
	GTK_openImage(imagenhref);
}

function gestiona(enlaces)
{
	var enlace;
	AddEventListener("muestraToolTip",creaToolTip);
  	AddEventListener("muestraToolTip",manejaToolTip);
  	AddEventListener("ocultaToolTip",eliminaToolTip);
  	AddEventListener("abreToolTip",abreToolTip);
  	AddEventListener("mueve",controlaventana);
  
	for (i=0;i<enlaces.length;i++)
	{
	enlace = enlaces[i];
	addEvent(enlace, "mouseover",'muestraToolTip',false);
	addEvent(enlace, "mouseout",'ocultaToolTip',false);	
	addEvent(enlace, "click",'abreToolTip',false);
	}	
}

