/* balloon.js
   Created by Trevor Phillips, 16/8/2006

   Simple library for adding "balloon help" popups to anything on mouseover.

   Usage:

   AddBalloonStyle(stylename,class,prehtml,posthtml)
      - Registers a new style of balloon referenced by the name, which will be in a
        DIV with the specified class, with the balloon text between the prehtml and posthtml.

   AddBalloon(areaobj,stylename,content,shownow)
      - Adds a balloon to the given area (id name or object), and shows it now if needed.
 */

var BLN_Styles = new Object();
var BLN_Targets = new Object();

var BLN_IdCount = 0;

function AddBalloonStyle(bsname,bsclass,prehtml,posthtml)
{
   BLN_Styles[bsname] = { 'bclass':bsclass, 'prehtml':prehtml, 'posthtml':posthtml };
}

function AddBalloon(e,bsname,content,shownow)
{
   if (typeof(e)=='string')
      aobj = document.getElementById(aobj);
   aobj = (e.target) || e.srcElement;
   if (!aobj)
      return;

   var tid = BLN_GetUniqueID(aobj);
   if (BLN_Targets[tid]) // Already got one!!
      return;
   BLN_Targets[tid] = aobj;
   
   aobj.onmouseover = BLN_ShowBalloon;
   aobj.onmouseout = BLN_HideBalloon;
   aobj.onmousemove = BLN_MoveBalloon;

   var bstyle = BLN_Styles[bsname];

   var newdiv = document.createElement('div');
   newdiv.style.position = 'absolute';
   newdiv.style.zIndex = '1501';
   newdiv.style.display = 'none';
   newdiv.className = bstyle.bclass;
   newdiv.innerHTML = bstyle.prehtml+content+bstyle.posthtml;

   aobj.BLN_balloon = newdiv;
   document.body.appendChild(newdiv);

   if (shownow)
      BLN_ShowBalloon(e);
}

function BLN_ShowBalloon(aobj)
{
   if (!aobj)
      aobj = window.event;
   var bln = aobj.BLN_balloon;
   if (!bln)
      bln = (aobj.target && aobj.target.BLN_balloon) || aobj.srcElement.BLN_balloon;
   if (!bln)
      return;

   BLN_MoveBalloon(aobj);
   bln.style.display = 'block';
   if (bln.BLN_HideTimeout)
      clearTimeout(bln.BLN_HideTimeout);
}

function BLN_HideBalloon(aobj)
{
   if (!aobj)
      aobj = window.event;
   var bln = aobj.BLN_balloon;
   if (!bln)
      bln = (aobj.target && aobj.target.BLN_balloon) || aobj.srcElement.BLN_balloon;
   if (!bln)
      return;
   bln.BLN_HideTimeout = setTimeout( bln.style.display = 'none', 1000);
}

function BLN_MoveBalloon(aobj)
{
   if (!aobj)
      aobj = window.event;
   var bln = aobj.BLN_balloon;
   if (!bln)
      bln = (aobj.target && aobj.target.BLN_balloon) || aobj.srcElement.BLN_balloon;
   if (!bln)
      return;

   var posx=0,posy=0;
   if (aobj.pageX || aobj.clientX)
      e=aobj;
   else
      e=window.event;

   if(e.pageX || e.pageY)
   {
      posx=e.pageX; posy=e.pageY;
   }
   else if(e.clientX || e.clientY)
   {
      if(document.documentElement.scrollTop)
      {
         posx=e.clientX+document.documentElement.scrollLeft;
         posy=e.clientY+document.documentElement.scrollTop;
      }
      else
      {
         posx=e.clientX+document.body.scrollLeft;
         posy=e.clientY+document.body.scrollTop;
      }
   }
   bln.style.top=(posy+2)+"px";
   bln.style.left=(posx+2)+"px";
}

function BLN_GetUniqueID(obj)
{
   if (!obj.id)
   {
      BLN_IdCount++;
      obj.id = 'BLN_UID_'+BLN_IdCount;
   }
   return obj.id;
}

function dumpProps(obj, parent) {
   for (var i in obj) {
      if (parent) { msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[
i]; }
      if (!confirm(msg)) { return; }
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}
