﻿// checks whether element is under a point (typically the mouse pointer location)
// used to manually generate mouseover/mouseout behavior as elements are scrolled underneath a stationary mouse
// since in IE7 scrolling elements beneath a stationary mouse does not generate these "mouseunder" events
// returns true if point intersects element, otherwise returns false;
function mouseUnder(element, debug) {
    var e = element;
    var eX = 0;
    var eY = 0;
//    if (debug) alert();
//    // calculate element's position on the page by adding position of all of element's ancestors
    while (e && e.style && !isNaN(parseInt(e.style.left))) {
        eX += parseInt(e.style.left);
        eY += parseInt(e.style.top);
        e = e.parentNode;
    }
    if (mouseUnder.y >= eY && mouseUnder.y <= eY + parseInt(element.style.height) &&
            mouseUnder.x >= eX && mouseUnder.x <= eX + parseInt(element.style.width))
        return true;
    else
        return false;
}

mouseUnder.trackMouse = function(e) {
    if (!e) e = window.event;
    mouseUnder.x = e.clientX;
    mouseUnder.y = e.clientY;
}

mouseUnder.x = 0;
mouseUnder.y = 0;


