//######################################################################
//
//            			   FSTOOLTIPS.JS   V1.1
//                         FUSIONSCRIPTZ   2006
//                       support@fusionscriptz.com
//
//                    Call script using similar tags
//
//  for links use:  <a href="index.html" onmouseover="tooltip('Tooltip Title','Tooltip Heading','Tooltip Content');">
//  for images use: <img src="image.jpg" onmouseover="tooltip('Tooltip Title','Tooltip Heading','Tooltip Content');">
//
//######################################################################




//########################  START CONFIG  ##############################

var offsetx = 15;
var offsety = 10;
var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 
var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);

var agt=navigator.userAgent.toLowerCase();
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie7orBelow = (/msie (4|5|6|7)\.0/i.test(agt) && !/opera/i.test(agt));


//########################   END CONFIG   ##############################

function newelement(newid){ 
    if(document.createElement){ 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            display = 'none';
            position = 'absolute';
        } 
        document.body.appendChild(el);
        
        if(!is_ie){
			el.innerHTML = '&nbsp;';
        }
		else {
			var iframeEl = document.createElement('iframe');
			iframeEl.id = newid + '_iframe';
			with(iframeEl.style)
			{ 
				position = 'absolute';
			} 
			el.appendChild(iframeEl);
	        
			var internalDiv = document.createElement('div');
			internalDiv.id = newid + '_int';
			with(internalDiv.style)
			{ 
				position = 'relative';
			} 
			internalDiv.innerHTML = '&nbsp;'; 
			el.appendChild(internalDiv);
		}
    } 
} 

//######################################################################

function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	return [myWidth, myHeight];
}

function findPosition( oElement ) {
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
      posX += oElement.offsetLeft;
      posY += oElement.offsetTop;
    }
    return [ posX, posY ];
  } else {
    return [ oElement.x, oElement.y ];
  }
}

function getmouseposition(e){
    if(document.getElementById){

        var iebody=(document.compatMode && document.compatMode != 'BackCompat') ? 
        		document.documentElement : document.body;
        
        pagex = (
				isapple == 1 ? 
					0 :
						(ie5) ?
							iebody.scrollLeft :
								window.pageXOffset
			);
        pagey = (
			isapple == 1 ? 
				0:
					(ie5) ? 
						iebody.scrollTop : 
							window.pageYOffset);
							
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;
        
        var fstooltip = document.getElementById('tooltip');
        
        if (is_ie && !is_ie7orBelow) {
        	mousex -= pagex;
        	mousey -= pagey;
        }
        
        var absX = mousex + pagex;
        var absY = mousey + pagey;
        
        if(	absX < fstooltip.XLeft - 3 || absX > fstooltip.XRight + 3 ||
					absY < fstooltip.YTop - 3 || absY > fstooltip.YBottom + 3){
					exit();
					return;	
				}
				
				var winSize = getWindowSize();
		        
		    //	the X coordinate
				if ((mousex + offsetx + fstooltip.clientWidth + 5) > winSize[0]) {
					var xCoordinate = mousex + pagex - offsetx - fstooltip.clientWidth;
					if(xCoordinate < pagex){
						xCoordinate = pagex + 1;
					}
					fstooltip.style.left = xCoordinate + "px"; 
				} else { 
					fstooltip.style.left = (mousex+pagex+offsetx) + "px"; 
				}
		
				//	the Y coordinate
				if ((mousey + offsety + fstooltip.clientHeight + 5) > winSize[1]) {
					var yCoordinate = mousey + pagey - offsety - fstooltip.clientHeight;
					if(yCoordinate < pagey){
						yCoordinate = pagey + 1;
					}
					fstooltip.style.top =  yCoordinate + "px"; 
				}	else { 
					fstooltip.style.top = (mousey+pagey+offsety) + "px"; 
				}
				
				if(is_ie){
				    var iframe = document.getElementById('tooltip_iframe');
						iframe.style.width = fstooltip.offsetWidth;
						iframe.style.height = fstooltip.offsetHeight;
						iframe.style.display = 'block';
				}
				
				fstooltip.style.display = 'block';
    	}
}
//######################################################################

function tooltip(sender, tiptitle, tipbold, tipnormal, width){

    if(!document.getElementById('tooltip')) newelement('tooltip');
    
    var pos = findPosition(sender);
        
    var ediv = document.getElementById('tooltip');
    var idiv = document.getElementById('tooltip_int');
    var iframe = document.getElementById('tooltip_iframe');
    
    ediv.XLeft = pos[0];
    ediv.XRight = pos[0] + sender.clientWidth;
    ediv.YTop = pos[1];
    ediv.YBottom = pos[1] + sender.clientHeight;
    
    var contentDiv;
    if(is_ie){
		contentDiv = idiv;
    }
    else {
		contentDiv = ediv;
    }
    contentDiv.innerHTML = 
		'<table class="fstooltips"' + 
		(width != null ? ' style="width: ' + width +   '" ' : '') + 
		'cellpadding="2" cellspacing="0"><tr><td class="tipheader"><img src="../scripts/fstooltips/tip_grey.gif" height="14" width="14" align="right">' + tiptitle + '</td></tr><tr><td class="tipcontent">' + tipnormal + '</td></tr></table>';
    ediv.style.display = 'block';

		if(is_ie){
			iframe.style.width = ediv.offsetWidth;
			iframe.style.height = ediv.offsetHeight;
			iframe.style.display = 'block';
		}
	
    document.onmousemove = getmouseposition;
}

//######################################################################

function exit(){
    document.onmousemove = null;
    document.getElementById('tooltip').style.display = 'none';
    if(is_ie){
	    document.getElementById('tooltip_iframe').style.display = 'none';
    }
}

//######################################################################