/* Author: yangzeming
 * Date: 2013-12-10
 * Desc: 遮罩层
    
 */
define("component/fulloverlay",function (require, exports, module) {

    
    var fullOverlay = function(point, text, map, style, target) {
        this._point = point;
        this._text = text;
        this._map = map;
        this._style = style || {};
        this._divText = this._style.divText || "";
        this._zIndex = this._style.zIndex || 1;
        this._target = target;
        this._divClass = this._style.divClass || "plan-fullMarker";
        this._class = this._style["class"] || "plan-text"
    };
    fullOverlay.prototype = new BMap.Overlay();
    fullOverlay.prototype.initialize = function(map) {
        this._map = map;
        var _wrap = this._div = document.createElement("div");
        _wrap.className = this._divClass;
        _wrap.style.zIndex = this._zIndex;
        _wrap.status = true;
        if (this._divText) {
            var _wspan = this._span = document.createElement("span");
            _wrap.appendChild(_wspan);
            _wspan.appendChild(document.createTextNode(this._divText))
        }
        var self = this;
        var arrow = this._arrow = document.createElement("div");
        arrow.className = this._class;
        this._text = $.easyUtil.subByte(this._text,20,"..")
        var th = this._text.replace(/[\u4e00-\u9fa5]/g, "aa").length;
        arrow.style.width = (10 * th) + "px";
        var _span = this._span = document.createElement("span");
        arrow.appendChild(_span);
        _span.appendChild(document.createTextNode(this._text));
        _wrap.appendChild(arrow);
        var l;
        $(_wrap).bind("mouseenter", function() {
            var n = this;
            l = setTimeout(function() {
                n.style.zIndex = 5;
                if ($(n).hasClass("mark")) {
                    $(n).addClass("on")
                } else {
                    if ($(n).hasClass("food-fullMarker")) {
                        $(n).addClass("hover-food-fullMarker")
                    } else {
                        if ($(n).hasClass("hotel-fullMarker")) {
                            $(n).addClass("hover-hotel-fullMarker")
                        } else {
                            $(n).addClass("hover-plan-fullMarker")
                        }
                    }
                } if ($(self._arrow).hasClass("plan-text")) {
                    $(self._arrow).addClass("hover-plan-text")
                } else {
                    $(self._arrow).addClass("hover-scenelist-text")
                }
            }, 200)
        });
        $(_wrap).bind("mouseleave", function() {
            if (l) {
                clearTimeout(l)
            }
            if (this.status) {
                this.style.zIndex = self._zIndex;
                $(this).removeClass("on");
                $(self._arrow).removeClass("hover-plan-text hover-scenelist-text")
            }
        });
        $(_wrap).bind("click", function() {
            this.status = false;
            self._target.oldMarker = self._target.currentMarker;
            self._target.currentMarker = this;
            if (self._target.oldMarker) {
                self._target.oldMarker.status = true;
                if (self._target.oldMarker == self._target.currentMarker) {
                    self._target.oldMarker.status = false
                }
                $(self._target.oldMarker).trigger("mouseleave", {})
            }
            self._target.createPop(self._point, {
                popWidth: self._target.popWidth,
                left: 50,
                top: 30
            });
            
        });
        $(self).bind("mouseenter", function() {
            self._div.oldZIndex = self._div.style.zIndex;
            self._div.style.zIndex = 5;
            if ($(self._div).hasClass("mark")) {
                $(self._div).addClass("on")
            } else {
                if ($(self._div).hasClass("food-fullMarker")) {
                    $(self._div).addClass("hover-food-fullMarker")
                } else {
                    if ($(self._div).hasClass("hotel-fullMarker")) {
                        $(self._div).addClass("hover-hotel-fullMarker")
                    } else {
                        $(self._div).addClass("hover-plan-fullMarker")
                    }
                }
            } if ($(self._arrow).hasClass("plan-text")) {
                $(self._arrow).addClass("hover-plan-text")
            } else {
                $(self._arrow).addClass("hover-scenelist-text")
            }
        });
        $(self).bind("mouseleave", function() {
            self._div.style.zIndex = self._div.oldZIndex;
            $(self._div).removeClass("on");
            $(self._arrow).removeClass("hover-plan-text hover-scenelist-text")
        });
        this._map.getPanes().markerPane.appendChild(_wrap);
        return _wrap;
    };
    fullOverlay.prototype.draw = function() {
        var h = this._map;
        var g = h.pointToOverlayPixel(this._point);
        this._div.style.left = g.x - 12 + "px";
        this._div.style.top = g.y - 36 + "px"
    };
    
    module.exports = fullOverlay;
});