/***********************************************
* 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
*
* Modified by balda-online (www.balda-online.com) for www.eteech.com
***********************************************/

var xOffset=20
var yOffset=-8

var ie=document.all
var w3c=document.getElementById && !document.all
var enabletip=false
if (ie||w3c) {
	var tipobj
	var tipobjX
	var tipobjY
}

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

/*------------------------------------------------------------------------
SHOW TOOLTIP
------------------------------------------------------------------------*/
function showTip(obj, contentBase, title, clContent, clTitle){
	if (w3c||ie){
		if (ie) {
			var p = document.getElementsByTagName("select");
			for(i=0;i<p.length;i++){
				p[i].style.visibility = 'hidden';
				/*
				if(p[i].type=="checkbox"){
					alert(p[i].checked);
				}
				*/
			}
		}
		var p = Position.positionedOffset(obj);
		tipobjX = p[0];
		tipobjY = p[1];
		var pc = Position.cumulativeOffset(obj);
		tipobjXc = pc[0];
		tipobjYc = pc[1];
		var pr = Position.realOffset(obj);
		tipobjXr = pr[0];
		tipobjYr = pr[1];
		var pp = Position.page(obj);
		tipobjXp = pp[0];
		tipobjYp = pp[1];
		/*
		*/
		var class_content = "";
		if (typeof clContent!="undefined") {
			class_content = ' class="'+clContent+'"';
		}
		var class_title = "";
		if (typeof clTitle!="undefined") {
			class_title = ' class="'+clTitle+'"';
		}
		if (typeof contentBase=="undefined") {
			contentBase = '';
		}
		if (typeof title=="undefined") {
			title = '';
		}
		var content = '<div><p'+class_title+'>'+title+'</p></div>'+'<p'+class_content+'>'+contentBase+'</p>';

		//tipobj = document.all? document.all["tooltip"] : document.getElementById? document.getElementById("tooltip") : ""
		//tipcontent = document.all? document.all["tooltipContent"] : document.getElementById? document.getElementById("tooltipContent") : ""
		
		tipobj = $("tooltip");
		tipcontent = $("tooltipContent");
		
		tipcontent.update(content);
		//tipcontent.innerHTML = content
		
		enabletip=true

		return false
	}
}

/*------------------------------------------------------------------------
HIDE THE TOOLTIP
------------------------------------------------------------------------*/
function hideTip(){
	if (w3c||ie){
		if ( ie && $('MB_content') == null ) {
			var p = document.getElementsByTagName("select");
			for(i=0;i<p.length;i++){
				p[i].style.visibility = 'visible';
			}
		}
		tipobj = $("tooltip");
		enabletip=false
//        tipobj.style.visibility="hidden" // avoid the IE6 cache optimisation with hidden blocks
		tipobj.style.top="-1000px"
		tipobj.style.backgroundColor=''
		//tipobj.style.width=''
	}
}

/*------------------------------------------------------------------------
ONMOVE EVENT
------------------------------------------------------------------------*/
function moveTip(e){
	if (enabletip){
		tipobj = $("tooltip");
		
		var nondefaultpos=false
		//var curX=(w3c)?e.pageX : event.x+ietruebody().scrollLeft;
		var curX=tipobjX+ietruebody().scrollLeft;
		//var curY=(w3c)?e.pageY : event.y+ietruebody().scrollTop;
		var curY=tipobjYp+tipobjYr;//+ietruebody().scrollTop;
		
		if ( $('MB_content') != null ) {
			curY -= $('MB_content').scrollTop;
		}
		
		//alert(tipobjY+'/'+tipobjYc+'/'+tipobjYr+'/'+tipobjYp);
		
		//Find out how close the mouse is to the corner of the window
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
		if ($('MB_content') != null ) {
			winwidth -= ( (winwidth-$('MB_content').getWidth()) / 2 );
		}
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

		var rightedge=ie&&!window.opera? winwidth-event.clientX-xOffset : winwidth-e.clientX-xOffset
		var bottomedge=ie&&!window.opera? winheight-event.clientY-yOffset : winheight-e.clientY-yOffset
		
		//alert(curX+'/'+winwidth+'/'+$('MB_content').getWidth()+'/'+rightedge+'/'+tipobj.offsetWidth);
		
		var leftedge=(xOffset<0)? xOffset*(-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
			tipobj.style.left=curX-tipobj.offsetWidth-xOffset+16+"px"
			nondefaultpos=true
		}
		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+xOffset+"px"
			}
		}

		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight) {
			tipobj.style.top=curY-tipobj.offsetHeight-yOffset+8+"px"
			nondefaultpos=true
		}
		else{
			tipobj.style.top=curY+yOffset+"px"
		}
	}
}

document.onmousemove=moveTip

