/*  =================================
    Global vars
    ================================= */
var ie = /MSIE/.test(navigator.userAgent);
var moz = !ie && navigator.product == "Gecko";

/*  =================================
    enhance page functionality onload
    ================================= */
window.onload = function() {

}

/*  =================================
    Popup
    ================================= */
var cout; // stores the active callout
function showPopup(e, txt, width){
  if(!width)width=200;
  var ctext, cptr;
  var show = false;
  var el = e.srcElement;
  if(!cout){
    show = true;
  }else{
    if(cout._el != el) show=true;
    cout.parentNode.removeChild(cout)
    cout = '';
  }
  if(show){
    cout = document.createElement("DIV");
    cout.className = "cout";

    cout.style.top = getElementTop(el) - 15 + "px";
    cout.style.left = getElementLeft(el) - width + "px";
    cout.style.width = width + "px";

    ctext = document.createElement("DIV");
    ctext.className = "ctext";
    ctext.innerHTML = txt;
    ctext.style.width = width - 26 + "px";
    cptr = document.createElement("DIV");
    cptr.className = "cptr";
    cout.appendChild(ctext);
    cout.appendChild(cptr);
    cout._el = el;
    document.body.appendChild(cout);
  }
}

/*  =================================
    override mozilla functions to mimic IE
    ================================= */
if(moz){
  Event.prototype.__defineGetter__("srcElement", function () {
     var node = this.target;
     while (node.nodeType != 1) node = node.parentNode;
     return node;
  })
}

/*  =================================
    utility functions
    ================================= */

function getElementLeft(el)
{
    var pos = el.offsetLeft;
    var par = el.offsetParent;
    while (par != null)
    {
        pos += par.offsetLeft;
        par = par.offsetParent;
    }
    return pos;
}

function getElementTop(el)
{
    var pos = el.offsetTop;
    var par = el.offsetParent;
    while (par != null)
    {
        pos += par.offsetTop;
        par = par.offsetParent;
    }
    return pos;
}