/*
    --------------------------------------------------------------------------
    Code for link-hover text boxes
    By Nicolas Honing
    Usage: <a onmouseover="popup('popup content', width)">a link</a>
     (width is optional - default is in CSS: #pup {width: x;},
      escape " in content with &quot;)
    Tutorial and support at http://nicolashoening.de?twocents&nr=8
    --------------------------------------------------------------------------
*/

var glossary= new Array ();

glossary['stem_cell']="Stem Cell: Biological cell found in all multicellular organisms, that can divide (through mitosis) and differentiate into diverse specialized cell types and can self-renew to produce more stem cells.";

glossary['allogeneic']="Allogeneic: Involving or derived from individuals of the same species, but from a donor that is not also the recipient or genetically identical to the recipient; can be related or unrelated donor.";

glossary['acute_ischemia']="Acute Ishemia: Low oxygen conditions.";

glossary['autologous']="Autologous: Originating from the recipient rather than from a separate donor.";


glossary['hsc']="Hematopoietic Stem Cell (HSC): A cell isolated from the blood, bone marrow or umbilical cord that can renew itself, can differentiate to a variety of specialized cells, can mobilize out of the bone marrow into circulating blood, and can undergo programmed cell death (apoptosis).";

glossary['hematopoietic_reconstitution']="Hematopoietic Reconstitution: Reestablishment of the body's ability to form new blood cells.";

glossary['homing']="Homing: The migration of cells to a target tissue.";

glossary['']="";

glossary['']="";

glossary['']="";

glossary['skeletal_muscle']="Skeletal Muscle: A form of striated muscle tissue existing under control of the somatic nervous system- i.e. it is voluntarily controlled. It is one of three major muscle types, the others being cardiac and smooth muscle.";


// create the popup box - remember to give it some width in your styling 
document.write('<div id="pup" style="position:abolute; display:none; z-index:200;"></div>');

var minMargin = 15; // set how much minimal space there should be (in pixels)
                    // between the popup and everything else (borders, mouse)
var ready = false;  // we are ready when the mouse event is set up
var default_width = 200; // will be set to width from css in document.ready

/* Prepare popup and define the mouseover callback */
jQuery(document).ready(function(){
    jQuery('#pup').hide();
    css_width = jQuery('#pup').width();
    if (css_width != 0) default_width = css_width;
    // set dynamic coords when the mouse moves
    jQuery(document).mousemove(function(e){ 
        var x,y;
      
        x = jQuery(document).scrollLeft() + e.clientX;
        y = jQuery(document).scrollTop() + e.clientY;

        x += 10; // important: if the popup is where the mouse is, the hoverOver/hoverOut events flicker
      
        var x_y = nudge(x,y); // avoids edge overflow
      
        // remember: the popup is still hidden
        jQuery('#pup').css('top', x_y[1] + 'px');
        jQuery('#pup').css('left', x_y[0] + 'px');
    });
    ready = true;
});

/*
 The actual callback:
 Write message, show popup w/ custom width if necessary,
 make sure it disappears on mouseout
*/
function popup(msg, width)
{
    if (ready) {
        // use default width if not customized here
        if (typeof width === "undefined"){
            width = default_width;
        }
        // write content and display
        jQuery('#pup').html(glossary[msg]).width(width).show();
        // make sure popup goes away on mouse out
        // the event obj needs to be gotten from the virtual 
        //   caller, since we use onmouseover='popup(msg)' 
        var t = getTarget(arguments.callee.caller.arguments[0]);
        jQuery(t).unbind('mouseout').bind('mouseout', 
            function(e){
                jQuery('#pup').hide().width(default_width);
            }
        );
    }
}

/* Avoid edge overflow */
function nudge(x,y)
{
    var win = jQuery(window);
    
    // When the mouse is too far on the right, put window to the left
    var xtreme = jQuery(document).scrollLeft() + win.width() - jQuery('#pup').width() - minMargin;
    if(x > xtreme) {
        x -= jQuery('#pup').width() + 2 * minMargin;
    }
    x = max(x, 0);

    // When the mouse is too far down, move window up
    if((y + jQuery('#pup').height()) > (win.height() +  jQuery(document).scrollTop())) {
        y -= jQuery('#pup').height() + minMargin;
    }

    return [ x, y ];
}

/* custom max */
function max(a,b){
    if (a>b) return a;
    else return b;
}

/*
 Get the target (element) of an event.
 Inspired by quirksmode
*/
function getTarget(e) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;
    return targ;
}

