﻿var IE = document.all ? true : false;

var tempX = 0;
var tempY = 0;
var pageWidth = 0;
var pageHeight = 0;
var mouseDiv = null;
var callBack = new Array();

if (!IE)
    document.captureEvents(Event.MOUSEMOVE);

function registerMouseDiv(div) {
    mouseDiv = div;
}

function registerCallback(cb) {
    callBack[callBack.length + 1] = cb;
}

function getMouseXY(e) {
    if (IE) {
        // grab the x-y pos.s if browser is IE              
        if (document.body != null) {
            tempX = event.clientX + document.documentElement.scrollLeft;
            tempY = event.clientY + document.documentElement.scrollTop;
        }
    }
    else {
        // grab the x-y pos.s if browser is NS              
        tempX = e.pageX;
        tempY = e.pageY;
    }
    // catch possible negative values in NS4
    if (tempX < 0) { tempX = 0 } if (tempY < 0) { tempY = 0 }
    // show the position values in the form named Show
    // in the text fields named MouseX and MouseY
    if (mouseDiv) {
        mouseDiv.style.position = 'absolute';
        mouseDiv.style.left = (tempX + 5) + 'px';
        mouseDiv.style.top = (tempY) + 'px';
    }

    for (var i = 0; i < callBack.length; i++)
        eval(callBack[i]);
    
    return true;
}

document.onmousemove = getMouseXY;

function getPageSize() {
    if( window.innerHeight && window.scrollMaxY ) // Firefox 
    {
    pageWidth = window.innerWidth + window.scrollMaxX;
    pageHeight = window.innerHeight + window.scrollMaxY;
    }
    else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
    {
        pageWidth = document.body.scrollWidth;
        pageHeight = document.body.scrollHeight;
    }
    else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    { 
        pageWidth = document.body.offsetWidth + document.body.offsetLeft; pageHeight = document.body.offsetHeight + document.body.offsetTop; 
    }
}