﻿/// <reference path="libs/mootools-1.2.3-core-yc.js" />


function getUserName() {
    try {
        var ut = Cookie.read('citycome');
        var u = ut.split('&')[0];
        u = u.substring(u.indexOf('=') + 1);
        return u;

    } catch (e) {
        return '';
    }
};
var ____uname = '';
function updateUserStatus() {
    var u = getUserName();
    if (____uname == u) return;
    ____uname = u;
    document.getElementById('dUserName').innerHTML = u;
    if (u == '') {
        $$('.u_guest').each(function(item) {
            item.style.display = '';
        });
        $$('.u_logined').each(function(item) {
            item.style.display = 'none';
        });
    } else {
        $$('.u_guest').each(function(item) {
            item.style.display = 'none';
        });
        $$('.u_logined').each(function(item) {
            item.style.display = '';
        });
    }
};

var defvalues = {
    'searchKeyword': '朝阳广场 cygc'
};

// 搜索面板
function SearchPanel() {
    var self = this;
    //    var tabs = ['dSearch_0', 'dSearch_1', 'dSearch_2'];
    //    var pnls = ['dContent_0', 'dContent_1', 'dContent_2'];
    //    for (var i = 0; i < tabs.length; i++) {
    //        $(pnls[i])._idx = i;
    //        $(tabs[i])._idx = i;
    //        $(tabs[i]).addEvent('click', function() {
    //            self.ShowPnl(this._idx);
    //        });
    //    }

    //    // 显示搜索页签
    //    this.ShowPnl = function(_idx) {
    //        for (var i = 0; i < tabs.length; i++) {
    //            var o = $(tabs[i]);
    //            if (_idx == o._idx) {
    //                o.className = 'current';
    //            } else {
    //                o.className = '';
    //            }
    //            o = null;
    //        }
    //        for (var i = 0; i < pnls.length; i++) {
    //            var o = $(pnls[i]);
    //            if (_idx == o._idx) {
    //                o.setOpacity(0);
    //                o.style.display = '';
    //                o.morph({ opacity: [0, 1] });
    //            } else {
    //                o.style.display = 'none';
    //            }
    //            o = null;
    //        }
    //    };

    // 地图搜索
    var oInputbox = $('dInputKeyword');
    var oBtnMapSearch = $('dBtnMapSearch');
    if (oInputbox && oBtnMapSearch) {

        oInputbox.value = defvalues.searchKeyword;
        oInputbox.addEvent('focus', function() {
            if (oInputbox.value.trim() == defvalues.searchKeyword) {
                oInputbox.value = '';
            }
            if (!oInputbox.getParent().hasClass('inputboxActive')) oInputbox.getParent().addClass('inputboxActive');
        });
        oInputbox.addEvent('blur', function() {
            if (oInputbox.getParent().hasClass('inputboxActive')) oInputbox.getParent().removeClass('inputboxActive');
            if (oInputbox.value == '') {
                oInputbox.value = defvalues.searchKeyword;
            }
        });
        oInputbox.addEvent('keypress', function(event) {
            if (event.key == 'enter') {
                self.SearchMap(oInputbox.value.trim());
            }
        });
        oBtnMapSearch.addEvent('click', function(event) {
            self.SearchMap(oInputbox.value.trim());
        });
    }
    this.SearchMap = function(_kw) {
        _kw = _kw.trim();
        if (_kw == '' || _kw == defvalues.searchKeyword) {
            alert('请输入搜索关键字');
            return;
        }
	var area = 'city';
        var viewport = gMap.getMapViewport();
        if ($('search_inview').checked )
            area = viewport.l + ',' + viewport.t + ',' + viewport.r + ',' + viewport.b;
       
        var url = 'map/SearchResult.aspx?area=' + area + '&kw=' + escape(_kw);
        gApp.showPanel(url);
    };
};


// 应用程序
function CitycomeApp() {
    var self = this;

    var userAgent = navigator.userAgent.toLowerCase();
    this.browser = {
        version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [0, '0'])[1],
        safari: /webkit/.test(userAgent),
        opera: /opera/.test(userAgent),
        msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
        mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
    };
    this.isIE6 = this.browser.msie && this.browser.version == '6.0';

    var getEle = function(oid) {
        return document.getElementById(oid);
    };


    // 初始化侧栏
    var openFrameItv = null;
    var openFrameUrl = '';
    var oFrame = document.getElementById('dSidePanel');
    this.showPanel = function(url) {
        $clear(openFrameItv);
        //if(url== openFrameUrl) return;
        openFrameUrl = url;
        openFrameItv = setTimeout(function() {
            try {
                if (openFrameUrl == '#' || openFrameUrl == 'javascript:void(0)') {
                    return false;
                }
                oFrame.src = 'jump.htm?' + escape(openFrameUrl);
            } catch (e) { }
        }, 30);

    };
    this.setActiveTab = function(tabid) {
        $$('#dSysTabs a').each(function(mi, i) {
            if (mi.hasClass('current')) mi.removeClass('current');
        });

        var o = $(tabid);
        if (o) {
            o.addClass('current');
        }
    };
    $$('#dSysTabs a').each(function(item, i) {
        if(item.target!= '_blank')
        item.addEvent('click', function(event) {
            self.showPanel(this.href);
            gApp.togSidePanel(true);
            $$('#dSysTabs a').each(function(mi) {
                if (mi.hasClass('current')) mi.removeClass('current');
            });
            $(event.target).addClass('current');
            event.stop();
            return false;
        });
    });



    var idSysBanner = 'dSysBanner';
    var idSysTools = 'dSysTools';

    var idSysMap = 'dSysMap';
    var idSysSide = 'dSysSide';

    var idSysSplit = 'dSysSplit';
    var idSysSplitTogButton = 'dSysSplitTogButton';
    var idSysSplitFullScreen = 'dSysSplitFullScreen';


    var isFullScreen = false;    // [ 屏幕一共有三种模式：正常、全屏、侧栏隐 ]
    var isShowSide = true;       // [ 是否显示侧栏 ]
    var sideFrameWidth = getEle(idSysSide).offsetWidth;        // 记录侧栏的宽度

    var ptxSide = $(idSysSide).getCoordinates();
    $(idSysSide).setStyles({
        'position': 'absolute',
        'left': ptxSide.left,
        'top': ptxSide.top
    });

    var resizeItv = null;
    var delayResize = function() {
        clearTimeout(resizeItv);
        setTimeout(self.doResize, 50);
    };

    // 搜索面板
    this.searchPanel = new SearchPanel();

    this.doResize = function() {
        var ps = window.getSize();

        // 限制窗口最小宽度
        if (ps.x < 600) ps.x = 600;
        if (ps.y < 400) ps.y = 400;

        var oBanner = document.getElementById(idSysBanner);
        var oMap = document.getElementById(idSysMap);
        var oSplit = document.getElementById(idSysSplit);
        var oSide = document.getElementById(idSysSide);
        var oSysToolbar = document.getElementById(idSysTools);

        // 计算
        var bannerHeight = 0;
        var splitWidth = 0;
        var splitHeight = 0;
        var sideWidth = 0;
        var sideHeight = 0;
        var toolbarHeight = parseInt(getEle(idSysTools).offsetHeight, 10);

        // 全屏与非全屏模式下Banner的高度
        if (isFullScreen) {
            bannerHeight = 0;
            if (oBanner.style.display != 'none') oBanner.style.display = 'none';
            getEle(idSysSplitFullScreen).className = 'togFullscreenClose';
        } else {
            if (oBanner.style.display != '') oBanner.style.display = '';
            bannerHeight = oBanner.offsetHeight;
            getEle(idSysSplitFullScreen).className = 'togFullscreenOpen';
        }

        // 得到顶部高度
        var topHeight = bannerHeight + toolbarHeight;

        // 工具栏下的阴影
        var oShadow = getEle('dSysToolsShadow');
        if (oShadow) {
            oShadow.style.top = topHeight + 'px';
        }

        // 限制最小宽度
        oSysToolbar.style.width = ps.x + 'px';
        oBanner.style.width = ps.x + 'px';

        // 计算侧栏宽度
        if (isShowSide) {
            if (oSide.style.display != '') oSide.style.display = '';
            sideWidth = sideFrameWidth;
            sideHeight = ps.y - topHeight;

            oSide.style.width = sideWidth + 'px';
            oSide.style.height = sideHeight + 'px';
            oSide.style.top = topHeight + 'px';
            oSide.style.left = (ps.x - sideWidth) + 'px';

            getEle(idSysSplitTogButton).className = 'togSidebarOpen';
            //oSideNavTabs.style.display = '';
        } else {
            if (oSide.style.display != 'none') oSide.style.display = 'none';
            sideWidth = 0;
            sideHeight = 0;

            getEle(idSysSplitTogButton).className = 'togSidebarClose';
            //oSideNavTabs.style.display = 'none';
        }

        splitHeight = ps.y - topHeight;
        splitWidth = oSplit.offsetWidth;

        oSplit.style.height = splitHeight + 'px';
        oSplit.style.top = topHeight + 'px';
        oSplit.style.left = (ps.x - sideWidth - splitWidth) + 'px';


        var oSBButton = getEle(idSysSplitTogButton);
        var mSBHeight = oSBButton.offsetHeight;
        oSBButton.style.top = (splitHeight - mSBHeight) / 2 + 'px';
        oSBButton.style.left = (splitWidth - oSBButton.offsetWidth) + 'px';

        var oFSButton = getEle(idSysSplitFullScreen);
        var mFBHeight = oFSButton.offsetHeight;
        oFSButton.style.top = (splitHeight - mSBHeight) / 2 + mSBHeight + 'px';
        oFSButton.style.left = (splitWidth - oFSButton.offsetWidth) + 'px';


        oMap.style.top = (topHeight) + 'px';
        oMap.style.left = (0) + 'px';
        oMap.style.width = (ps.x - sideWidth - splitWidth) + 'px';
        oMap.style.height = (ps.y - topHeight) + 'px';


        oSBButton = null;
        oFSButton = null;
        oShadow = null;

        oBanner = null;
        oMap = null;
        oSplit = null;
        oSide = null;
        oSysToolbar = null;

        if (gMap) gMap.doResize();
    };

    // 全屏切换
    //@status: 指定是否全屏，不设置则在全屏与非全屏之间进行切换
    this.togFullScreen = function(status) {
        if (status) {
            isFullScreen = status;
        } else {
            isFullScreen = !isFullScreen;
        }
        if (isFullScreen) isShowSide = false; else isShowSide = true;
        self.doResize();
    };

    // 侧栏切换
    //@status: 指定是否显示侧栏，不设置值则在显示与不显示侧栏之间切换
    //@fwidth: 指定侧栏的宽度，不设置则使用最后一次使用的宽度
    this.togSidePanel = function(status, fwidth) {
        if (status) {
            //if (status == isShowSide) return;
            isShowSide = status;
        } else {
            isShowSide = !isShowSide;
        }
        if (fwidth && typeof (fwidth) == 'number') {
            sideFrameWidth = fwidth;
        }
        self.doResize();
    };

    this.doDestroy = function() {
        clearInterval(update_user_status_itv);
        update_user_status_itv = null;
    };

    this.doInit = function() {
        // 设置窗口分隔按钮的事件
        $(idSysSplitTogButton).addEvent('click', function() {
            isShowSide = !isShowSide;
            self.doResize();
        }).setProperty('hideFocus', 'true');

        $(idSysSplitFullScreen).addEvent('click', function() {
            self.togFullScreen();
        }).setProperty('hideFocus', 'true');

        // 工具栏阴影
        var oShadow = document.getElementById('dSysToolsShadow');
        if (oShadow) {
            if (self.isIE6) {
                oShadow.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="citycomeSkin/default/map/shadow.png")';
            } else {
                oShadow.src = 'citycomeSkin/default/map/shadow.png';
            }
        }

        var l_urls = [
            'http://nnmap2009.citycome.com/mb2.aspx?v={V}&t={T}&x={X}&y={Y}&z={Z}&f={F}',
            'http://map-nn.citycome.com/nnmaps/mb2.aspx?v={V}&t={T}&x={X}&y={Y}&z={Z}&f={F}'
        ];

        // gConfig.startup.x = 229436;
        // gConfig.startup.y = 124458;

        gMap = new CityMap('dSysMap', gConfig);



        var glayer_m = gMap.BuildMapLayer(true, l_urls, 4, 2, false, 'jpeg', true, false);

        var glayer_r = gMap.BuildMapLayer(false, l_urls, 4, 3, true, 'png', true, true);

        gMap.BuildHotspotLayer('hotspot', true, '_map_hs.ashx', function(arg, _id, _name) {
            var pt = gMap.screen2map(gMap.scrmousePt);
            ObjWin.show(pt.x, pt.y, _id, _name);
        });

        var glayer_l = gMap.BuildLabelsLayer('citycome-labels', false, '_map_label.ashx', 'moilabel', function(arg, _id, _name) {
            var pt = gMap.screen2map(gMap.scrmousePt);
            ObjWin.show(pt.x, pt.y, _id, _name);
        });


        gMap.BuildZoombar();
/*
        var glayer_ad = gMap.BuildADLayer('citycome_ad', true);
        glayer_ad.add('ad_sofang', 'http://nanning.citycome.com/citycomeAD/swf/sofang.swf', 222318, 125838, 219, 225, Math.round(219 / 2), 225, 'swf', true, 'http://www.soufun.com/');
        glayer_ad.add('ad_bdwj', 'http://nanning.citycome.com/citycomeAD/swf/bdwj.swf', 224491, 126489, 219, 225, Math.round(219 / 2), 225, 'swf', true, '');
        glayer_ad.add('ad_default', 'http://nanning.citycome.com/citycomeAD/swf/default.swf', 222627, 125305, 219, 225, Math.round(219 / 2), 225, 'swf', true, 'http://nanning.citycome.com/web/citycome_ad/a1.htm');
        glayer_ad.add('ad_yufengyinglun', 'http://nanning.citycome.com/citycomeAD/swf/yufengyinglun.swf', 229176, 124333, 219, 225, Math.round(219 / 2), 225, 'swf', true, 'http://nanning.citycome.com/web/FondEngland/FondEngland.htm');

	    glayer_ad.add('ad_ggad_dxhb', 'http://nanning.citycome.com/citycomeAD/swf/ggad_dxhb.swf', 224953, 125571, 219, 225, Math.round(219 / 2), 225, 'swf', true, '');
    	

	    glayer_ad.add('ad_carshow', 'http://nanning.citycome.com/citycomeAD/swf/ad_car2.swf', 226734, 127616, 219, 225, Math.round(219 / 2), 225, 'swf', true, 'http://life.citycome.com/viewthread.php?tid=11655');
    		
	    glayer_ad.add('ad_bdwj', 'http://nanning.citycome.com/citycomeAD/swf/ad_bbw.swf', 227080,115126, 219, 225, Math.round(219 / 2), 225, 'swf', true, 'http://life.citycome.com/viewthread.php?tid=11875&page=1&extra=');	

glayer_ad.add('ad_soho2', 'http://nanning.citycome.com/citycomeAD/swf/ggad_soho2.swf', 217470,124121, 219, 225, Math.round(219 / 2), 225, 'swf', true, 'http://life.citycome.com/viewthread.php?tid=11903');	
*/
        var birdview = gMap.BuildBirdView('city-birdview', 220, 145, true, l_urls, 32);
        birdview.setRoleLayerManager(glayer_r);
        birdview.setLabelManager(glayer_l);

    };

    var update_user_status_itv = setInterval(updateUserStatus, 3000);


    // 添加窗体事件
    window.addEvent('resize', delayResize);
    window.addEvent('domready', delayResize);
    window.addEvent('unload', this.doDestroy);

    // 调整界面位置
    this.doResize();

    // 执行初始化
    this.doInit();

    // 调整界面位置
    this.doResize();

    if (_START == "MO") {
        window.setTimeout(function() {
            ObjWin.show(mox, moy, moid, moname);
        }, 500);
    }
};

var gMap = null;
var gApp = new CitycomeApp();

function AjaxService() {
    var XHRQueue = [];
    var XHRQueueAbort = function(_method) {
        for (var i = 0; i < XHRQueue.length; i++) {
            if (XHRQueue[i]._method == _method) {
                XHRQueue[i]._obj.cancel();
                break;
            }
        }
    };
    var XHRQueueAdd = function(_m, _o) {
        var isExit = false;
        for (var i = 0; i < XHRQueue.length; i++) {
            if (XHRQueue[i]._method == _m) {
                XHRQueue[i]._obj = _o;
                isExit = true;
                break;
            }
        }
        if (!isExit) XHRQueue.push({ _method: _m, _obj: _o });
    };
    this.getData = function(_method, _url, _param, _CallBack) {
        XHRQueueAbort(_method);
        Req = new Request({ url: (_url + "?" + _param), method: 'get', onComplete: function() { _CallBack(this.response.text); } }).send();
        XHRQueueAdd(_method, Req);
    };
}
var AjaxSvc = new AjaxService();

function BusPlanSvc() {
    var self = this;
    var pos = { s: null, e: null };
    this.setPoint = function(type) {
        try {
            gMap.getmappos_start(type, "取点", false, self.succ, null);
        }
        catch (e) { }
    };
    this.succ = function(type, mapx, mapy) {
        var urlp = 't=' + new Date().getSeconds();
        if (type == 1) {
            pos.s = { x: mapx, y: mapy };
        }
        else {
            pos.e = { x: mapx, y: mapy };
        }
        if (pos.s != null) urlp += '&spos=' + pos.s.x + ',' + pos.s.y;
        if (pos.e != null) urlp += '&epos=' + pos.e.x + ',' + pos.e.y;
        gApp.showPanel('map/BusSearchResult.aspx?' + urlp);
        if (pos.s != null && pos.e != null) {
            pos.s = null;
            pos.e = null;
        }
    };
}
var BusSvc = new BusPlanSvc();

function BusStationInfoWin() {
    this.stations = [];
    var self = this;
    var _bsID = 0;
    var isInit = false;
    var winw = 311;
    var winh = 150;
    var win = null;
    var posx = 0;
    var posy = 0;
    var content = '';
    var header = '<div class="bWHeader"><div><span>{0}</span><a href="javascript:BusWin.close();" title="关闭" class="close"></a></div></div><div class="bWBody" style=\"height: 112px;\">&nbsp;</div>';
    this.init = function() {
        if (win == null) win = gMap.BuildWindow('busStationInfoWin', winw, winh, null, null);
    };
    this.showline = function(lineid) {
        gApp.showPanel('map/BusSearchResult.aspx?lineid=' + lineid + '&nofly=1');
    };
    this.showbyid = function(_id) {
        for (var i = 0; i < self.stations.length; i++) {
            if (self.stations[i].id == _id) {
                self.show(self.stations[i].x, self.stations[i].y, self.stations[i].id, self.stations[i].name);
                break;
            }
        }
    };
    this.show = function(x, y, id, _title) {
        if (!isInit) self.init();

        if (x < 1 || y < 1) return;

        var loadinfo = false;
        if (_bsID != id) loadinfo = true;

        if (loadinfo) {
            posx = x;
            posy = y;
            header = header.replace("{0}", _title);
            win.show(x, y, header, winw, winh);
            _bsID = id;
            self.getInfo(id, _title);
        }
        else {
            win.show(x, y, content, winw, winh);
        }
    };
    this.getInfo = function(id, name) {
        AjaxSvc.getData('gblbshtml', "map/bussvc.ashx", "method=gblbshtml&param=" + id + "&name=" + escape(name), self.cb);
    };
    this.cb = function(res) {
        if (res != null && res != "") {
            content = res;
            win.show(posx, posy, res, winw, winh);
        }
    };
    this.close = function() {
        win.close();
    };
}
var BusWin = new BusStationInfoWin();

function MapObjInfoWin() {
    var self = this;
    var _ObjID = 0;
    var isInit = false;
    var winw = 311;
    var winh = 376;
    var tabobj = ['oWTab1', 'oWTab2', 'oWTab3'];
    var tabpnl = ['oWPnl1', 'oWPnl2', 'oWPnl3'];
    var win = null;
    var posx = 0;
    var posy = 0;
    var content = '';
    var header = '<div class="oWHeader"><div><span>{0}</span><a href="javascript:ObjWin.close();" title="关闭" class="close"></a></div></div><div class="oWBody" style=\"height: 232px;\"></div>';
    this.init = function() {
        if (win == null) win = gMap.BuildWindow('mapObjInfoWin', winw, winh, null, null);
    };
    this.show = function(x, y, id, _title) {
        if (!isInit) self.init();

        if (x < 1 || y < 1) return;

        var loadinfo = false;
        if (_ObjID != id) loadinfo = true;

        if (loadinfo) {
            posx = x;
            posy = y;
            header = header.replace("{0}", _title);
            win.show(x, y, header, winw, winh);
            _ObjID = id;
            self.getBaseInfo(id);
        }
        else {
            win.show(x, y, content, winw, winh);
        }
    };
    this.tab = function(idx) {
        for (var i = 0; i < tabobj.length; i++) {
            $(tabobj[i]).className = (idx == i) ? "on" : "off";
            $(tabpnl[i]).style.display = (idx == i) ? "" : "none";
        }
        
    };
    this.ApplyShop = function(id)
    {
          window.open("http://life.citycome.com/shopping/shop/member.php?ac=itemapply&shopid=m"+id);
      }
    this.AddShop = function() {
         window.open("http://life.citycome.com/shopping/shop/post.php?action=newshop");
     }
     this.ReportBug = function(id) {
         alert("感谢您为我们补充信息，系统将跳转到商铺页面完成纠错步骤。\n*如果商铺信息有误，请点击‘商家展示’一栏中的‘补充商铺信息’按钮\n*如果是地图有误，请点击地图右下方的‘报错’。");
         window.open("http://life.citycome.com/shopping/shop/m"+id);
     }
    this.getBaseInfo = function(id) {
        AjaxSvc.getData('getobjinfo', "map/mapsvc.ashx", "method=getobjinfo&param=" + id, self.cb);
    };
    this.cb = function(res) {
        if (res != null && res != "") {
            content = res;
            win.show(posx, posy, res, winw, winh);
            sa.setStatus(true);
            self.tab(2);
        }
    };
    this.close = function() {
        win.close();
    };
    this.getPOS = function() {
        return { x: posx, y: posy };
    };
};
var ObjWin = new MapObjInfoWin();

// 公交搜索面板
var PnlOfBusSearch = function() {
    var searchBusLine = $("btnBusLine");
    var bussel = $("busSel");
    var locates = $("btn_locates");
    var locatee = $("btn_locatee");
    var startStation = $("txt_bus_s");
    var endStation = $("txt_bus_e");
    var searchStation = $("txt_bus_station");

    bussel.onchange = function() {
        for (var i = 1; i < 5; i++) {
            if (bussel.value == 4) {
                searchBusLine.style.display = 'none';
            }
            else {
                searchBusLine.style.display = '';
            }
            if (this.value == i) {
                $("d_busmode" + i).style.display = '';
            }
            else {
                $("d_busmode" + i).style.display = 'none';
            }
        }
    };

    searchBusLine.addEvent('click', function() {
        if (bussel.value == "1") {
            gApp.showPanel('map/BusSearchResult.aspx?st=' + escape($('txt_bus_s').value) + '&ed=' + escape($('txt_bus_e').value));
        }
        if (bussel.value == "2") {
            gApp.showPanel('map/BusSearchResult.aspx?lineid=' + $('txtBusLine').value);
        }
        if (bussel.value == "3") {
            gApp.showPanel('map/BusSearchResult.aspx?keyword=' + escape($('txt_bus_station').value));
        }
    });
    locates.addEvent('click', function() {
        BusSvc.setPoint(1);
    });
    locatee.addEvent('click', function() {
        BusSvc.setPoint(2);
    });
};
PnlOfBusSearch();


// 背投广告
(function() {
    var displayTime = 10;
    var g = function(_id) {
        return document.getElementById(_id);
    };
    if(!g('dMaskAD'))return ;
    //    var odMaskAD = g('dMaskAD');
    //    var odMaskBG_T = g('dMaskBG_T');
    //    var odMaskBG_B = g('dMaskBG_B');
    //    var odMaskWating = g('dMaskWating');
    //    var odMaskWaitTime = g('dMaskWaitTime');
    //    var odMaskClose = g('dMaskClose');
    //    var odMaskT = g('dMaskT');
    //    var odMaskB = g('dMaskB');
    //    var odMaskList = g('dMaskList');

    // 关闭广告层
    window.doCloseMaskAD = function() {
        clearInterval(adcounterItv); adcounterItv = null;
        $('dMaskWating').style.display = 'none';
        $('dMaskClose').style.display = 'none';
        $('dMaskList').style.display = 'none';
        doCloseAD();
    };

    var closeADItv = null;

    $('dMaskBG_T').style.top = '0px';
    $('dMaskBG_B').style.top = '270px';

    var openHeight = 0;

    var ajustElements = function() {
        var ps = window.getSize();
        var boH = ps.y - 94;
        $('dMaskAD').setStyles({
            'width': ps.x,
            'height': boH
        });
        var boHdiv2 = Math.round(boH / 2);

        if (null == closeADItv) {
            $('dMaskBG_T').setStyle('height', boHdiv2 - openHeight);

            $('dMaskBG_B').setStyles({
                'top': boHdiv2 + openHeight,
                'height': boHdiv2 - openHeight
            });
        }

        $('dMaskT').setStyles({
            'top': boHdiv2 - 170 - openHeight,
            'left': Math.round((ps.x - 600) / 2)
        });
        $('dMaskB').setStyles({
            'top': boHdiv2 + openHeight,
            'left': Math.round((ps.x - 600) / 2)
        });

        $('dMaskWating').setStyles({
            'top': boHdiv2 - 170 - openHeight - 22,
            'left': Math.round((ps.x - 600) / 2)
        });
        $('dMaskClose').setStyles({
            'top': boHdiv2 - 170 - openHeight - 22,
            'left': Math.round(ps.x / 2 + 300 - 50)
        });
        $('dMaskList').setStyles({
            'top': boHdiv2 + openHeight + 170 + 3,
            'left': Math.round((ps.x - 600) / 2)
        });
    };
    ajustElements();

    $('dMaskAD').setStyle('visibility', 'visible');

    window.addEvent('resize', ajustElements);

    // 关闭广告
    var doCloseAD = function() {
        closeADItv = setInterval(function() {

            var mTop = parseInt($('dMaskBG_T').style.top, 10);
            var mBom = parseInt($('dMaskBG_B').style.top, 10);

            var nTop = mTop - 15;
            var nBom = mBom + 15;

            $('dMaskBG_T').setStyle('top', nTop);
            $('dMaskBG_B').setStyle('top', nBom);

            $('dMaskT').setStyle('top', nTop + parseInt($('dMaskBG_T').offsetHeight, 10) - $('dMaskT').offsetHeight);
            $('dMaskB').setStyle('top', nBom);

            if (mTop < -$('dMaskBG_T').getCoordinates().height) {
                clearInterval(closeADItv); closeADItv = null;
                g('dMaskAD').style.display = 'none';
                window.removeEvent('resize', ajustElements);
            }
        }, 30);
    };


    // 关闭倒计时
    var adcounterItv = setInterval(function() {
        displayTime--;
        g('dMaskWaitTime').innerHTML = displayTime;
        if (displayTime <= 0) {
            clearInterval(adcounterItv); adcounterItv = null;
            doCloseMaskAD();
        }
    }, 1000);
})();

/*基本信息框 周边*/
function SearchAround() {
    var self = this;

    this.idx = -1;
    this._id = '';
    this.pops = [];
    this.icons = ['gc.gif', 'zs.gif', 'cy.gif', 'yl.gif', 'gw.gif', 'mr.gif', 'yh.gif', 'yd.gif', 'yd.gif', 'jyz.gif'];
    this.icons2 = ['gc2.gif', 'zs2.gif', 'cy2.gif', 'yl2.gif', 'gw2.gif', 'mr2.gif', 'yh2.gif', 'yd2.gif', 'yd2.gif', 'jyz2.gif'];
    this.morePnl = $('d_moreAroundPnl');
    this.morePnlClose = $('a_moreAourndClose');
    this.morePnlClose.addEvent('click', function() {
        self.morePnl.style.top = '-2000px';
    });
    this.morePnlLinks = $$('#d_moreAround A');
    for (var i = 0; i < this.morePnlLinks.length; i++) {
        this.morePnlLinks[i].addEvent("click", function() {
            self.more(this);
            $('d_ClearMark').style.display = '';
        });
    }

    this.showmore = function() {
        var wincoor = window.getCoordinates();
        var pnlcoor = self.morePnl.getCoordinates();
        self.morePnl.style.left = (wincoor.width - pnlcoor.width) / 2 + 'px';
        self.morePnl.style.top = (wincoor.height - pnlcoor.height) / 2 + 'px';
    };
    this.more = function(obj) {
        var id = obj.id.replace('a_c', '');
        var ca = gMap.getMapViewport();
        var area = ca.l + ',' + ca.t + ',' + ca.r + ',' + ca.b;
        gApp.showPanel('/map/SearchResult.aspx?area=' + area + '&class=' + id);
    };
    this.show = function(id, idx) {
        self._id = id;
        self.idx = idx;
        self.setStatus(false);
        if (id == 'bs') {
            self.loadObjByCatID(id, self.getRange());
        }
        else {
            var ca = self.getRange();
            var area = ca.l + ',' + ca.t + ',' + ca.r + ',' + ca.b;
            gApp.showPanel('/map/SearchResult.aspx?area=' + area + '&class=' + id);
        }
        if (id == '-1') {
            $('d_ClearMark').style.display = 'none';
            self.morePnl.style.top = '-2000px';
        }
    };
    this.changeRange = function() {
        if (self._id == 'bs') {
            self.loadObjByCatID(self._id, self.getRange());
        }
        else {
            var ca = self.getRange();
            var area = ca.l + ',' + ca.t + ',' + ca.r + ',' + ca.b;
            gApp.showPanel('/map/SearchResult.aspx?area=' + area + '&class=' + self._id);
        }
        //self.loadObjByCatID(self._id, self.getRange());
    };
    this.getRange = function() {
        var range = 0;
        var rads = $('d_aroundRange').getElementsByTagName("INPUT");
        for (var i = 0; i < rads.length; i++) {
            if (rads[i].checked) {
                range = (rads[i].value * 2);
                break;
            }
        }
        var pos = ObjWin.getPOS();
        return { l: (pos.x - range), t: (pos.y - range), r: (pos.x + range), b: (pos.y + range) };
    };
    this.loadObjByCatID = function(id, ca) {

        function mvcb(res) {
            try {
                eval("var list = " + res);
                self.pops = list;
                gMap.layerMarks.clear();
                for (var i = 0; i < self.pops.length; i++) {
                    var o = self.pops[i];
                    gMap.layerMarks.add(o.id, 'citycomeSkin/default/map/caticons/' + self.icons[self.idx], o.x, o.y, 25, 29, 13, 29, o.name, function(_id) { self.showinfo(_id); });
                }
            }
            catch (e) { }
        }

        var param = escape(self._id) + '&l=' + ca.l + '&t=' + ca.t + '&r=' + ca.r + '&b=' + ca.b;
        AjaxSvc.getData('getcatsbyaround', "map/mapsvc.ashx", "method=getcatsbyaround&param=" + param, mvcb);

    };
    this.showinfo = function(_id) {
        var pop = null;
        for (var i = 0; i < self.pops.length; i++) {
            if (self.pops[i].id == _id) {
                pop = self.pops[i];
                break;
            }
        }
        if (pop != null) {
            if (self._id != 'bs') {
                ObjWin.show(pop.x, pop.y, pop.id, pop.name);
            }
            else {
                BusWin.show(pop.x, pop.y, pop.id, pop.name);
            }
        }
    };
    this.setStatus = function(resetFlag) {
        if (resetFlag) {
            self.idx = -1;
            self._id = '-1';
            $('rad_500').checked = true;
        }
        var aa = $('d_aroundLinks').getElementsByTagName("A");
        for (var i = 0; i < aa.length; i++) {
            if (aa[i].id == 'aa_' + self.idx.toString()) {
                aa[i].className = 'on';
                aa[i].style.backgroundImage = 'url(citycomeSkin/default/map/caticons/' + self.icons[i] + ')';
            }
            else {
                aa[i].className = 'off';
                aa[i].style.backgroundImage = 'url(citycomeSkin/default/map/caticons/' + self.icons2[i] + ')';
            }
        }
    };
};
var sa = null;
window.addEvent('domready', function() {
    sa = new SearchAround();
});

(function() {
    var self = this;
    this.cid = '';
    this.idx = -1;
    this.pops = [];
    this.icons = ['gc.gif', 'zs.gif', 'cy.gif', 'yl.gif', 'gw.gif', 'mr.gif', 'yh.gif', 'yd.gif', 'yd.gif', 'jyz.gif'];

    this.ToolBtn = $('aTMapAround');
    this.Pnl = $("ul_aroundList");
    this.links = self.Pnl.getElementsByTagName('A');
    this.links[0].onclick = function() { self.show('bs', 0); };
    this.links[1].onclick = function() { self.show('119', 1); };
    this.links[2].onclick = function() { self.show('118', 2); };
    this.links[3].onclick = function() { self.show('121', 3); };
    this.links[4].onclick = function() { self.show('45', 4); };
    this.links[5].onclick = function() { self.show('38', 5); };
    this.links[6].onclick = function() { self.show('124', 6); };
    this.links[7].onclick = function() { self.show('107', 7); };
    this.links[8].onclick = function() { self.show('47', 8); };
    this.links[9].onclick = function() { self.show('514', 9); };
    this.links[10].onclick = function() { self.show('-1', -1); };
    this.ClearBtn = $('d_ClearMark');

    this.ClearBtn.addEvent('click', function() {
        self.show('-1', -1);
    });

    this.ToolBtn.addEvent('mouseover', function() {
        self.pnlshow(true);
    });
    this.ToolBtn.addEvent('mouseout', function() {
        self.pnlshow(false);
    });
    this.Pnl.addEvent('mouseover', function() {
        self.pnlshow(true);
    });
    this.Pnl.addEvent('mouseout', function() {
        self.pnlshow(false);
    });

    this.pnlshow = function(flag) {
        if (flag) {
            var coor = self.ToolBtn.getCoordinates();
            self.Pnl.style.left = coor.left + 'px';
            self.Pnl.style.top = coor.top + 12 + 'px';
            self.Pnl.style.display = '';
        }
        else {
            self.Pnl.style.display = 'none';
        }
    };

    this.show = function(cid, idx) {
        self.idx = idx;
        self.cid = cid;
        if (cid == 'bs') {
            if (gMap.getZoom() > 3) {
                var ca = gMap.getMapViewport();
                var param = escape(cid) + '&l=' + ca.l + '&t=' + ca.t + '&r=' + ca.r + '&b=' + ca.b;
                AjaxSvc.getData('getcatsbyaround', "map/mapsvc.ashx", "method=getcatsbyaround&param=" + param, self.callback);
            }
            else {
                self.changeZoom();
            }
        }
        else {
            var ca = gMap.getMapViewport();
            //var area = ca.l + ',' + ca.t + ',' + ca.r + ',' + ca.b;
            var area = 0 + ',' + 0 + ',' + 9999999 + ',' + 9999999;
            gApp.showPanel('/map/SearchResult.aspx?area=' + area + '&class=' + cid);
        }
        if (cid == '-1') {
            this.ClearBtn.style.display = 'none';
            sa.morePnl.style.top = '-2000px';
        }
        else {
            this.ClearBtn.style.display = '';
        }
    };
    this.callback = function(res) {
        try {
            eval("var list = " + res);
            self.pops = list;
            gMap.layerMarks.clear();
            for (var i = 0; i < self.pops.length; i++) {
                var o = self.pops[i];
                gMap.layerMarks.add(o.id, 'citycomeSkin/default/map/caticons/' + self.icons[self.idx], o.x, o.y, 25, 29, 13, 29, o.name, function(_id) { self.showinfo(_id); });
            }
        }
        catch (e) { }
    };
    this.showinfo = function(_id) {
        var pop = null;
        for (var i = 0; i < self.pops.length; i++) {
            if (self.pops[i].id == _id) {
                pop = self.pops[i];
                break;
            }
        }
        if (pop != null) {
            if (self.idx != 0) {
                ObjWin.show(pop.x, pop.y, pop.id, pop.name);
            }
            else {
                BusWin.show(pop.x, pop.y, pop.id, pop.name);
            }
        }
    };
    this._timeID = null;
    this.changeZoom = function() {
        self._timeOutID = $clear(self._timeID);
        self._timeID = null;
        gMap.zoomTo(4);
        self._timeOutID = window.setTimeout(function() { self.show(self.cid, self.idx); }, 1000);
    };
})();