/***********************************************
* Cool DHTML tooltip script- ? 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
*************************************
STEPHEN ROWE - HACKED THIS TO PIECES FOR MY OWN USE - THANKS TO DYNAMICDRIVE.COM FOR THE INITIAL START

**********/

var offsetxpoint=10 //Customize x offset of tooltip
var offsetypoint=0 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var showBox=false;
if (ie||ns6)
{
	var boxObj = document.all ? document.all['boxover'] : (document.getElementById ? document.getElementById('boxover') : '');
}

var timeOutId;

var data = new Array();


function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function addElementBefore(node,tag,id,htm)
  {
    var ne = document.createElement(tag);
    if(id) ne.id = id;
    if(htm) ne.innerHTML = htm;
    node.parentNode.insertBefore(ne,node);
  }

  function addElementAfter(node,tag,id,htm)
  {
    var ne = document.createElement(tag);
    if(id) ne.id = id;
    if(htm) ne.innerHTML = htm;
    node.parentNode.insertBefore(ne,node.nextSibling);
  }


function addElement(parent, elementType, elementId) {
	if(!document.getElementById(elementId))
  	{
  		var pEl = document.getElementById(parent);
  		var nEl = document.createElement(elementType);
  		nEl.setAttribute('id',elementId);
  		pEl.appendChild(nEl);
  	}
}

function addAttribute(element, attrName, attrValue)
{
	 element.setAttribute(attrName, attrValue);
}

function removeElement(parent,elementId) {
	if(document.getElementById(elementId))
  	{
 		var pEl = document.getElementById(parent);
  		var nEl = document.getElementById(elementId);
  		pEl.removeChild(nEl);
  	}
}

function removeAllChildren(parent)
{
	var p = document.getElementById(parent);
	if (p)
	{
		while( p.hasChildNodes() ) { p.removeChild( p.lastChild ); }
	}
}

function encodeHtml(val) {
     encodedHtml = escape(val);
     encodedHtml = encodedHtml.replace(/\//g,"%2F");
     encodedHtml = encodedHtml.replace(/\?/g,"%3F");
     encodedHtml = encodedHtml.replace(/=/g,"%3D");
     encodedHtml = encodedHtml.replace(/&/g,"%26");
     encodedHtml = encodedHtml.replace(/@/g,"%40");
     return unescape(encodedHtml);
   } 

function setBox(id,data, obj){
	//find the boxover object and prepare its position	
	boxObj = document.getElementById(id); 

	//set the events
	if(ns6)
		document.captureEvents(Event.MOUSEMOVE);
			
	obj.onmousemove=positionBox;
	
	//don't build the data till time is up
	BOtimeOutId = window.setTimeout(function() { setData(data); }, 700);

}

function init(id,data, obj)
{
	//find the boxover object and prepare its position	
	boxObj = document.getElementById(id); 
	
	//set the events
	if(ns6)
	{
		document.captureEvents(Event.MOUSEMOVE);
	}

	obj.onmousemove = positionBox;
	
	//don't build the data till time is up
	BOtimeOutId = window.setTimeout(function() { draw(data); }, 900);
	
}
function initOperator(id,data, obj)
{
	//find the boxover object and prepare its position	
	boxObj = document.getElementById(id); 
	//set the events
	if(ns6)
		document.captureEvents(Event.MOUSEMOVE);
			
	obj.onmousemove=positionBox;
	
	//don't build the data till time is up
	BOtimeOutId = window.setTimeout(function() { drawOperator(data); }, 900);
	
}

function setData(data)
{


	removeElement('BObodyImage', 'BObodyImage_img' );
	removeElement('BOheadText', 'BOheadText_h1' );	

	
	if (ns6||ie){

		var SPAN_OPEN = " <span class='boxoverTextTitle'>";
		var SPAN_CLOSE = "</span> ";
		var string = '';
		
		for(i=0; i< data.length; i++ ) 
		{
				
			if(data[i][0] == 'BObodyImage')
			{
				addElement(data[i][0], 'img', data[i][0] + '_img' );
				document.getElementById(data[i][0] + '_img').src = data[i][2];
			
			} 
			else if(data[i][0] == 'BOheadText')
			{
			
				addElement(data[i][0], 'h1', data[i][0] + '_h1' );
				document.getElementById(data[i][0] + '_h1').innerHTML = data[i][2];
			
			} 
			else if(data[i][0] == 'status')
			{
				string = string + data[i][2] + "<br />";
			}
			else if( data[i][1] &&  data[i][2].length > 0 && data[i][2] != ' <!-- PLACEHOLDER --> ' )
			{
				
					string = string + SPAN_OPEN + data[i][1] + SPAN_CLOSE + data[i][2] + "<br />";
									
			}
		}

		document.getElementById("BObodyText").innerHTML = string;
		 		
		showBox = true;
		
		boxObj.style.visibility="visible";

	}
}

function positionBox(e){
	
	  	var curX;
	  	var curY;

		//Had to change this as firebug shows a event is not defined 	
	  	curX = (ns6) ? e.pageX : event.clientX+ietruebody().scrollLeft;
	  	curY = (ns6) ? e.pageY : event.clientY+ietruebody().scrollTop;		
			  
       
		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
		
		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000		

		if( rightedge < boxObj.offsetWidth)		
			boxObj.style.left = ie? ietruebody().scrollLeft+event.clientX-boxObj.offsetWidth+"px" : window.pageXOffset+e.clientX-boxObj.offsetWidth+"px"
		else if (curX < leftedge)
			boxObj.style.left="5px"
		else
			boxObj.style.left=curX+offsetxpoint+"px"
	
		if ( bottomedge < boxObj.offsetHeight)
			boxObj.style.top=ie? ietruebody().scrollTop+event.clientY-boxObj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-boxObj.offsetHeight-offsetypoint+"px"
		else
			boxObj.style.top=curY+offsetypoint+"px"
			
		
	
}

function hideBox(id){
	window.clearTimeout(BOtimeOutId);
	if (ns6||ie){

		showBox=false;
		boxObj = document.getElementById(id);
		boxObj.style.visibility="hidden"
		boxObj.style.left="-1000px"
		boxObj.style.backgroundColor=''
		boxObj.style.width=''
	}
}
