//===== walquiriabm =====//
//colocar no link -> tt="sim/não" head="titulo da caixinha" title="conteudo"

function iniciaToolTip(id){
	var links,i,h;
	if(!document.getElementById || !document.getElementsByTagName) return;
	adicionaCss();
	h=document.createElement("span");
	h.id="toolTipConteudo";
	h.setAttribute("id","toolTipConteudo");
	h.style.position="absolute";
	document.getElementsByTagName("body")[0].appendChild(h);
	if(id==null) links=document.getElementsByTagName("a");
	else links=document.getElementById(id).getElementsByTagName("a");
	for(i=0;i<links.length;i++){
		if(links[i].getAttribute("tt")=='sim' && links[i].getAttribute("title")){
			links[i].id="link"+i;
			//alert(links[i].id);
			Prepare(links[i]);
		}
	}
}

function Prepare(el){
	var tooltip,t,b,s,l, caixinha;
	t=el.getAttribute("title");
	if(t==null || t.length==0) t="link:";
	el.removeAttribute("title");
	
	caixinha = CreateEl("div",t);
	setinha = CreateEl("div","");
	setinha.id = "setinha"+el.id;
	caixinha2 = CreateEl("div","caixinha2");
	caixinha3 = CreateEl("div","caixinha3");
	
	/*if(el.getAttribute("head")){
		caixinha2.innerHTML = el.getAttribute("head").replace("&","&amp;");
	}
	else
		caixinha2.innerHTML = "CBS";*/
		
	tooltip=CreateEl("div","");
	s=CreateEl("span","top");
	
	//s.appendChild(document.createTextNode(t));
	//s.className=t;
	
	caixinha.appendChild(setinha);
	caixinha.appendChild(caixinha2);
	caixinha3.appendChild(s);
	caixinha.appendChild(caixinha3);	
	tooltip.appendChild(caixinha);
	
	var quebraLinha = document.createElement("span");
	quebraLinha.innerHTML = '<br>';      
	caixinha3.appendChild(quebraLinha);
	
	caixinha3.innerHTML=caixinha3.innerHTML.replace(/##/g,"<br>");
	
	
	
//	alert(caixinha3.innerHTML);

	/*b=CreateEl("b","bottom");
	l=el.getAttribute("href");
	if(l.indexOf("#")==-1){
		if(l.length>40) l=l.substr(0,37)+"...";
		b.appendChild(document.createTextNode(l));
		caixinha3.appendChild(b);
	}*/
	//else
	//	el.style.cursor="help";

	setOpacity(tooltip);
	//
	//tooltip.style.display='none';
	//el.appendChild(tooltip);
	//
	el.tooltip=tooltip;
	el.onmouseover=showTooltip;
	el.onmouseout=hideTooltip;
	//el.onmousemove=Locate;
}

function showTooltip(e){
	document.getElementById("toolTipConteudo").appendChild(this.tooltip);
	//document.getElementById("toolTipConteudo").innerHTML = this.tooltip.innerHTML;
	Posiciona(e);
}

function hideTooltip(e){
	var d=document.getElementById("toolTipConteudo");
	if(d.childNodes.length>0) d.removeChild(d.firstChild);
}

function setOpacity(el){
	el.style.filter="alpha(opacity:95)";
	el.style.KHTMLOpacity="0.95";
	el.style.MozOpacity="0.95";
	el.style.opacity="0.95";
}

function CreateEl(t,c){
	var x=document.createElement(t);
	x.className=c;
	x.style.display="";
	return(x);
}

function adicionaCss(){
	var l=CreateEl("link");
	l.setAttribute("type","text/css");
	l.setAttribute("rel","stylesheet");
	l.setAttribute("href","../css/bibToolTip.css");
	l.setAttribute("media","screen");
	document.getElementsByTagName("head")[0].appendChild(l);
}

function Posiciona(e){
	if(typeof(e)=='undefined')var e=window.event
	source=e.target?e.target:e.srcElement
	if(source.nodeType == 3)source = source.parentNode;
	
	if (!source.id)source = source.parentNode;
	
	var posx = eval(getAbsoluteLeft(source.id) + getElementWidth(source.id));
	document.getElementById("toolTipConteudo").style.top=(getAbsoluteTop(source.id) - 3)+"px";
	
	if(posx<610){
		document.getElementById("toolTipConteudo").style.left = (posx-3)+"px";
		document.getElementById("setinha"+source.id).className = "setinha";
	}
	else{
		document.getElementById("toolTipConteudo").style.left = (getAbsoluteLeft(source.id)-282)+"px";	
		document.getElementById("setinha"+source.id).className = "setinha2";
	}
}

function getAbsoluteLeft(objectId) {
	o = document.getElementById(objectId);
	oLeft = o.offsetLeft;
	while(o.offsetParent!=null) {
		oParent = o.offsetParent;
		oLeft += oParent.offsetLeft;
		o = oParent;
	}
	return oLeft
}

function getAbsoluteTop(objectId) {
	o = document.getElementById(objectId)
	oTop = o.offsetTop            
	while(o.offsetParent!=null) {
		oParent = o.offsetParent 
		oTop += oParent.offsetTop 
		o = oParent
	}
	return oTop
}

function getElementWidth(objectId) {
	x = document.getElementById(objectId);
	return x.offsetWidth;
}
//window.onload=function(){iniciaToolTip('tool')};
window.onload=function(){iniciaToolTip()};



