﻿/***********************************************
* Cool DHTML tooltip script II- © 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
***********************************************/
 /*13.Aug.2009, TuấnHT đổi tên cho không trùng với các tooltip khác
	offsetfromcursorX	=>	Xcursor
	offsetfromcursorY	=>	Ycursor
	dhtmltooltip		=>	tooltipImage
	dhtmlpointer		=>	xóa bỏ
	ddrivetip()			=>	jsShowImage()
	hideddrivetip()		=>	jsHideImage()
	ie			=>	varIE
	ns6			=>	varNS6
	enabletip	=>	varDisplay
	tipobj		=>	objTip
	thetext		=>	strText
	ietruebody()		=>	truebodyIE()
	positiontip(e)		=>	locateTip(e)
 */

var Xcursor=5 //Customize x offset of tooltip
var Ycursor=5 //Customize y offset of tooltip

document.write('<div id="tooltipImage"></div>') //write out tooltip DIV

var varIE = document.all
var varNS6 = document.getElementById && !document.all
var varDisplay = false

if ( varIE || varNS6 )
	var objTip = document.all ? document.all["tooltipImage"] : document.getElementById ? document.getElementById("tooltipImage") : ""

function truebodyIE()
{
	return ( document.compatMode && document.compatMode!="BackCompat" )? document.documentElement : document.body
}

function jsShowImage(strImageSource)
{
	if ( varNS6 || varIE )
	{
		var strText = "<table cellspacing='0' cellpadding='0' class='tooltipImageTable'>";
		strText += "<tr><td><img src='" + strImageSource + "' height='270' border='0'></td></tr>";
		strText += "</table>";

		objTip.innerHTML = strText;
		varDisplay = true;
		return false;
	}
}

function locateTip(e)
{
	if (varDisplay)
	{
		var nondefaultpos = false
		var curX = (varNS6) ? e.pageX : event.clientX+truebodyIE().scrollLeft;
		var curY = (varNS6) ? e.pageY : event.clientY+truebodyIE().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var winwidth = varIE && !window.opera ? truebodyIE().clientWidth : window.innerWidth-20
		var winheight = varIE && !window.opera ? truebodyIE().clientHeight : window.innerHeight-20

		var rightedge = varIE && !window.opera? winwidth-event.clientX-Xcursor : winwidth-e.clientX-Xcursor
		var bottomedge = varIE && !window.opera? winheight-event.clientY-Ycursor : winheight-e.clientY-Ycursor

		var leftedge=(Xcursor<0)? Xcursor*(-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<objTip.offsetWidth)
		{
			//move the horizontal position of the menu to the left by it's width
			objTip.style.left=curX-objTip.offsetWidth+"px"
			nondefaultpos=true
		}
		else if (curX<leftedge)
			objTip.style.left="5px"
		else
		{
			//position the horizontal position of the menu where the mouse is positioned
			objTip.style.left=curX+Xcursor+"px"
		}

		//same concept with the vertical position
		if (bottomedge<objTip.offsetHeight)
		{
			objTip.style.top=curY-objTip.offsetHeight-Ycursor+"px"
			nondefaultpos=true
		}
		else
		{
			objTip.style.top=curY+Ycursor+"px"
		}
		objTip.style.visibility="visible"
	}
}

function jsHideImage()
{
	if ( varNS6 || varIE )
	{
		varDisplay = false
		objTip.style.visibility = "hidden"
		objTip.style.left = "-1000px"
		objTip.style.backgroundColor = ''
		objTip.style.width = ''
	}
}

document.onmousemove=locateTip

