function wbids_saveMousePos(ev)
{
    if(!ev)
        ev = window.event;

    var mouseX = 0;
    var mouseY = 0;

    if(ev.pageX || ev.pageY) {
        mouseX = ev.pageX;
        mouseY = ev.pageY;
    } else if(ev.x || ev.y) {
        var win_offset = wbids_getScroll();
        try {
            if (ev.clientX && ev.clientY) {
                mouseX = ev.clientX + win_offset[0];
                mouseY = ev.clientY + win_offset[1];
            } else {
                mouseX = ev.x + win_offset[0];
                mouseY = ev.y + win_offset[1];
            }
        } catch (e) {}
    }

    var msg_div = document.getElementById('msg_div');
    msg_div.setAttribute('mouseX', mouseX);
    msg_div.setAttribute('mouseY', mouseY);
    var timeout = msg_div.getAttribute('timeout');
    if(timeout) {
        clearTimeout(timeout);
        wbids_message_hide();
    }
}

var isIE8 = false;
/* create message divs */
function wbids_message_init(timeout_ms)
{

    if (navigator.userAgent.toUpperCase().match("MSIE 8"))
        isIE8 = true;

    var body = document.getElementsByTagName('body')[0];

    var msg_div = document.createElement('div');
    msg_div.id = 'msg_div';
    msg_div.style.position = 'absolute';
    msg_div.style.left = '0px';
    msg_div.style.top = '0px';
    msg_div.style.padding = '3px';

    // div style
    msg_div.style.backgroundColor = '#FFFFCC';
    msg_div.style.border = '1px dotted black';
    msg_div.style.display = 'none';
    msg_div.style.fontSize = '12px';
    msg_div.style.fontFamily = 'Arial';
    msg_div.style.color = 'black';
    msg_div.onclick = wbids_message_hide;

    msg_div.setAttribute('timeout_ms', timeout_ms);

    body.appendChild(msg_div);

    // set up event handler
    document.onclick = wbids_saveMousePos;
}

function wbids_message(msg)
{
    var msg_div = document.getElementById('msg_div');

    var mouseX = msg_div.getAttribute('mouseX');
    var mouseY = msg_div.getAttribute('mouseY');
    var timeout_ms = msg_div.getAttribute('timeout_ms');

    var topoff = parseInt(mouseY) + 10;
    var leftoff = parseInt(mouseX) + 20;

    msg_div.style.left = leftoff + 'px';
    msg_div.style.top = topoff + 'px';
    msg_div.innerHTML = msg;
    msg_div.style.display = 'block';

    // set timer to hide the message
    var old_timeout = msg_div.getAttribute('timeout');
    if(old_timeout)
        clearTimeout(old_timeout);
    msg_div.setAttribute('timeout', setTimeout(wbids_message_hide, timeout_ms));

    document.onscroll = wbids_message_hide;
}

function wbids_message_hide()
{
    var msg_div = document.getElementById('msg_div');
    msg_div.style.display = 'none';

    var old_timeout = msg_div.getAttribute('timeout');
    if(old_timeout) {
        clearTimeout(old_timeout);
        msg_div.setAttribute('timeout', 0);
    }

    document.onscroll = null;
}

function wbids_getScroll() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( self.pageYOffset ) == 'number' ) {
        scrOfY = self.pageYOffset;
        scrOfX = self.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
/*
    if(isIE8)
        return [ 0, 0 ];
*/
    return [ scrOfX, scrOfY ];
}

/* currently not used
function wbids_getSize() {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [ myWidth, myHeight ];
}
*/

/* vim:set et sw=4 sts=4: */
