// *************************************************************************************************************
var isCSS, isW3C, isIE4, isNN4; 
var offsetX, offsetY, objBox, objH, objW, isHover, doFollow, followMouse, hideDelay, hideId, winH, winW, sURL;
var dX, dY;
var roundBox = false;
function initTooltip(){
	if (document.images) {
		isCSS = (document.body && document.body.style) ? true : false;
		isW3C = (isCSS && document.getElementById) ? true : false;
		isIE4 = (isCSS && document.all) ? true : false;
		isNN4 = (document.layers) ? true : false;
		isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
		isIEAll = (document.all) ? true : false;
		objBox = getRawObject("tooltipBox");
		objH = getObjectHeight("tooltipBox")
		objW = getObjectWidth("tooltipBox")
		offsetX = 15;
		offsetY = 16;
		winH = getInsideWindowHeight()
		winW = getInsideWindowWidth()
		isHover = false;
		doFollow = true;
		followMouse = false; 
		roundBox = true;
		hideDelay = 50;
		hideId = 0;
		dX = 2;
		dY = 2;
		sURL = "";
	  	objBox.onmouseover = function(){
  			if(!followMouse) clearTimeout(hideId);
  		}
  		objBox.onmouseout = function(){
  			if(!followMouse) hideId = setTimeout('hideObj()', hideDelay);
  		}
		if (isNN4) { 
			document.captureEvents(Event.MOUSEMOVE);
		}
		document.onmousemove = moveTooltip;
		document.onkeydown = moveKey;
		window.onresize = getWinHW;
	}
}
function shiftBy(obj, deltaX, deltaY) {
	var theObj = getObject(obj);
	if (theObj) {
		if (isCSS) {
			var units = (typeof theObj.left == "string") ? "px" : 0 
			theObj.left = getObjectLeft(obj) + deltaX + units;
			theObj.top = getObjectTop(obj) + deltaY + units;
		} else if (isNN4) {
			theObj.moveBy(deltaX, deltaY);
		}
	}
}
function getObjectLeft(obj)  {
	var elem = getRawObject(obj);
	var result = 0;
	if (document.defaultView) {
		var style = document.defaultView;
		var cssDecl = style.getComputedStyle(elem, "");
		result = cssDecl.getPropertyValue("left");
	} else if (elem.currentStyle) {
		result = elem.currentStyle.left;
	} else if (elem.style) {
		result = elem.style.left;
	} else if (isNN4) {
		result = elem.left;
	}
	return parseInt(result);
}
function getObjectTop(obj)  {
	var elem = getRawObject(obj);
	var result = 0;
	if (document.defaultView) {
		var style = document.defaultView;
		var cssDecl = style.getComputedStyle(elem, "");
		result = cssDecl.getPropertyValue("top");
	} else if (elem.currentStyle) {
		result = elem.currentStyle.top;
	} else if (elem.style) {
		result = elem.style.top;
	} else if (isNN4) {
		result = elem.top;
	}
	return parseInt(result);
}
function moveKey(evt){
	var keyPressed = -1;
	evt = (evt) ? evt : (window.event) ? window.event : "";
	if (evt&&(getObjVisibility("tooltipBox").toLowerCase()=="visible")) {
		if (evt.ctrlKey) {
			keyPressed = evt.keyCode
		}
		if (keyPressed == 38) { // up
			shiftBy("tooltipBox", 0, -dY);
			cancelKey(evt);
		} else if (keyPressed == 39) { // right
			shiftBy("tooltipBox", dX, 0);
			cancelKey(evt);
		}  else if (keyPressed == 40) { // down
			shiftBy("tooltipBox", 0, dY);
			cancelKey(evt);
		}else if (keyPressed == 37) { // left
			shiftBy("tooltipBox", -dX, 0);	
			cancelKey(evt);
		}
	}
}
function cancelKey(evt){
	if (evt.preventDefault) {
		evt.preventBuble();
		evt.preventDefault();
		evt.stopPropagation();
		return false;
	} else {
		evt.keyCode = 0;
		evt.cancelBuble = true;
		evt.returnValue = false;
		return false;
	}
}
function seekLayer(doc, name) {
	var theObj;
	for (var i = 0; i < doc.layers.length; i++) {
		if (doc.layers[i].name == name) {
		theObj = doc.layers[i];
		break;
		}
		if (doc.layers[i].document.layers.length > 0) {
			theObj = seekLayer(document.layers[i].document, name);
		}
	}
	return theObj;
}
function getRawObject(obj) {
	var theObj;
	if (typeof obj == "string") {
		if (isW3C) {
			theObj = document.getElementById(obj);
		} else if (isIE4) {
			theObj = document.all(obj);
		} else if (isNN4) {
			theObj = seekLayer(document, obj);
		}
	} else {
		theObj = obj;
	}
	return theObj;
}
function getObject(obj) {
	var theObj = getRawObject(obj);
	if (theObj && isCSS) {
		theObj = theObj.style;
	}
	return theObj;
}
function shiftTo(obj, x, y) {
	var theObj = getObject(obj);
	if (theObj) {
		if (isCSS) {
			var units = (typeof theObj.left == "string") ? "px" : 0 
			theObj.left = x + units;
			theObj.top = y + units;
		} else if (isNN4) {
			theObj.moveTo(x,y)
		}
	}
}
function show(obj) {
	var theObj = getObject(obj);
	if (theObj) {
		theObj.visibility = "visible";
	}
}
function getObjVisibility(obj){
	var theObj = getObject(obj);
	if (theObj) {
		return (theObj.visibility);
	}
}
function hide(obj) {
	var theObj = getObject(obj);
	if (theObj) {
		theObj.visibility = "hidden";
	}
}
function getObjectWidth(obj)  {
	var elem = getRawObject(obj);
	var result = 0;
	if (elem.offsetWidth) {
		result = elem.offsetWidth;
	} else if (elem.clip && elem.clip.width) {
		result = elem.clip.width;
	} else if (elem.style && elem.style.pixelWidth) {
		result = elem.style.pixelWidth;
	}
	return parseInt(result);
}
function getObjectHeight(obj)  {
	var elem = getRawObject(obj);
	var result = 0;
	if (elem.offsetHeight) {
		result = elem.offsetHeight;
	} else if (elem.clip && elem.clip.height) {
		result = elem.clip.height;
	} else if (elem.style && elem.style.pixelHeight) {
		result = elem.style.pixelHeight;
	}
	return parseInt(result);
}
function getInsideWindowWidth() {
	if (window.innerWidth) {
		return window.innerWidth;
	} else if (isIE6CSS) {
		return document.body.parentElement.clientWidth
	} else if (document.body && document.body.clientWidth) {
		return document.body.clientWidth;
	}
	return 0;
}
function getInsideWindowHeight() {
	if (window.innerHeight) {
		return window.innerHeight;
	} else if (isIE6CSS) {
		return document.body.parentElement.clientHeight
	} else if (document.body && document.body.clientHeight) {
		return document.body.clientHeight;
	}
	return 0;
}
function getWinHW(){
	winH = getInsideWindowHeight()
	winW = getInsideWindowWidth()
}
function setRoundBox(text) {
	text = '<table width=20 border=0 cellpadding=0 cellspacing=0 bgcolor=#00bfff>'
	+'<tr>'
	+'<td align=left valign=middle nowrap style=\'border-style:solid;border-color:#00008b;border-width:2px\'><font face=Verdana size=2 style=\'font-size:11px\' color=#00008b>'
	+text
	+'</font></td></tr></table>'
	return text
}
function setBoxText(text){
	text = '<span class=\"tooltipText\">'+text+'</span>';
	if (roundBox) {
		text = setRoundBox(text)
	}
	if(isNN4){
		objBox.document.open();
		objBox.document.write(text);
		objBox.document.close();
	} else {
		objBox.innerHTML = text;
	}		
}
function showTooltip(text){
	if (isNN4) text = '<div class=\"tooltipText\">'+text+'</div>';
	if (!followMouse&&(hideId!=0)) clearTimeout(hideId);
	setBoxText(text);
	show("tooltipBox");
	objH = getObjectHeight("tooltipBox")
	objW = getObjectWidth("tooltipBox")
	isHover = true;
	doFollow = true;
}
function hideTooltip(){
	if (followMouse) {
		hideObj()
	}
	else {
		hideId = setTimeout('hideObj()', hideDelay);
	}
}
function hideObj(){
	hide("tooltipBox");
	setBoxText('');
}
function moveTooltip(evt){
	var moveX, moveY, offX, offY;
	if (isHover && doFollow) {
		if (isIEAll) {
			moveX = event.clientX;
			moveY = event.clientY;
		} else {
			offX = window.pageXOffset;
			offY = window.pageYOffset;
			moveX = evt.pageX - offX;
			moveY = evt.pageY - offY;
		}
		if ((moveX+objW+offsetX) > winW) {
			moveX = winW - objW - 20
		} else {
			moveX += offsetX - 5
		}
		if ((moveY+objH+offsetY) > winH) {
			moveY = moveY - objH - 5
		} else {
			moveY += offsetY 
		}
		if (isIEAll) {
			moveX += document.body.scrollLeft;
			moveY += document.body.scrollTop;
		} else {
			moveX += offX;
			moveY += offY;
		}			
		shiftTo("tooltipBox", moveX, moveY)
		if (!followMouse) doFollow = false;
	}
}
// *************************************************************************************************************
function onLoadAction(){ 
	initTooltip();
	sURL = "sdafdgfdg";
	followMouse = true;
}

