


/***********************************************
* 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
***********************************************/

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=10 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
var flagDontMove = false
var flagActive = false

//user defined freeze
var freezetip=false

//for delayfreeze 
var defaultFreeze_ms = 3*60 //milliseconds 
var defaultFreeze_timestamp

if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltipStockPriceChart"] : document.getElementById? document.getElementById("dhtmltooltipStockPriceChart") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function ddrivetip(thetext, thecolor, thewidth, magic){
	if (ns6||ie){
	    if (typeof thewidth != "undefined") {
	        if (thewidth.toString().indexOf('%') != -1) {
	            //alert('test');
	            //tipobj.style.width = thewidth;
	        } else {
	            tipobj.style.width = thewidth + "px"
	        }
	    }
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		if (typeof magic!="undefined" && magic!="") flagDontMove = true
		tipobj.innerHTML=thetext
		enabletip=true
		freezetip=false;
		
		var dateObj = new Date();
		defaultFreeze_timestamp = dateObj.getTime();

		return false
	}
}

function positiontip(e){

if ((!enabletip) || (flagDontMove && flagActive))
	return;
	
if (tipobj.style.visibility == "visible") //already displayed (first time), check if there is a default freeze (delay)
{
	var dateObj = new Date();
	var currentTimestamp = dateObj.getTime();	
	if ((defaultFreeze_timestamp + defaultFreeze_ms) >= currentTimestamp)
		return;
}	

if (freezetip) //if freezed, handle auto-hide here
{
	//find out if mouse is outside the tooltip , auto hide it
	var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
	var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;

	var tipX = tipobj.offsetLeft; 
	var tipY = tipobj.offsetTop;
	var tipX2 = tipX + tipobj.offsetWidth;
	var tipY2 = tipY + tipobj.offsetHeight;
	
	//expand to cover offset 
	if (offsetxpoint > 0)
		tipX -= (offsetxpoint+1);
	if (offsetypoint > 0)
		tipY -= (offsetypoint+1);
		

	if (!((curX>=tipX && curX<=tipX2) && (curY>=tipY && curY<=tipY2))) //current cursor is inside div element
	//if ((curX < tipX || curX > tipX2) || (curY<tipY || curY>tipY2)) //current cursor is outside div element
	{
		//alert("auto hiding tooltip\n" + "curX : " + curX + " curY : " + curY + "\ntipX : " + tipX + " tipY : " + tipY + "\ntipX2 : " + tipX2 + " tipY2 : " + tipY2);
		hideddrivetip();
		
		return;
	}
}
else
{	
	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
		//original 
		//tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
		
		var pageX = ie? ietruebody().scrollLeft : window.pageXOffset;
		var eClientX = ie? event.clientX : e.clientX;
		
		//alert("pageX : " + pageX + " eClientX : " + eClientX);
		
		if (eClientX - pageX >= tipobj.offsetWidth) //if there is enough space on the left side
		{
			tipobj.style.left=pageX+eClientX-tipobj.offsetWidth+"px";
			//alert("tipobj.offsetWidth : " + tipobj.offsetWidth + "\npageX : " + pageX + " eClientX : " + eClientX + " ==> " + tipobj.style.left);
			//tipobj.offsetWidth is a smaller value in Firefox compared to IE, thus image is not properly using the left space 
		}
		else //align left
			tipobj.style.left= pageX + "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)
	{
		//original
		//tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
		var pageY = ie? ietruebody().scrollTop : window.pageYOffset
		var eClientY = ie? event.clientY : e.clientY
		
		if (eClientY - pageY >= tipobj.offsetHeight) //if there is enough space on top
			tipobj.style.top=pageY+eClientY-tipobj.offsetHeight-offsetypoint+"px";
		else //align on the cursor
			tipobj.style.top=curY+offsetypoint+"px"	
	}
	else
		tipobj.style.top=curY+offsetypoint+"px"
		flagActive = true;
		tipobj.style.visibility="visible"

}
}

function hideddrivetip(){
if (ns6||ie){
freezetip=false
enabletip=false
flagActive = false;
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

function freezeddrivetip(){
if (ns6||ie){
	freezetip=true
	//store current xy position?
}
}

document.onmousemove=positiontip
