//===============================================
// functions for balloon help

var balloons_enabled   = null;
var balloons           = new Array();

function initBalloons(){
    balloons_enabled   = true;
}

function showBalloon(div,e){
    if(balloons_enabled){
        var id_parts        = div.id.split("_");
        var id              = id_parts[1];
        var balloon         = document.getElementById("balloon_object_" + id);
        var target          = getTarget(e);
        target.onmousemove  = moveBalloon;
        moveBalloon(e);
        balloon.style.visibility = "visible";
    }
}

function hideBalloon(div,e){
    if(balloons_enabled){
        var id_parts                = div.id.split("_");
        var id                      = id_parts[1];
        var balloon                 = document.getElementById("balloon_object_" + id);
        var target                  = getTarget(e);
        target.onmousemove          = function(e){};
        balloon.style.visibility    = "hidden";
    }
}

function moveBalloon(e){
    
        if(!e){ e = window.event; }
 
        if(e){
            var link        = getTarget(e);
            var id          = link.id.split("_");            
            var balloon     = document.getElementById("balloon_object_" + id[1]);
            var x           = getMouseCoord(e,"x");
            var y           = getMouseCoord(e,"y");
            var orient      = (x > 477)? "lefthand" : "righthand";
            var elor        = $(balloon).getChildById("orientation");
            elor.className  = orient;
            
            var bwidth = parseInt(balloon.style.width);

            if(orient == "lefthand"){
                x = x - (bwidth + 4);
            } else {
                x = x + 4;
            }

            y = y - (balloon.offsetHeight/2);

            balloon.style.top  = y + "px";
            balloon.style.left = x + "px";
        }    
}

function getTarget(e){
    
    var target = null;
    if(!e){ e = window.event; }
    if(e.target){ target = e.target; }
    else if(e.srcElement){ target = e.srcElement; }
    if (target.nodeType == 3){ target = target.parentNode; }// defeat Safari bug
    
    return target;
}

function getMouseCoord(e,axis){ 
    
    var result = null;
    
    if(!e){ e = window.event; }
 
    if(e){ 
        if(e.pageX || e.pageY){ // this doesn't work on IE6!! (works on FF,Moz,Opera7)
            if(axis == "x"){ result = e.pageX; }
            if(axis == "y"){ result = e.pageY; }

        } else if(e.clientX || e.clientY){ // works on IE6,FF,Moz,Opera7
            if(axis == "x"){ result = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; }
            if(axis == "y"){ result = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; }
        }
    }
    
    return result
}

