/***********************************************
* 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
*
* 07/01/05 tk v1.0: adapted for icms
***********************************************/

// define where the tooltip starts
var tt_offsetfromcursorX=12; //Customize x offset of tooltip
var tt_offsetfromcursorY=10; //Customize y offset of tooltip

var tt_offsetdivfrompointerX=10; //Customize x offset of tooltip DIV relative to pointer image
var tt_offsetdivfrompointerY=14; //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).


// check if we have ie or netscape
var tt_ie			= document.all;
var tt_ns6			= document.getElementById && !document.all;
var tt_enabletip	= false;
var tt_initialized	= false;
var tt_prepared	= false;

function inittooltip(pointerimage) {
	if (pointerimage == "") {
		pointerimage = "images/arrow2.gif";
	}
	
	// write the style sheet
	// yes, better in an extra css, i know...
	document.write(' \
<style type="text/css"> \
#dhtmltooltip{ \
	position: absolute; \
	left: -300px; \
	width: 150px; \
	border: 1px solid black; \
	padding: 2px; \
	background-color: lightyellow; \
	visibility: hidden; \
	z-index: 151; \
');
	if (tt_ie) {
		document.write('	/*Remove below line to remove shadow. Below line should always appear last within this CSS*/ \
	filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135); \
');
	}
	document.write(' \
} \
 \
#dhtmlpointer{ \
	position: absolute; \
	left: -300px; \
	z-index: 152; \
	visibility: hidden; \
} \
</style> \
');
	
	// write the tooltip
	document.write('<div id="dhtmltooltip"></div>'); //write out tooltip DIV
	document.write('<img id="dhtmlpointer" src="' + pointerimage + '">'); //write out pointer image
	
	tt_prepared = true;
}

function ietruebody() {
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function ddrivetip(thetext, thewidth, thecolor) {
	if (tt_prepared && (tt_ns6 || tt_ie)) {
		// get the objects if we dont have them already
		if (typeof(tt_tipobj) == "undefined") {
			tt_tipobj = document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "";
		}
		if (typeof(tt_pointerobj) == "undefined") {
			tt_pointerobj = document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : "";
			
			// ok, everything is ready
			tt_initialized = true;
		}
		
		if (typeof thewidth != "undefined" && thewidth > 5) {
			tt_tipobj.style.width = thewidth + "px";
		}
		if (typeof thecolor != "undefined" && thecolor != "") {
			tt_tipobj.style.backgroundColor = thecolor;
		}
		tt_tipobj.innerHTML = thetext;
		tt_enabletip = true;
		return false;
	}
}

function positiontip(e){
	if (tt_enabletip && tt_initialized) {
		var nondefaultpos = false
		var curX=(tt_ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(tt_ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		
		//Find out how close the mouse is to the corner of the window
		var winwidth = tt_ie&&!window.opera? ietruebody().clientWidth : window.innerWidth - 20;
		var winheight = tt_ie&&!window.opera? ietruebody().clientHeight : window.innerHeight - 20;

		var rightedge = tt_ie&&!window.opera? winwidth - event.clientX - tt_offsetfromcursorX : winwidth - e.clientX - tt_offsetfromcursorX;
		var bottomedge = tt_ie&&!window.opera? winheight - event.clientY - tt_offsetfromcursorY : winheight - e.clientY - tt_offsetfromcursorY;

		var leftedge=(tt_offsetfromcursorX < 0)? tt_offsetfromcursorX*(-1) : -1000;

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge < tt_tipobj.offsetWidth){
			//move the horizontal position of the menu to the left by it's width
			tt_tipobj.style.left=curX - tt_tipobj.offsetWidth + "px";
			nondefaultpos = true;
		}
		else if (curX < leftedge) {
			tt_tipobj.style.left = "5px";
		} else {
			//position the horizontal position of the menu where the mouse is positioned
			tt_tipobj.style.left = curX + tt_offsetfromcursorX - tt_offsetdivfrompointerX + "px";
			tt_pointerobj.style.left = curX + tt_offsetfromcursorX + "px";
		}

		//same concept with the vertical position
		if (bottomedge < tt_tipobj.offsetHeight) {
			tt_tipobj.style.top=curY - tt_tipobj.offsetHeight - tt_offsetfromcursorY + "px";
			nondefaultpos=true;
		} else {
			tt_tipobj.style.top = curY + tt_offsetfromcursorY + tt_offsetdivfrompointerY + "px";
			tt_pointerobj.style.top = curY + tt_offsetfromcursorY + "px";
		}
		tt_tipobj.style.visibility = "visible";
		if (!nondefaultpos) {
			tt_pointerobj.style.visibility = "visible";
		} else {
			tt_pointerobj.style.visibility = "hidden";
		}
	}
}

function hideddrivetip(){
	if  (tt_initialized && (tt_ns6 || tt_ie)) {
		tt_enabletip=false;
		tt_tipobj.style.visibility = "hidden";
		tt_pointerobj.style.visibility = "hidden";
		tt_tipobj.style.left = "-1000px";
		tt_tipobj.style.backgroundColor = '';
		tt_tipobj.style.width = '';
	}
}

document.onmousemove = positiontip;

