﻿
/*
悬浮提示
 
new ActiveTip(element/object, moveTip);
element/object：元素，搜索该元素中所有子元素msg属性
moveTip：提示的层，默认：id=moveTitleDiv的元素
------------------------------------------------------------------------------------*/
function ActiveTip(_, C) {
    this.obj = _ ? (typeof (_) == "string" ? document.getElementById(_) : _) : document.body;
    this.objBox = C ? C : document.getElementById("moveTitleDiv");
    var A = this.obj.getElementsByTagName("*");
    this.start = function (B) {
        var D = B ? B : window.event, _ = (D.target) ? D.target : D.srcElement;
        try {
            if (!_.getAttribute("msg")) {
                while (!_.getAttribute("msg") || _.parentNode.tagName == "body") {
                    _ = _.parentNode;
                }
            }
            this.objBox.innerHTML = _.getAttribute("msg");
            this.mousePlace(B);
            this.objBox.style.visibility = "visible";
            if (this.item) {
                this.objBox2.style.visibility = "visible";
            }
            this.ele = _;
            addEventHandler(this.ele, "click", this._move);
            //addEventHandler(this.ele, "mouseout", this._stop);
        }
        catch (D) {
        }
    };
    this.move = function ($) {
        this.mousePlace($);
    };
    this.stop = function ($) {
        this.objBox.innerHTML = "";
        this.objBox.style.visibility = "hidden";
        removeEventHandler(this.ele, "click", this._move);
       // removeEventHandler(this.ele, "mouseout", this._stop);
    };
    this._start = BindAsEventListener(this, this.start);
    this._move = BindAsEventListener(this, this.move);
    this._stop = BindAsEventListener(this, this.stop);
    for (var B = 0; B < A.length; B++) {
        if (A[B].getAttribute("msg") && A[B].getAttribute("msg").length > 0) {
            addEventHandler(A[B], "click", this._start);
        }
    }
}
ActiveTip.prototype.mousePlace = function (D) {
    var A = D ? D : window.event, C = 16, B = 12, _ = document.documentElement.scrollLeft || document.body.scrollLeft, $ = document.documentElement.scrollTop || document.body.scrollTop;
    if (this.item) {
        if (A.clientX + C + this.objBox.offsetWidth + this.objBox2.offsetWidth < document.documentElement.clientWidth) {
            this.objBox.style.left = A.clientX + _ + C + "px";
            alert(A.clientX);
            this.objBox2.style.left = A.clientX - 130 + _ + C + this.objBox.offsetWidth - 1 + "px";
        } else {
            this.objBox.style.left = A.clientX - 130 + _ - this.objBox.offsetWidth + "px";
            alert(A.clientX);
            this.objBox2.style.left = A.clientX - 130 + _ - this.objBox.offsetWidth - this.objBox2.offsetWidth + 1 + "px";
        }
        if (A.clientY + B + this.objBox.offsetHeight < document.documentElement.clientHeight) {
            this.objBox.style.top = A.clientY + $ + B + "px";
            this.objBox2.style.top = A.clientY + $ + B + "px";
        } else {
            var E = A.clientY + $ - this.objBox.offsetHeight;
            this.objBox.style.top = (E > 0 ? E : ($ + 10)) + "px";
            this.objBox2.style.top = (E > 0 ? E : ($ + 10)) + "px";
        }
    } else {
        if (A.clientX + C + this.objBox.offsetWidth < document.documentElement.clientWidth) {
            this.objBox.style.left = A.clientX - 130 + _ + C + "px";

        } else {
            this.objBox.style.left = A.clientX - 130 + _ - this.objBox.offsetWidth + "px";

        }
        if (A.clientY + B + this.objBox.offsetHeight < document.documentElement.clientHeight) {
            this.objBox.style.top = A.clientY + $ + B + "px";
        } else {
            E = A.clientY + $ - this.objBox.offsetHeight;
            this.objBox.style.top = (E > 0 ? E : ($ + 10)) + "px";
        }
    }

};


document.write('<div id="moveTitleDiv" style="visibility:hidden;position:absolute;z-index:100000;padding:5px;visibility:hidden;opacity:0.8; font-size:12px;filter:alpha(opacity=100);"></div>');



/* --------------------
添加事件监控
addEventHandler(element, "mouseup", BindAsEventListener(this, fn));
-------------------- */
function BindAsEventListener($, A) { var _ = function () { A.apply($, arguments) }; return _; }
function addEventHandler(_, A, $) { if (_.addEventListener) _.addEventListener(A, $, false); else if (_.attachEvent) _.attachEvent("on" + A, $); else _["on" + A] = $ }
function removeEventHandler(_, A, $) { if (_.removeEventListener) { _.removeEventListener(A, $, false); } else if (_.detachEvent) { _.detachEvent("on" + A, $); } else { _["on" + A] = null; } }
