var _madwho_popup = {
    vertical_offset : '-3px',
    horizontal_offset : '-3px',
    start_delay : 500,
    end_delay : 500,
    clientX: 0,
    clientY: 0,

    showpreview : function(innerHTML, obj, event, endDelay) {
        this.clientX = event.clientX;
        this.clientY = event.clientY;
        var delay = this.end_delay;
        if (typeof endDelay != "undefined") {
            delay = endDelay;
        }
        this.show(unescape(innerHTML), obj, event, delay);
    },

    show : function(content, obj, e, delay) {
        var temp = content;
        content = '<div class="popup_tile">';
        content += '<div class="cls">';
        content += '<img style="cursor:pointer;" onclick="_madwho_popup.hideNow()" src="close_down.gif" alt="Close"/>';
        content += '</div>';
        content += temp;
        content += '</div>';
        temp = null;

        if (window.event) {
            event.cancelBubble = true;
        } else if (e.stopPropagation) {
            e.stopPropagation();
        }
        if (typeof delay == "undefined") {
            delay = this.end_delay;
        }
        this._do_hide();
        var tooltip = document.getElementById('popup');
        tooltip.innerHTML = content;
        if ((e.type == 'click' && tooltip.style.visibility == 'hidden') || e.type == 'mouseover') {
            var self = this;
            this._show_handler = setTimeout(function() {
                self._do_show();
            }, delay);
        } else if (e.type == 'click') {
            tooltip.style.visibility = 'hidden';
        }
        tooltip.x = document.body.scrollLeft + this.clientX + 10;
        tooltip.y = document.body.scrollTop + this.clientY + 10;
        tooltip.style.left = document.body.scrollLeft + this.clientX + 10 + 'px';
        tooltip.style.top = document.body.scrollTop + this.clientY + 10 + 'px';
        return true;
    },

    hide : function() {
        this._must_hide = true;
        var self = this;
        if (this._am_visible) {
            this._hide_handler = setTimeout(function() {
                self._do_hide();
            }, this.start_delay);
        } else {
            this._do_hide();
        }
        return true;
    },

    hideNow : function() {
        this._must_hide = true;
        var self = this;
        this._hide_handler = setTimeout(function() {
            self._do_hide();
        }, 0);
        return true;
    },

//---Private
    _show_handler : null,
    _hide_handler : null,
    _must_hide : true,
    _am_visible : false,

    _clear_tip : function() {
        if (typeof this._hide_handler != 'undefined' || this._hide_handler !== null) {
            clearTimeout(this._hide_handler);
            delete(this._hide_handler);
        }
        if (typeof this._show_handler != 'undefined' || this._show_handler !== null) {
            clearTimeout(this._show_handler);
            delete(this._show_handler);
        }
    },

    _do_show : function() {
        document.getElementById('popup').style.visibility = 'visible';
        this._am_visible = true;
    },

    _do_hide : function() {
        if (this._must_hide) {
            document.getElementById('popup').style.visibility = 'hidden';
            this._am_visible = false;
        }
        this._clear_tip();
    },

    _continue : function() {
        this._must_hide = false;
    },

    _stop : function() {
        this._must_hide = true;
        this.hide();
    }
};
