/*
DHTML popInfo v0.3
writen by: Daantje (JK Webdesign)
last update: 22 Jul 2003 - 13:31

documentation:
This script will pop up a DIV element with the given HTML.
Just like the TITLE atribute on the A tags... Only this one understands
HTML and will be visible until you pull out on the link...
Also build a funtion to replace the title attributes on given tags.
You can call this function onload of the page.

license:
This script is FREE to use! You may copy, edit
or use this script in ANY way possible!
But please, mention me in your credits...
*/

//configuration
var infDivID = 'popInfoDiv'; //ID of the <DIV> tag
var infDivOverlap = 3; //pixels ovelap on link
var infDivOutTime = 10; //amount of seconds before hidding
var replaceTitleAttribIn = new Array('a','div','input','span','select','img'); //search for these tags, and replace title attributes

//needed
var tmr;
var lastPopInfo;

//pop up an info DIV.
//call with empty txt value to hide the object.
function popInfo(obj,txt){
if(obj){
//get popup div element
infDiv = document.getElementById(infDivID);
if(infDiv){
//kill timer
clearTimeout(tmr);
//check what to do... over or out...
if(txt){
//kill last pop div, when one is there....
if(lastPopInfo)
infDiv.style.visibility = "hidden";
//get position
t = obj.offsetTop;
l = obj.offsetLeft;
//patch position when we are in an other element...
if(obj.offsetParent.offsetTop || obj.offsetParent.offsetLeft){
obj2 = obj;
while(obj2.offsetParent){
t += obj2.offsetParent.offsetTop;
l += obj2.offsetParent.offsetLeft;
obj2 = obj2.offsetParent;
}
}
//puse the popup to the link....
infDiv.style.top = t + obj.offsetHeight - infDivOverlap;
infDiv.style.left = l + obj.offsetHeight - infDivOverlap;
infDiv.innerHTML = txt; //set text...
infDiv.style.visibility = "visible"; //make it visible
lastPopInfo = infDiv; //remember current div for next over or out...
}else{
//it's an out... kill it on a timer...
tmr = setTimeout('infDiv.style.visibility = "hidden"', (infDivOutTime * 100));
}
}
}
}

//this function will replace all found title attriubutes
//with popInfo calls... (You may want to use this onload...)
function changeTitleToPopInfo(){
//loop tags
for(j=0;j<replaceTitleAttribIn.length;j++){
//get all this kind of tags
doc = document.getElementsByTagName(replaceTitleAttribIn[j]);
for(i=0;i<doc.length;i++){
//remember title contents
txt = doc[i].getAttribute('title');
if(txt){
//make new attributes...
ov = doc[i].setAttribute('onmouseover',"popInfo(this,'"+txt+"')");
ou = doc[i].setAttribute('onmouseout',"popInfo(this)");
//remove the title...
doc[i].removeAttribute('title');
}
}
}
}

