var hints={
    opacity: 0,
    timerID: null,
    findPos:function(obj) {
        var curleft = curtop = 0;
        var curheight=obj.offsetHeight;
        var curwidth=obj.offsetWidth;
        if (obj.offsetParent) {
            curleft = obj.offsetLeft
            curtop = obj.offsetTop
            while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
            }
        }
        return [curleft,curtop,curwidth,curheight];
    },
    calc_opt_size:function(hintid){
        //we'll have a +/-of about 100 on the width to get a best fit
        text=document.getElementById(hintid).innerHTML; 
        var initwidth=300;
        var optheight=50;
        var hint=document.getElementById("hint");
        hint.style.visibility="hidden";
        hint.innerHTML=text;
        hint.style.width=initwidth+"px";
        while(initwidth>200 && initwidth<400 && hint.offsetHeight<optheight){
            if(hint.offsetHeight>optheight) initwidth=initwidth-10;
                else initwidth=initwidth-10;
            hint.style.width=initwidth+"px";
        }
        document.getElementById("hint-top-bar").style.left="7px";
        document.getElementById("hint-top-bar").style.top="0px";
        document.getElementById("hint-top-bar").style.width=(initwidth-7)+"px";
        
        document.getElementById("hint-bottom-bar").style.left="7px";
        document.getElementById("hint-bottom-bar").style.top=(hint.offsetHeight+5)+"px";
        document.getElementById("hint-bottom-bar").style.width=(initwidth-7)+"px";
        
        document.getElementById("hint-left-bar").style.left="0px";
        document.getElementById("hint-left-bar").style.top="7px";
        document.getElementById("hint-left-bar").style.height=(hint.offsetHeight-5)+"px";
        
        document.getElementById("hint-right-bar").style.left=(initwidth+5)+"px";
        document.getElementById("hint-right-bar").style.top="7px";
        document.getElementById("hint-right-bar").style.height=(hint.offsetHeight-5)+"px";
        
        hint.style.visibility="visible";
        
    },

    positionhint:function(obj){
        var pos=this.findPos(obj);
        var hint=document.getElementById('hint_tl');
        var arrow=document.getElementById('hint-arrow');
        var bodywidth=document.getElementsByTagName('body')[0].offsetWidth;
        if((pos[0]-10+hint.offsetWidth)>bodywidth){
            left=bodywidth-hint.offsetWidth-5;
        }else{
            left=(pos[0]-10);
        } 
        document.getElementById('hint-arrow').style.left=((pos[0]-10)-left+20+left)+"px";
        hint.style.left=left+"px";
        hint.style.top=(pos[1]+pos[3]+15)+"px";
        arrow.style.top=(pos[1]+pos[3]+3)+"px";
        var bodywidth=document.getElementsByTagName('body')[0].offsetWidth;
    }, 
    showhint:function(hintid,obj){
        document.getElementById('hint_tl').style.display="";
        document.getElementById('hint-arrow').style.display="";
        this.calc_opt_size(hintid);
        this.positionhint(obj);
        this.opacity=0;
        var obj=document.getElementById('hint_tl');
        var arrow=document.getElementById('hint-arrow');
        if (obj.filters&&obj.filters[0]){
            if (typeof obj.filters[0].opacity=="number"){ //if IE6+
            obj.filters[0].opacity=0
            arrow.filters[0].opacity=0
            }else{ //else if IE5.5-
            obj.style.filter="alpha(opacity=0)"
            arrow.style.filter="alpha(opacity=0)"
            }
        }
        else
        {
            arrow.style.opacity=0;
            obj.style.opacity=0;
        }
				document.getElementById('hint_tl').style.display="";
        arrow.style.display="";
        clearTimeout(this.timerID);
        this.timerID=setTimeout("hints.fadein()", 500);
    },
    fadein:function(){
        var obj=document.getElementById('hint_tl');
        var arrow=document.getElementById('hint-arrow');
        if(this.opacity<1){
            this.opacity=this.opacity+0.1;
            if (obj.filters&&obj.filters[0]){
                if (typeof obj.filters[0].opacity=="number"){ //if IE6+
                obj.filters[0].opacity=(this.opacity*100)
                arrow.filters[0].opacity=(this.opacity*100)
                }else{ //else if IE5.5-
                obj.style.filter="alpha(opacity="+(this.opacity*100)+")"
                arrow.style.filter="alpha(opacity="+(this.opacity*100)+")"
                }
            }
            else
            {
                obj.style.opacity=this.opacity;
                arrow.style.opacity=this.opacity;
                clearTimeout(this.timerID);
            }
            this.timerID=setTimeout("hints.fadein()", 10);
        }
    },    
    fadeout:function(){
        var obj=document.getElementById('hint_tl');
        var arrow=document.getElementById('hint-arrow');
        if(this.opacity>0){
            this.opacity=this.opacity-0.1;
            if (obj.filters&&obj.filters[0]){
                if (typeof obj.filters[0].opacity=="number"){ //if IE6+
                obj.filters[0].opacity=(this.opacity*100)
                arrow.filters[0].opacity=(this.opacity*100)
                }else{ //else if IE5.5-
                obj.style.filter="alpha(opacity="+(this.opacity*100)+")"
                arrow.style.filter="alpha(opacity="+(this.opacity*100)+")"
                }
            }
            else
            {
                obj.style.opacity=this.opacity;
                arrow.style.opacity=this.opacity;
            }
            this.timerID=setTimeout("hints.fadeout()", 10);
        }
        else
        {
            document.getElementById('hint_tl').style.display="none";
            arrow.style.display="none";
            clearTimeout(this.timerID);
        }
    },
    hidehint:function(){
        clearTimeout(this.timerID);
        this.timerID=setTimeout("hints.fadeout()", 10);
    },
    init:function(){
       var body=document.getElementsByTagName('body')[0];
	var newdiv=document.createElement("div");
        body.appendChild(newdiv);
	newdiv.innerHTML='<div id="hint-arrow" style="filter: alpha(opacity=0);background-image: url(\'/themes/newarmour/css/images/arrow.gif\'); position: absolute; width: 24px; height: 13px; top: -13px; left: 20px;"></div><div id="hint_tl" style="filter: alpha(opacity=0); display: none; background-image: url(\'/themes/newarmour/css/images/tl.gif\'); background-repeat: no-repeat; position: absolute; top: 300px; left: 50px;"><div id="hint_bl" style="background-image: url(\'/themes/newarmour/css/images/bl.gif\'); background-position: bottom left; background-repeat: no-repeat;"><div id="hint_tr" style="background-image: url(\'/themes/newarmour/css/images/tr.gif\'); background-position: top right; background-repeat: no-repeat;"><div id="hint_br" style="background-image: url(\'/themes/newarmour/css/images/br.gif\'); background-position: bottom right; background-repeat: no-repeat; padding: 5px;"><div id="hint-top-bar" style="background-color: #f8ff8e; position: absolute; height: 5px;font-size: 1px;"></div><div id="hint-bottom-bar" style="background-color: #f8ff8e; position: absolute; height: 5px;font-size: 1px;"></div><div id="hint-left-bar" style="background-color: #f8ff8e; position: absolute; width: 5px;font-size: 1px;"></div><div id="hint-right-bar" style="background-color: #f8ff8e; position: absolute; width: 5px;font-size: 1px;"></div><div id="hint" style="font-size: 12px; line-height: 17px; background-color: #f8ff8e;"></div></div></div></div></div>';
        var tags=document.getElementsByTagName("*");
        for(i=0; i<tags.length; i++){
            if(tags[i].getAttribute("hint")){
                eval("tags[i].onmouseover=function(e){if (!e) var e = window.event;	if (e.target) targ = e.target;	else if (e.srcElement) targ = e.srcElement; hints.showhint('"+tags[i].getAttribute("hint")+"', targ);};");
                eval("tags[i].onmouseout=function(e){if (!e) var e = window.event;	if (e.target) targ = e.target;	else if (e.srcElement) targ = e.srcElement; hints.hidehint();};");
            }
        }
    }
}

