/*
Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
This notice MUST stay intact for legal use
Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code

Please note! The original script has been modified to accomodate IT-Jobbanks needs and to fix a few bugs! 
*/

var offsetxpoint=-150 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false

if (ie||ns6)
    var tipobj;
    complaceo_AddLoadEvent( function() {
		tipobj = complaceo_GetObject("tooltip");
	}
);

function complaceo_AddLoadEvent(f)
{
     
	var old = window.onload; 
	
	if (typeof window.onload != 'function') 
		{ window.onload = f; } else { window.onload = function onloadHandler() { old(); f();} } 
}

function complaceo_GetObject( o )
{
	if (document.all)
		return document.all[o];
	else
		return document.getElementById(o);
}

// Attach the hide function to all links with the correct class
// TODO: create a global function, available on window onload, where all links are processed, and send functions to this global function
// addLoadEvent( function() {
//		var oLinks = document.getElementsByTagName( "a" );
//		var oLink, i = 0;
//		while ( oLink = oLinks[i++] ){
//			if ( oLink.className.indexOf( "ddrivetip" ) != -1 ) {
//				oLink.onmouseout = hideddrivetip;
//			}
//		}
//	}
//);

function ddrivetip(parent, thetext, thecolor, thewidth, contentFromTinyMCE) {
    if (ns6||ie) {
        if (typeof thewidth!="undefined" && thewidth!=0) {
            tipobj.style.width=thewidth+"px"
        }
        
        if (typeof thecolor!="undefined" && thecolor!="" && thecolor!=0 && thecolor!=null) {
            tipobj.style.backgroundColor=thecolor
        }

        if (typeof contentFromTinyMCE!="undefined" && contentFromTinyMCE!="" && contentFromTinyMCE!=0) {
            tipobj.setAttribute("class", "ContentFromTinyMCE ToolTipWithContentFromTinyMCE");
        }
        
        tipobj.innerHTML=thetext
        enabletip=true
        
        // create iframe that prevents IE 6's bleeding bug
        if ( is_ie6down && !tipobj.getElementsByTagName( "iframe" )[0] ){
            tipobj.innerHTML = '<iframe class="bleedMat" src="about:blank" scrolling="no" frameborder="0"></iframe>' + tipobj.innerHTML;
            var ieMat = tipobj.firstChild;
            ieMat.style.width = tipobj.offsetWidth + "px";
            ieMat.style.height = tipobj.offsetHeight + "px";			
        }
        parent.onmousemove = positionddrivetip;
        return false
    }    
}

function positionddrivetip(e){
    if (enabletip){
        var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
        var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
        
        //Find out how close the mouse is to the corner of the window
        var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
        var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

        var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

        //if the horizontal distance isn't enough to accomodate the width of the context menu
        if (rightedge<tipobj.offsetWidth)
        {
            //move the horizontal position of the menu to the left by it's width
            var left = ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth : window.pageXOffset+e.clientX-tipobj.offsetWidth
            if (left < 5)
                left = 5
            tipobj.style.left= left + "px"
        }
        else if (curX<leftedge)
            tipobj.style.left="5px"
        else
            //position the horizontal position of the menu where the mouse is positioned
            tipobj.style.left=curX+offsetxpoint+"px"

        //same concept with the vertical position
        if (bottomedge<tipobj.offsetHeight)
        {
            var top = ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint
            if ( top < 0 )
            {
                // The tooltip is higher than the available size. Place the 
                // tooltip under the parent and resize it to fit the entire
                // witch of the screen.
                top = curY+offsetypoint
                tipobj.style.left = "5px"
                var width = ie&&!window.opera? ietruebody().clientWidth : window.innerWidth
                width = width - 40;
                tipobj.style.width = width+"px"
            }
            tipobj.style.top= top +"px" 
        }
        else
            tipobj.style.top=curY+offsetypoint+"px"
        tipobj.style.visibility="visible"
    }
}

function hideddrivetip(parent){
    if (ns6||ie){
        enabletip=false
        tipobj.style.visibility="hidden"
        tipobj.style.left="-1000px"
        tipobj.style.backgroundColor=''
        tipobj.style.width=''
    }
    parent.onmousemove = null;
}

//document.onmousemove=positionddrivetip

