/* 
Original script by Brian Gosselin of ScriptAsylum.com 
Script updated and modified by Dennis Gaskill
Script courtesy of BoogieJack.com
*/


var dofade=true;       // Enables fade-in (fade may not work in all browsers or older browsers)
var center=true;      // Centers the tool tip under the mouse, set to true to display to the right
var centertext=false;  // Set to true to center the text within the tool tip


// --- NOTHING TO EDIT HERE, TWO OPTIONAL SETTINGS WHERE NOTED BELOW --- //

function ieBody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

var NS4 = (navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)? true : false;
var IE4 = (document.all && !document.getElementById)? true : false;
var IE5 = (document.getElementById && document.all)? true : false;
var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
var W3C = (document.getElementById)? true : false;
var w_y, w_x, seedBox, boxheight, boxwidth;
var ishover=false;
var isloaded=false;
var ieop=0;
var op_id=0;

function getSize(){
w_y=(NS4||NS6||window.opera)? window.innerHeight : (IE5||IE4)? document.body.clientHeight : 0;
w_x=(NS4||NS6||window.opera)? window.innerWidth : (IE5||IE4)? document.body.clientWidth : 0;
}

function getBoxW(){
if(NS4)boxwidth=(seedBox.document.width)? seedBox.document.width : seedBox.clip.width;
if(IE5||IE4)boxwidth=(seedBox.style.pixelWidth)? seedBox.style.pixelWidth : seedBox.offsetWidth;
if(NS6)boxwidth=(seedBox.style.width)? parseInt(seedBox.style.width) : parseInt(seedBox.offsetWidth);
}

function getBoxH(){
if(NS4)boxheight=(seedBox.document.height)? seedBox.document.height : seedBox.clip.height;
if(IE4||IE5)boxheight=(seedBox.style.pixelHeight)? seedBox.style.pixelHeight : seedBox.offsetHeight;
if(NS6)boxheight=parseInt(seedBox.offsetHeight);

}

function movement(x,y){
if(NS4)seedBox.moveTo(x,y);
if(W3C||IE4){
seedBox.style.left=x+'px';
seedBox.style.top=y+'px';
}}

function getScrollY(){
if(NS4||NS6)return window.pageYOffset;
if(IE5||IE4)return ieBody().scrollTop;
}

function getScrollX(){
if(NS4||NS6)return window.pageXOffset;
if(IE5||IE4)return ieBody().scrollLeft;
}

function populate(text){
if(NS4){
seedBox.document.open();
seedBox.document.write(text);
seedBox.document.close();
}
if(W3C||IE4)seedBox.innerHTML=text;
}

function scribble(text){
if(isloaded){
if(text!=0){
ishover=true;
if(NS4)text='<div class="popUp">'+((centertext)?'<center>':'')+text+((centertext)?'</center>':'')+'</div>';
populate(text);
getBoxH();
if((W3C || IE4) && dofade){
ieop=0;
incropacity();
}}else{
if(NS4)seedBox.visibility="hide";
if(IE4||W3C){
if(dofade)clearTimeout(op_id);
seedBox.style.visibility="hidden";
}
populate('');
ishover=false;
}}}

  
// --- OPTIONAL SETTINGS YOU MAY CHANGE BELOW ---  //


/*
EDIT FADE IN TIME BELOW, DEFAULT IS 220, TWO INSTANCES PRESENT
EDIT TIME OUT BELOW, DEFAULT IS 40, ONE INSTANCE PRESENT 
*/

function incropacity(){
if(ieop<=220){
ieop+=7;
if(IE4 || IE5)seedBox.style.filter="alpha(opacity="+ieop+")";
if(NS6)seedBox.style.MozOpacity=ieop/220;
op_id=setTimeout('incropacity()', 40);
}}

// --- NOTHING ELSE TO EDIT --- //

function moveobj(evt){
if(isloaded && ishover){
margin=(IE4||IE5)? 1 : 23;
if(NS6)if(document.height+27-window.innerHeight<0)margin=15;
if(NS4)if(document.height-window.innerHeight<0)margin=10;
//mx=(NS4||NS6)? evt.pageX : (IE5||IE4)? event.clientX : 0;
//my=(NS4||NS6)? evt.pageY : (IE5||IE4)? event.clientY : 0;
if (NS4){
mx=evt.pageX
my=evt.pageY
}
else if (NS6){
mx=evt.clientX
my=evt.clientY
}
else if (IE5){
mx=event.clientX
my=event.clientY
}
else if (IE4){
mx=0
my=0
}

if(NS4){
mx-=getScrollX();
my-=getScrollY();
}
xoff=(center)? mx-boxwidth/2 : mx+5;
yoff=(my+boxheight+30-getScrollY()+margin>=w_y)? -15-boxheight: 30;
movement( Math.min(w_x-boxwidth-margin , Math.max(2,xoff))+getScrollX() , my+yoff+getScrollY());
if(NS4)seedBox.visibility="show";
if(W3C||IE4)seedBox.style.visibility="visible";
}}

if(NS4)document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=moveobj;
window.onload=function(){
  seedBox=(NS4)? document.layers['seedBox'] : (IE4)? document.all['seedBox'] : (W3C)? document.getElementById('seedBox') : null;
  getBoxW();
  getBoxH();
  getSize();
  isloaded=true;
  if((W3C || IE4) && centertext)seedBox.style.textAlign="center";
  if(W3C)seedBox.style.padding='4px';
  if(IE4 || IE5 && dofade)seedBox.style.filter="alpha(opacity=0)";
  }
window.onresize=getSize;
