var offsetxpoint=20 //Customize x offset of tooltip
var offsetypoint=10 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "";
var tipTitle=document.all? document.all["ttTitle"] : document.getElementById? document.getElementById("ttTitle") : "";
var tipImage=document.all? document.all["ttImage"] : document.getElementById? document.getElementById("ttImage") : "";
var tipAutor=document.all? document.all["ttAutor"] : document.getElementById? document.getElementById("ttAutor") : "";

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(obj, thetext, thecolor, thewidth){
	if (ns6||ie){
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px";
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor;
		tipTitle.innerHTML=obj.getAttribute("titulo");
		tipImage.src="thumbnails/"+obj.getAttribute("imagen")+".jpg";
		tipAutor.innerHTML=obj.getAttribute("autor");
		//tipobj.innerHTML=thetext
		enabletip=true;
		return false;
	}
}
function getPosition(e) {
	e = e || window.event;
	var cursor = {x:0, y:0};
	if (e.pageX || e.pageY) {
		cursor.x = e.pageX;
		cursor.y = e.pageY;
	}
	else {
		cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) -	document.documentElement.clientLeft;
	cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) -document.documentElement.clientTop;
	}
	return cursor;
}
	  
function maxHeight() {
  var h=0;
  if (window.document.innerHeight>h)
   h=window.document.innerHeight;
  if (window.document.documentElement.clientHeight>h)
   h=window.document.documentElement.clientHeight;
  if (window.document.body.clientHeight>h)
   h=window.document.body.clientHeight;
  return h;
 }
 
function maxWidth() {
  var w=0;
  if (window.document.innerWidth>w)
   w=window.document.innerWidth;
  if (window.document.documentElement.clientWidth>w)
   w=window.document.documentElement.clientWidth;
  if (window.document.body.clientWidth>w)
   w=window.document.body.clientWidth;
  return w;
}
 
function positiontip(e){
//	var andechivo=document.getElementById("chivo");
	e = e || window.event;
	var curs=getPosition(e);
	var anmax=maxWidth();
	var almax=maxHeight();
//	andechivo.innerHTML="x="+curs.x+", y="+curs.y+", ancho="+anmax+", alto="+almax ;
	if (enabletip){
		var curX=(ns6)?e.pageX : event.x+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.y+ietruebody().scrollTop;
		
		var margenTop=435;
		var margenDer="";
		var margenIzq=0;
		var margenBot="";
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
		
//		andechivo.innerHTML+=", right="+rightedge+", bottom="+bottomedge;
//		andechivo.innerHTML+=", anchoOBJ="+tipobj.offsetWidth+", altoOBJ="+tipobj.offsetHeight;		
		
		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000
	
	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<tipobj.offsetWidth){
		//move the horizontal position of the menu to the left by it's width
		tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px";
	}
	else if (curX<leftedge){
		tipobj.style.left="5px"
	}
	else{
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetxpoint+"px";
	}
	
	//same concept with the vertical position
//	andechivo.innerHTML+=", "+curs.y+" < "+margenTop
	if ((curs.y-tipobj.offsetHeight)<margenTop){
			tipobj.style.top=curs.y+offsetypoint+"px"
			tipobj.style.visibility="visible"
	}
	else{
		tipobj.style.top=curs.y-tipobj.offsetHeight+"px"
		tipobj.style.visibility="visible"
	}
	
/*	if (cursX<margenTop bottomedge<tipobj.offsetHeight)
		tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
		else
			tipobj.style.top=curY+offsetypoint+"px"
			tipobj.style.visibility="visible"
	}*/	
}
	return true;
}




function hideddrivetip(){
	if (ns6||ie){
		enabletip=false
		tipobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}
document.onmousemove=positiontip
