// JavaScript Document
// position of the tooltip relative to the mouse in pixel //
var offsetx = 22;
var offsety = 10;
var offsetGuard = 20;
var ttMinXPos = 5;
var ttMinYPos = 5;
var ttMaxWidth = 500;
var screenBorder = 50;
var mouseOutEvent = 0;
var setTimeoutObj;
var ttIsDisplayed = 0;
var TT_DELAY = 300;
var gMouseX, gMouseY;
var gTTPosX, gTTPosY, gTTHeight, gTTWidth, gElemOffsetArray,
gScreenHeight,gScreenWidth,gDocumentHeight,gDocumentWidth,gScrollX,gScrollY,gCounter;
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);
function test(text) {
alert(text);
}
/**
* returns a hashtable (array):
*
* width : the width of the viewport
* height : the height of the viewport
* vScroll : the vertical scroll
* hScroll : the horizontal scroll
* totalWidth : the width of the page
* totalHeight : the height of the page
*/
window.getSize = function() {
var width = 0, height = 0, vScroll = 0, hScroll = 0, tWidth = 0, tHeight = 0;
if ( typeof( window.innerWidth ) == 'number' ) {
width = window.innerWidth;
height = window.innerHeight;
}
else {
if ( document.documentElement && document.documentElement.clientWidth ) {
width = document.documentElement.clientWidth;
height = document.documentElement.clientHeight;
}
else {
if ( document.body && document.body.clientWidth ) {
width = document.body.clientWidth;
height = document.body.clientHeight;
}
}
}
if( document.body && ( document.body.scrollTop || document.body.scrollLeft ) ) {
vScroll = document.body.scrollTop;
hScroll = document.body.scrollLeft;
}
else {
if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
vScroll = document.documentElement.scrollTop;
hScroll = document.documentElement.scrollLeft;
}
else {
if( window.pageYOffset ) {
vScroll = window.pageYOffset;
hScroll = window.pageXOffset;
}
}
}
var xScroll = 0, yScroll = 0;
if(document.body) {
if ( window.innerHeight && window.scrollMaxY ) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
}
else {
if (document.body.scrollHeight > document.body.offsetHeight ) {
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
}
else {
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
}
}
tWidth = Math.max( width, xScroll );
tHeight = Math.max( height, yScroll );
return { width: width, height: height, vScroll: vScroll, hScroll: hScroll, totalWidth: tWidth, totalHeight: tHeight };
}
function newelement(newid)
{
if(document.createElement)
{
var el = document.createElement('div');
el.id = newid;
with(el.style)
{
display = 'none';
//display = 'block';
//visibility = 'hidden';
//position = 'absolute';
position = 'absolute';
}
el.innerHTML = ' ';
document.body.appendChild(el);
} else {
alert("could not create tt");
}
}
function moveTT(e) {
getmouseposition(e);
mouseOverElement(e);
setTT(e);
if(!(isInside=isMouseInsideElement('navBox'))) {
navHover('', '0' );
}
//debugAppend('
isMouseInsideElement:: navBox = '+isInside);
}
function setTT(e) {
getTTAttribs(gMouseX, gMouseY);
placeTT(gTTPosX, gTTPosY, gTTWidth, gTTHeight);
}
function getmouseposition(ev) {
ev = ev || window.event;
if(!ev) return;
if(ev.pageX || ev.pageY){
//if(!ie5){
//debug(ie5+":: page - ");
x=ev.pageX;
y=ev.pageY;
} else {
//debug(ie5+":: client - ");
x=ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y=ev.clientY + document.body.scrollTop - document.body.clientTop
}
gMouseX=x;
gMouseY=y;
getDocumentAttribs();
//debug("x="+gMouseX+", y="+gMouseY+" : scrollx="+gScrollX+", scrolly="+gScrollY+" : screenH="+gScreenHeight+", screenW="+gScreenWidth+" : docH="+gDocumentHeight+", docW"+gDocumentWidth+" ["+gCounter+"]");
if(!ie5) {
gMouseX += document.body.scrollLeft;
gMouseY -= gScrollY;
} else {
gMouseX -= document.body.scrollLeft;
gMouseY += gScrollY;
}
//debugAppend(" ::: ev="+ev+", mx="+gMouseX+", my="+gMouseY+"
");
}
function getTTAttribs(mousex, mousey) {
//alert("getTTAttribs("+mousex+", "+mousey+")");
var dbgText = '';
if(document.getElementById)
{
var iebody=(document.compatMode &&
document.compatMode != 'BackCompat') ?
document.documentElement : document.body;
var ttElem = document.getElementById('tooltip');
// Max TT width & height
/* var ttWidth = ttElem.width || ttElem.offsetWidth;
ttWidth = Math.min(ttWidth, ttMaxWidth);
if(ttWidth == 0) ttWidth = ttMaxWidth;
ttElem.style.width = ttWidth+'px';
var ttHeight = ttElem.height || ttElem.offsetHeight;
*/ //alert("getTTAttribs("+ttWidth+", "+ttHeight+")");
if(typeof window.getSize != 'undefined') {
//alert("getsize");
//dbgText = "
[getSize()]";
// Position the tt in the correct quadrant for its location on the screen
var pagex = gScrollX;
var pagey = gScrollY;
//debugAppend(" - getSize["+mousex+"/"+mousey+"/"+screenWidth+"/"+screenHeight+"/"+documentWidth+"/"+documentHeight+"/"+pagex+"/"+pagey+"]");
var x = mousex;
var y = mousey;
/* var w = screenWidth;
var h = screenHeight;
*/
// Check for x position changes
////if(x > (w/2)) { // Set it in the left side of the cursor
xLimit = gScreenWidth-(gTTWidth+offsetx+offsetGuard);
if(x > xLimit) { // Set it in the left side of the cursor
var ox = - gTTWidth - (offsetx); // Just 1*offsetx
//var ox = -(x - xLimit);
} else {
//lixlpixel_tooltip.style.width = 'auto';
var ox = offsetx;
}
ox += pagex;
// Check for y position changes
////if(y > (h/2)) { // Set it in the top side of the cursor
yLimit = gScreenHeight-(gTTHeight+offsety+offsetGuard);
if(!ns6) var yLimitExtra = pagey;
else var yLimitExtra = 0;
if(y > (yLimit+yLimitExtra)) { // Set it in the top side of the cursor
//var oy = - ttHeight - (2*offsety);
var oy = - (y - yLimit);
} else {
var oy = offsety-yLimitExtra;
}
oy += pagey;
//dbgText = "
[tw:"+ttWidth+"/th:"+ttHeight+"/mx:"+x+"/my:"+y+"/ww:"+w+"/wh:"+h+"/ox:"+ox+"/oy:"+oy+"]";
} else {
/* pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
*/ ox = offsetx + gScrollX;
oy = offsety + gScrollY;
//alert("no getSize["+mousex+"/"+mousey+"/"+ttWidth+"/"+ttHeight+"/"+documentWidth+"/"+documentHeight+"/"+pagex+"/"+pagey+"]");
}
// Ensure no -ve values
var newx = (mousex+ox);
newx = Math.max(ttMinXPos, newx);
var newy = (mousey+oy);
newy = Math.max(ttMinYPos, newy);
// Make sure that the TT is not under the mouse cursor
if(newx<=mousex && (newx+gTTWidth)>=(mousex-offsetx)) {
if(newy<=mousey && (newy+gTTHeight)>=(mousey)) {
newy = mousey-gTTHeight-offsety;
}
}
gTTPosX = newx;
gTTPosY = newy;
/* gScreenHeight=screenHeight;
gScreenWidth=screenWidth;
gDocumentHeight=documentHeight;
gDocumentWidth=documentWidth;
gScrollX=pagex;
gScrollY=pagey;
*/
//debugAppend(" - getTTAttrib:"+gMouseX+"/"+gMouseY+"//"+gTTPosX+"/"+gTTPosY+"//"+gScrollX+"/"+gScrollY);
}
}
function getDocumentAttribs() {
//alert("getDocumentAttribs("+mousex+", "+mousey+")");
var dbgText = '';
if(document.getElementById)
{
var iebody=(document.compatMode &&
document.compatMode != 'BackCompat') ?
document.documentElement : document.body;
if(typeof window.getSize != 'undefined') {
//alert("getsize");
//dbgText = "
[getSize()]";
// Position the tt in the correct quadrant for its location on the screen
var w = window.getSize();
var screenHeight = w.height;
var screenWidth = w.width;
var documentHeight = w.totalHeight;
var documentWidth = w.totalWidth;
var pagex = w.hScroll;
var pagey = w.vScroll;
//dbgText = "
[tw:"+ttWidth+"/th:"+ttHeight+"/mx:"+x+"/my:"+y+"/ww:"+w+"/wh:"+h+"/ox:"+ox+"/oy:"+oy+"]";
} else {
pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
//alert("no getSize["+mousex+"/"+mousey+"/"+ttWidth+"/"+ttHeight+"/"+documentWidth+"/"+documentHeight+"/"+pagex+"/"+pagey+"]");
}
gScreenHeight=screenHeight;
gScreenWidth=screenWidth;
gDocumentHeight=documentHeight;
gDocumentWidth=documentWidth;
gScrollX=pagex;
gScrollY=pagey;
//debugAppend(" - getDocumentAttribs["+gScreenWidth+"/"+gScreenHeight+"/"+gDocumentWidth+"/"+gDocumentHeight+"/"+gScrollX+"/"+gScrollY+"]");
//debugAppend(" - getTTAttrib:"+gMouseX+"/"+gMouseY+"/"+gTTPosX+"/"+gTTPosY+"/"+gTTWidth+"/"+gTTHeight);
}
}
function placeTT(ttPosX, ttPosY, ttWidth, ttHeight) {
//debugAppend(" - placeTT(ttElem, "+ttPosX+", "+ttPosY+", "+ttWidth+", "+ttHeight+")");
var ttElem = document.getElementById('tooltip');
if(!ttElem) return 0;
placeElem(ttElem, ttPosX, ttPosY);
if(ttWidth) ttElem.style.width = ttWidth+"px";
return 1;
}
function placeElem(elem, x, y) {
if(!elem || !x || !y) {
//debugAppend(" - placeElem(ttElem, "+x+", "+y+") - skipped");
return 0;
}
////alert("placeElem(ttElem, "+x+", "+y+")");
elem.style.left = x + 'px';
elem.style.top = y + 'px';
return 1;
}
function tooltip(tip, className) {
//alert('hello');
mouseOutEvent=0;
if(typeof(tip) == "object") { // inherited from tools, shift args
var a=tooltip.arguments;
tip = a[1];
className = a[2];
}
if( ttIsDisplayed == 0) setTimeoutObj = setTimeout(function tmp(e) {showTT(e, tip);}, TT_DELAY);
//document.onmousemove = getmouseposition; // Keep tracking mouse for latest display position
document.onmousemove = moveTT; // Keep tracking mouse for latest display position
document.onmouseout = exit; // If we leave the tt area then cancel the display
}
function showTT(e, tip)
{
//debugAppend('showTT()');
if( ttIsDisplayed == 1) return; // Displayed already
//getmouseposition(e);
// Ensure the div is created/present
if(!document.getElementById('tooltip')) newelement('tooltip');
var ttElem = document.getElementById('tooltip');
if(!ttElem) return;
ttElem.innerHTML = unescape(tip);
if(typeof(className)!= 'undefined' && className.length>0) {
ttElem.className = 'tooltip '+className;
} else {
ttElem.className = 'tooltip';
}
placeTT(-1000, gMouseY); // Off the screen
//ttElem.style.visibility = 'visible'; // Show to get dimensions
ttElem.style.display = 'block'; // Needs to be here, if non then no dimensions
ttElem.style.width = 'auto'; // Let it float to a natural size before resizing
ttElem.style.zIndex = '1000';
// Max TT width & height
var ttWidth = ttElem.width || ttElem.offsetWidth;
ttWidth = Math.min(ttWidth, ttMaxWidth);
if(ttWidth == 0) ttWidth = ttMaxWidth;
ttElem.style.width = ttWidth+'px';
var ttHeight = ttElem.height || ttElem.offsetHeight;
//alert("getTTAttribs("+ttWidth+", "+ttHeight+")");
gTTHeight = ttHeight;
gTTWidth = ttWidth;
setTT(e); //
ttElem.style.visibility = 'visible';
document.onmousemove = moveTT;
ttIsDisplayed = 1;
//moveTT(e);
}
function exit()
{
clearTimeout(setTimeoutObj);
document.onmouseout = '';
//document.onmousemove = '';
if( ttIsDisplayed == 0) return; // Not displayed already
if(!document.getElementById('tooltip')) return;
var lixlpixel_tooltip = document.getElementById('tooltip');
lixlpixel_tooltip.style.display = 'none';
ttIsDisplayed = 0;
//document.getElementById('tooltip').style.visibility = 'hidden';
mouseOutEvent=1;
}