/*Javascript for Bubble Tooltips by Alessandro Fulciniti
http://pro.html.it - http://web-graphics.com */
/* Modified to search for " -- " in title to produce a header if found
Update: Also removes alt-attributes on imagelinks in IE */

if ((typeof Jesper=='undefined')){
    var Jesper = {};
}
if ((typeof Jesper.link=='undefined')){
    Jesper.link = {};
}
Jesper.link.Bubbles = new Class({
    initialize: function(el){
        this.enable(el);
        this.name = name;
    },
    enable : function (id)
    {
        var links,i,h;
        if(!document.getElementById || !document.getElementsByTagName) return;

        h=document.createElement("span");
        h.id="btc";
        h.setAttribute("id","btc");
        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++){
            this.prepare(links[i]);
        }
    },
    prepare : function (el)
    {
        var tooltip, title, b, span, l, parts, header, cn, b;
        title=el.getAttribute("title");
        
        if(title!=null && title.length!=0)
        {
            el.removeAttribute("title");
            tooltip = this.createElement("span","tooltip");
            span = this.createElement("span");
            // Replaces "Lorum -- Ipsum" with <h2>Lorum</h2><span>Ipsum</span>
            parts=title.split(/ -- /);
            if(parts[1] != null)
            {
                header=this.createElement("h2");
                header.appendChild(document.createTextNode(parts[0]));
                tooltip.appendChild(header);
                span.appendChild(document.createTextNode(parts[1]));
            }
            else
                span.appendChild(document.createTextNode(title));
            
            tooltip.appendChild(span);
            this.applyStyle(tooltip);
            el.tooltip=tooltip;
            el.onmouseover=this.showTooltip;
            el.onmouseout=this.hideTooltip;
            el.onmousemove=this.locate;
            //Removes the alt-attribute in IE to prevent it to popup
            cn = el.childNodes[0];
            if (cn && cn.nodeName.toLowerCase() == "img" && document.all && !window.opera){
        	   cn.title = "";
            }
        }
    },
    createElement : function(type, className)
    {
        var x=document.createElement(type);
        x.className=className;
        x.style.display="block";
        return(x);
    },
    applyStyle : function(el)
    {
        el.style.filter="alpha(opacity:95)";
        el.style.KHTMLOpacity="0.95";
        el.style.MozOpacity="0.95";
        el.style.opacity="0.95";
        el.style.MozBorderRadius="1px";
    },
    locate: function(e)
    {
        var posx=0,posy=0;
        if(e==null) e=window.event;
        if(e.pageX || e.pageY){
            posx=e.pageX; posy=e.pageY;
            }
        else if(e.clientX || e.clientY){
            if(document.documentElement.scrollTop){
                posx=e.clientX+document.documentElement.scrollLeft;
                posy=e.clientY+document.documentElement.scrollTop;
                }
            else{
                posx=e.clientX+document.body.scrollLeft;
                posy=e.clientY+document.body.scrollTop;
                }
            }
        document.getElementById("btc").style.top=(posy+20)+"px";
        document.getElementById("btc").style.left=(posx-50)+"px";
    },
    
    showTooltip: function (e){
        document.getElementById("btc").appendChild(this.tooltip);
        Jesper.link.Bubbles.prototype.locate(e);
    },
    
    hideTooltip: function (e){
        var d=document.getElementById("btc");
        if(d.childNodes.length>0) d.removeChild(d.firstChild);
    }
});