/* Author: yangzeming
 * Date: 2013-12-10
 * Desc: 地图组件
 */
define("component/guilinmap", [], function (require, exports, module) {


    var Map = _.Class({
        initial: function (options) {

            this.defaultDipTooltip = 'default';
            var callB = null;
            var self = this;
            var defaultOp = {
                showType: "map",
                mapOp: {
                    fillOpacity: 0.3,
                    fillColor: "46d300",
                    strokeColor: "7B7B7B",
                    strokeOpacity: 0.8,
                    wrapCss: {
                        position: "absolute"
                    },
                    strokeWidth: 0,
                    tipClose: callB,
                    stroke: true,
                    isSelectable: true,
                    singleSelect: true,
					isDeselectable : false,
                    mapKey: 'name',
                    listKey: 'name',
                    onShowToolTip: function (data) {
                       
                        //data.toolTip.html("hahahadfsdf");
                    },
                    onClick: function (e) {
                        //var newToolTip = defaultDipTooltip;


                    },
                    showToolTip: true,
                    toolTipClose: [],  //"tooltip-click",mouseout

                    

                    areas: [
						 {
                            key: "ziyuan",
                            fillColor: "46d300"

                        },
						{
                            key: "quanzhou",
                            fillColor: "46d300"

                        },
						{
                            key: "longsheng",
                            fillColor: "46d300"

                        },
						{
                            key: "guanyang",
                            fillColor: "46d300"

                        },
						{
                            key: "xingan",
                            fillColor: "46d300"

                        },
						{
                            key: "lingchuan",
                            fillColor: "46d300"

                        },
						{
                            key: "gongcheng",
                            fillColor: "46d300"

                        },
						{
                            key: "pingle",
                            fillColor: "46d300"

                        },
						{
                            key: "yangshuo",
                            fillColor: "46d300"

                        },
						{
                            key: "lingui",
                            fillColor: "46d300"

                        },
						{
                            key: "guilin",
                            fillColor: "46d300"

                        },
						{
                            key: "lipu",
                            fillColor: "46d300"

                        },
						{
                            key: "yongfu",
                            fillColor: "46d300"

                        }
                     
                    ]
                }

            };
            this.options = $.extend(true, {}, defaultOp, options);
            this.$con = $(options.con);
            this.$image = $(options.image);
            this.personTip = "hello";
            this.$dibiao = "#haikou";
            this.createMap();

           
        },
        createMap: function () {
            var self = this;
            this.$con.mapster(this.options.mapOp);


        },
        genericToolTip: function (area, name, tooltip, dibiao) {
           
            if (this.options.showType == "map") {
                $.post("/home/home/ReturnJSONAreaCount", { Area: area }, function (result) {
                    if (+result.status == 1) {
                        var _html = '<ul>',
                            data = result.data;
                        _html += '<li style="color:#36FFA6;font-size:14px;font-weight:bold;margin-bottom:5px;">' + name + '</li>';
                        for (var i = 0, len = data.length; i < len; i++) {
                            _html += '<li style="line-height:20px;"><span>' + data[i]["Name"] + ':</span><span style="margin-left:10px;">' + data[i]["Count"] + '</span></li>';
                        }
                        if (data.length == 0) {
                            _html += "<li>暂无数据</li>";
                        }
                        _html += '</ul>';
                        tooltip.html(_html);
                        tooltip.show().position({
                            of: $(dibiao),
                            at: "left top",
                            my: (area == "DF" ? "right+110% top-100%" : "right top-100%")
                        }).hide().effect("explode", { "mode": "show" }, 500, function () {

                        });


                    } else {

                    }

                }, "json");
            } else {

                this.showPersonTip(tooltip, dibiao, area);
            }

        },
        showPersonTip: function (tooltip, dibiao, area) {
            tooltip.html(this.getPersonToolTip());
            //tooltip.css({ left: "636.5px", top: "58px" }).effect("explode", { "mode": "show" }, 500, function () {

            //});
            tooltip.show().position({
                of: $(dibiao),
                at: "left top",
                my: (area == "DF" ? "right+110% top-100%" : "right top-100%")
            }).hide().effect("explode", { "mode": "show" }, 500, function () {

            });
           // $(dibiao).hide().effect("shake", { "mode": "show" }, 1000, function () { });
        },
        toolTip: function (key) {
            this.$con.mapster('tooltip');
            this.$con.mapster('tooltip', key || "haikou");
        },
        setPersonToolTip: function (param) {
            this.personTip = param;
        },
        getPersonToolTip: function () {
            return this.personTip;
        },
        deSelect: function (key) {
            $('area').filter('[name="' + key + '"]').mapster('deselect');
        },
        selectArea: function (key) {
            var target = $('area').filter('[name="' + key + '"]');
            target.mapster('select');
            //target.mapster('tooltip');
           // this.$con.mapster('tooltip');
           // this.$con.mapster('tooltip', key);
           
        },
        showToolTip: function (key) {
            var target = $('area').filter('[name="' + key + '"]');

            target.mapster('tooltip');

        },
        showIcon: function () {
            $(".j_dibiao").effect("clip", { "mode": "show" }, 800, function () {
            });

        }

    });
    module.exports = Map;


});