var nombre_pop = "popAviso";
var title;

function quita() {	
	$("#"+nombre_pop).remove();
	if (title) {
		$(this).attr("title",title);
		$(this).attr("alt",title);
	}
}

function aviso(e) {
	var texto = $(this).attr("title");
	if (texto) {
		title = texto;
		$(this).removeAttr("title");
		$(this).removeAttr("alt");
		if (!$("#"+nombre_pop)[0]) { // Se crea el elemento
	 		$("body").append("<div id=\""+nombre_pop+"\">"+texto+"</div>");
		}
	}
}

function mueve(e) {
	if ($("#"+nombre_pop)[0]) {
		var ely = $("#"+nombre_pop).height();
		var elx = $("#"+nombre_pop).width();
		var posy = e.pageY;
		var posx = e.pageX;
		var scrollx = $(window).scrollLeft();
		var scrolly = $(window).scrollTop();
		var cx = $(window).width();
		var cy = $(window).height();
		var desy = posy+20;
		var desx = posx-20;
		if (cx-posx<elx) {
			desx = posx-elx-20;
		}
		if (cy-posy<ely) {
			desy = posy-ely-20;
		}
		$("#"+nombre_pop).css({
			display: "block",
			top: (desy)+"px",
			 left: (desx)+"px"
		}); 
	}
}

jQuery(function($) {
	$("map area[title]").mouseover(aviso);
	$("map area[title]").mouseout(quita);
	$("map area[title]").mousemove(mueve);	
	$("table.buscador tbody tr[title]").mouseover(aviso);
	$("table.buscador tbody tr[title]").mouseout(quita);
	$("table.buscador tbody tr[title]").mousemove(mueve);
});	
