///////////////////////////////////////////////////////////////////////////////
var GJnMapTakeOverManager = Class.create();
GJnMapTakeOverManager.prototype = {
    initialize: function() {
    },
    setTakeOver : function (map) {
        //緯度経度ズーム付与
        var lat = '?lat=' + map.getCenter().lat();
        var lon = '&lon=' + map.getCenter().lng();
        var zoom = '&zoomlevel=' + map.getZoom();

		//賃貸需要タブ
		if($('tabneeds') != null) {
	        var newUrl = $('tabneeds').href;
	        if(newUrl.indexOf('?') != -1) {
		        newUrl = newUrl.substr(0, newUrl.indexOf('?'));        
	        }
	        newUrl = newUrl + lat + lon + zoom;
	        $('tabneeds').href = newUrl;
		}

        
		//価格動向タブ        
        if($('tablandprice') != null) {
	        var newUrl = $('tablandprice').href;
	        if(newUrl.indexOf('?') != -1) {
		        newUrl = newUrl.substr(0, newUrl.indexOf('?'));        
	        }
	        newUrl = newUrl + lat + lon + zoom;
	        $('tablandprice').href = newUrl;
        }

		//街の動向タブ        
        if($('tabtown') != null) {
	        var newUrl = $('tabtown').href;
	        if(newUrl.indexOf('?') != -1) {
		        newUrl = newUrl.substr(0, newUrl.indexOf('?'));        
	        }
	        newUrl = newUrl + lat + lon + zoom;
	        $('tabtown').href = newUrl;        
        }
        
        //物件調査タブ
        if($('tabbukken') != null) {
	        var newUrl = $('tabbukken').href;
	        if(newUrl.indexOf('?') != -1) {
		        newUrl = newUrl.substr(0, newUrl.indexOf('?'));        
	        }
	        newUrl = newUrl + lat + lon + zoom;
	        $('tabbukken').href = newUrl;
        }

    }
};
/**
 * 賃貸需要
 * 《ヒートマップの表示 》
 *   ・ZoomLevel : 13～16
 *   ・Data : リラクマデータ
 */
var GJnMapAddrNeedsManager = Class.create();
GJnMapAddrNeedsManager.prototype = {
    initialize: function(map, contFlg, options) {
        this.map = map;
        this.minZoom = 14;
        this.heatMap = null;
        this.manager = new MarkerManager(this.map, {"maxZoom" : 19});
        this.heatmapManager = null;
        this.eventObject = [];
        this.loader = null;
        
        //laoding
        jQuery().ajaxStart(function(){
            if(this.loader == null) {
                var opts = {
                    "image" : "/nextra/static/img/jNextra/gmaps/control/loader.gif",
                    "modal":false,
	                "overlay" :  {"className":'jnxt-gmaps-control-loader-overlay', 
	                				"zIndex":7999, 
	                				"color":'#CCC', 
	                				"opacity":0.3}
                };
                this.loader = new jNextraGMaps2.Control.Loader(opts);
            }
            this.map.addControl(this.loader);
            this.loader.show();
                
        }.bind(this));
        jQuery().ajaxStop(function(){
            if(this.loader != null) {
                this.loader.hide();
            }
        }.bind(this));
        
        Event.observe(window, "load", this._load.bind(this), false);
        GEvent.addListener(this.map, "zoomend", this._takeOver.bind(this));
        jNextraGMaps2.Event.addListener(this.map, "BufferMoveEnd", this._takeOver.bind(this));
        jNextraGMaps2.Event.addListener(this.map, 'LocationChanged', this._locationText.bind(this));
    },
    
    /**
     * 初期表示
     */
    _load : function() {
        //駅プロット
        this._getEkiInfo();
        //ヒートマッププロット
        if(this.heatMap === null) {
            this.heatMap = new GJnHeatMapManager(this.map);
            this.heatMap.show();
        } else {
            this.heatMap.update();
        }
    },
    
    /**
     * location変更時の処理
     * 地図上のセンターの住所を表示する。
     */
    _locationText : function(e, l, location) {
        if(location.getFullAddress() != '') {
            $('addr-name').innerHTML = "<span>" + location.getFullAddress() + "を表示中</span>";
        } else {
            $('addr-name').innerHTML = "<span></span>";
        }
    },
    
    _takeOver : function(param) {
    	takeOver = new GJnMapTakeOverManager();
    	takeOver.setTakeOver(this.map);
        this._getEkiInfo(param);
    },
        
    
    /**
     * Drag及びZoomイベント発生時の各種情報クリア
     */
    _init : function() {
        for(i = 0; i<this.eventObject.length; i++) {
            this.eventObject[i] = null;
        }
        this.eventObject = null;
        this.eventObject = [];
        this.manager.clearMarkers();
    },
    
    /**
     * 駅情報のMarker作成
     */
    _getEkiInfo: function(e) {
        this._init();
        var zLevel = this.map.getZoom();
        if(zLevel < this.minZoom) {
            this.map.clearOverlays();
            return true;
        }
        
        bounds = this.map.getBufferBounds();
        var lat1 = bounds.getSouthWest().lat();
        var lat2 = bounds.getNorthEast().lat();
        var lon1 = bounds.getSouthWest().lng();
        var lon2 = bounds.getNorthEast().lng();
        var baseUri = '/Map/geteki/lat1/' + lat1 + '/lat2/' + lat2 + '/lon1/' + lon1 + '/lon2/' + lon2;
        new Ajax.Request(
            baseUri, {
                method: 'get',
                requestHeaders: ['If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT'],
                onSuccess: function(httpObj) {
                    if(httpObj.responseText == null) {
                        this.loader.hide();                    
                    }
                    eval("var obj=" + httpObj.responseText); 
                    this._setEkiInfo(obj);
                }.bind(this),
                
                onFailure : function(httpObj) {
                    if(this.loader != null) {
                        this.loader.hide();
                    }
                }.bind(this),
                
                onComplete: function(httpObj) { 
                    obj = null;
                }
            }
        );
    },

    /**
     * 駅情報のMarker作成
     */
    _setEkiInfo: function(res) {
        for (i = 0; i < res.length; i++) {
            opt = {
                "image": "/img/owner/city/ico_station.gif",
                "lat": res[i].lat,
                "lon": res[i].lon,
                "width": "24",
                "height": "24",
                "url": '',
                "name": res[i].name,
                "url": res[i].url
            };
            this.manager.addMarker(this._getEkiEvent(i,opt), this.minZoom);
        }
        res = null;
    },
    
    /**
     *駅マーカクリックイベント登録
    */
    _getEkiEvent: function(i, data) {
        var mk = new jNextraGMaps2.Marker.Icon(new GLatLng(data.lat, data.lon), data);
        var eventRet = GEvent.addListener(mk, 'click', function() {
            location.href = data.url;
            return false;
        }.bind(this));
        this.eventObject.push(eventRet);
        
        //tooltip
        eventRet = GEvent.addListener(mk, "mouseover", function(){
            var html = "";
            html += "<div id=\"eki\" class=\"mapbln\">";
            html += "<div class=\"hed\"><p>" + data.name + "駅</p></div>";
            html += "<div class=\"btm\">クリックで詳細表示</div>";
            html += "</div>";
            
            var opts = { "marker" : mk,
                         "width": 300,
                         "autoPosType" : true,
                         "closeBtn" : false
                       };
            this.map.openExtInfoWindow(new GLatLng(data.lat, data.lon), html, opts);
        }.bind(this));
        this.eventObject.push(eventRet);
        
        //tooltip
        eventRet = GEvent.addListener(mk, "mouseout", function(){
            this.map.closeExtInfoWindow();
        }.bind(this));
        this.eventObject.push(eventRet);
        
        return mk;
    },
    
    /**
     * ヒートマップ制御
     */
    _oprHeatMap : function(flg) {
        if(flg) {
            this.heatMap.show();
        } else {
            this.heatMap.hide();        
        }
    }
};
////////////////////////////////////
/**
 * 賃貸管理PJ 市区郡物件調査
 */
/**
 * 物件調査
 * 《賃貸物件の表示 》
 *   ・ZoomLevel : 13～19
 *   ・Data : 賃貸データ
 */
var GJnMapAddrBukkenManager = Class.create();
GJnMapAddrBukkenManager.prototype = {
    initialize: function(map, contFlg, options) {
        this.map = map;
        this.eventObject = [];
        this.manager = new MarkerManager(this.map, {"maxZoom" : 19});
        this.circleObject = null;
        this.markers = [];
        this.contFlg = contFlg;
        this.loader = null;
        this.minZoom = 14;
        
        //event
        Event.observe(window, "load", this._load.bind(this), false);
        jNextraGMaps2.Event.addListener(this.map, "BufferMoveEnd", this._takeOver.bind(this));
        GEvent.addListener(this.map, "zoomend", this._takeOver.bind(this));
        jNextraGMaps2.Event.addListener(this.map, 'LocationChanged', this._locationText.bind(this));
    },
    /**
     * 初期表示
     */
    _load : function() {
        if(this.contFlg == 'eki') {
            for (var tmp in this.markers) {
                this.map.removeOverlay(this.markers[tmp]);
            }
            this.circleObject = new GJnCircleMapManager(this.map, this.markers);
            this.markers = this.circleObject.createCircle(this.map);
        }
        this._getRentInfo();
    },
    
    /**
     * location変更時の処理
     * 地図上のセンターの住所を表示する。
     */
    _locationText : function(e, l, location) {
        if(location.getFullAddress() != '') {
            $('addr-name').innerHTML = "<span>" + location.getFullAddress() + "を表示中</span>";
        } else {
            $('addr-name').innerHTML = "<span></span>";
        }
    },
    
    /**
     * メモリクリア
     */
    _init : function() {
        for(i = 0; i<this.eventObject.length; i++) {
            delete this.eventObject[i];
        }
        this.eventObject = null;
        this.eventObject = [];
        this.map.closeExtInfoWindow();        
        this.manager.clearMarkers();
    },
    
    _takeOver : function(param) {
    	takeOver = new GJnMapTakeOverManager();
    	takeOver.setTakeOver(this.map);
        this._getRentInfo(param);
    },
    
    /**
     * 賃貸物件情報のMarker作成
     */
    _getRentInfo: function(param) {
        this._init();        
        var zLevel = this.map.getZoom();
        if(zLevel < this.minZoom) {
            return true;
        }

        if(this.loader == null) {
            var opts = {
                "image" : "/nextra/static/img/jNextra/gmaps/control/loader.gif",
                "modal":false,
                "overlay" :  {"className":'jnxt-gmaps-control-loader-overlay', 
                				"zIndex":7999, 
                				"color":'#CCC', 
                				"opacity":0.3}
            };
            this.loader = new jNextraGMaps2.Control.Loader(opts);
        }
        this.map.addControl(this.loader);
        this.loader.show();

        var bukkentype = "";
        var list = document.getElementsByAttribute('ozein_brent_info', '*', '*');
        var cnt = 0;
        var btype = new Array();
        for (var i = 0; i < list.length; i++) {
            if (list[i].checked) {
                btype[cnt] = list[i].getAttribute("btype");
                cnt++;
            }
        }
        bukkentype = btype.join(",");
        if(bukkentype == "") {
            return true;
        }
        var zoomPrecision = {
            19 : 0,
            18 : 0,
            17 : 5000,
            16 : 5000,
            15 : 10000,
            14 : 20000
            };
        var lllvData;
        if (typeof zoomPrecision[zLevel] == 'undefined') {
            return true;
        }
        lllvData = zoomPrecision[zLevel];
        var r = this.map.getBounds().getSouthWest().lat() + "," + this.map.getBounds().getSouthWest().lng();
        var l = this.map.getBounds().getNorthEast().lat() + "," +  this.map.getBounds().getNorthEast().lng();

        var geofb = r + ";" + l;
        data = {
            "collections": "BRent",
            "geofb" : geofb,
            "lllv": lllvData
        };
        //チェックボックス指定があればパラメータ付加
        if(bukkentype.length != 0) {
            data.bukkentype = bukkentype;
        }
        jNextra.Facade.Bukken.Maps2(
            data,
            this._setRentInfo, 
            this, 
            null
        );
    },
    
    /**
     * 賃貸物件情報のMarkerイベント作成
     */
    _setRentInfo: function(res) {
        //指定物件タイプでアイコン切り分け
        var btype = null;
        var list = document.getElementsByAttribute('ozein_brent_info', '*', '*');
        for (var i = 0; i < list.length; i++) {
            if (list[i].checked) {
                btype = list[i].getAttribute("ozein_brent_info");
                break;
            }
        }
           var imgName = null;
           switch(btype) {
               case 'bknAll': //全ての物件
                   imgName = "/img/owner/city/ico_bknall.gif";
                   break;
               case 'apart': //アパート
                   imgName = "/img/owner/city/ico_apart.gif";
                   break;
               case 'mansion': //マンション
                   imgName = "/img/owner/city/ico_mansion.gif";
                   break;
               case 'kodate': //一戸建て
                   imgName = "/img/owner/city/ico_kodate.gif";
                   break;
               case 'buil': //ビル
                   imgName = "/img/owner/city/ico_buil.gif";
                   break;
               case 'shop': //店舗
                   imgName = "/img/owner/city/ico_shop.gif";
                   break;
               case 'warehouse': //倉庫
                   imgName = "/img/owner/city/ico_warehouse.gif";
                   break;
               case 'factory': //工場
                   imgName = "/img/owner/city/ico_factory.gif";
                   break;
               case 'parking': //駐車場
                   imgName = "/img/owner/city/ico_parking.gif";
                   break;
               case 'other': //その他
                   imgName = "/img/owner/city/ico_other.gif";
                   break;
               default:
                   imgName = "/img/owner/city/ico_other.gif";
                   break;
           }
        for (i = 0; i < res.ROWSET.length; i++) {
            opt = {
                "image": imgName,
                "lat": res.ROWSET[i].LAT,
                "lon": res.ROWSET[i].LON,
                "width": "24",
                "height": "24",
                "range": res.ROWSET[i].RANGE
            };
            this.manager.addMarker(this._getRentEvent(opt), this.minZoom);
        }
        this.loader.hide();
        res = null;
    },
    
    /**
     *賃貸物件マーカクリックイベント登録
    */
    _getRentEvent: function(data) {
        var mk = new jNextraGMaps2.Marker.Icon(
            new GLatLng(data.lat, data.lon), 
            {
                image : data.image,
                width : data.width,
                height: data.height
            }
        );
        var bukkentype = "";
        var list = document.getElementsByAttribute('ozein_brent_info', '*', '*');
        var cnt = 0;
        var btype = new Array();
        for (var i = 0; i < list.length; i++) {
            if (list[i].checked) {
                btype[cnt] = list[i].getAttribute("btype");
                cnt++;
            }
        }
        bukkentype = btype.join(",");
        var eventRet = GEvent.addListener(mk, 'click', function() {
        
            var nodes = document.getElementsByAttribute('ozein_brent_info', '*', '*');
            for (var i = 0; i< nodes.length; i++) {
                nodes[i].disabled = true;
            }
            
            this.map.closeExtInfoWindow(); 
            this.loader.show();
            var baseUri = '/Map/detail/geofb/' + data.range + '/bukkentype/' + bukkentype;
            new Ajax.Request(
                baseUri, {
                    method: 'get',
                    requestHeaders: ['If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT'],
                    onSuccess: function(o) {
                        html = o.responseText;
                        var opts = { "marker" : mk,
                                     "width": 300,
                                     "autoPosType" : true,
                                     "closeImg" : "/img/owner/mapblnclose.gif",
                                     "closeFlg" : {"frameOutPoint" : true,"zoomChange" : true}
                                   };
                        this.loader.hide();
                        this.map.openExtInfoWindow(mk.getPoint(), html, opts);
                    }.bind(this),
                    
                    onFailure : function(httpObj) {
                        if(this.loader != null) {
                            this.loader.hide();
                        }
                    }.bind(this),
                    
                    onComplete: function(httpObj) { 
                        var nodes = document.getElementsByAttribute('ozein_brent_info', '*', '*');
                        for (var i = 0; i< nodes.length; i++) {
                            nodes[i].disabled = false;
                        }
                        html = null;
                    }
                }
            );
        }.bind(this));
        this.eventObject.push(eventRet);
        return mk;
    }
};
///////////////////////////////////////////////////////////////////////////////
/**
 * 価格調査
 * 《地価公示データの表示 》
 *   ・ZoomLevel : 14以上
 *   ・Data : 地価公示データ
 */
var GJnMapAddrPriceManager = Class.create();
GJnMapAddrPriceManager.prototype = {
    initialize: function(map, contFlg, options) {
        this.minZoom = 14;
        this.map = map;
        this.eventObject = [];
        this.circleObject = null;
        this.markers = [];
        this.manager = new MarkerManager(this.map, {"maxZoom" : 19});
        this.contFlg = contFlg;
        this.loader = null;
        
        //event
        Event.observe(window, "load", this._load.bind(this), false);
        GEvent.addListener(this.map, "zoomend", this._takeOver.bind(this));
        jNextraGMaps2.Event.addListener(this.map, "BufferMoveEnd", this._takeOver.bind(this));
        jNextraGMaps2.Event.addListener(this.map, 'LocationChanged', this._locationText.bind(this));
    },
    
    /**
     * 初期表示
     */
    _load : function() {
        //駅コンテンツの場合同心円情報作成
        if(this.contFlg == 'eki') {
            //同心円削除
            for (var tmp in this.markers) {
                this.map.removeOverlay(this.markers[tmp]);
            }
            this.circleObject = new GJnCircleMapManager(this.map, this.markers);
            this.markers = this.circleObject.createCircle();
        }
        this._getLandPriceInfo();
    },
    
    /**
     * location変更時の処理
     * 地図上のセンターの住所を表示する。
     */
    _locationText : function(e, l, location) {
        if(location.getFullAddress() != '') {
            $('addr-name').innerHTML = "<span>" + location.getFullAddress() + "を表示中</span>";
        } else {
            $('addr-name').innerHTML = "<span></span>";
        }
    },
    _takeOver : function(param) {
    	takeOver = new GJnMapTakeOverManager();
    	takeOver.setTakeOver(this.map);
        this._getLandPriceInfo(param);
    },
    /**
     * 地価公示情報のMarker作成
     */
    _getLandPriceInfo: function(param) {
        //イベント設定クリア
        for(i = 0; i<this.eventObject.length; i++) {
            this.eventObject[i] = null;
        }
        
        this.eventObject = null;
        this.eventObject = [];
        this.map.closeInfoWindow();
        this.manager.clearMarkers();
        
        var zLevel = this.map.getZoom();
        if(zLevel < this.minZoom) {
            return true;
        }
        
        if(this.loader == null) {
            var opts = {
                "image" : "/nextra/static/img/jNextra/gmaps/control/loader.gif",
                "modal":false,
                "overlay" :  {"className":'jnxt-gmaps-control-loader-overlay', 
                				"zIndex":7999, 
                				"color":'#CCC', 
                				"opacity":0.3}
            };
            this.loader = new jNextraGMaps2.Control.Loader(opts);
        }
        this.map.addControl(this.loader);
        this.loader.show();
        
        var lat1 = this.map.getBounds().getSouthWest().lat();
        var lat2 = this.map.getBounds().getNorthEast().lat();
        var lon1 = this.map.getBounds().getSouthWest().lng();
        var lon2 = this.map.getBounds().getNorthEast().lng();
        data = {
            "name" : "land_price_toushi_latlon",
            "lat1": lat1,
            "lat2": lat2,
            "lon1": lon1,
            "lon2": lon2
        };
        var baseUri = '/Map/price/lat1/' + lat1 + '/lat2/' + lat2 + '/lon1/' + lon1 + '/lon2/' + lon2;
        var obj;
        new Ajax.Request(
            baseUri, {
                method: 'get',
                requestHeaders: ['If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT'],
                onSuccess: function(httpObj) {
                    eval("obj=" + httpObj.responseText); 
                    this._setLandPriceInfo(obj);
                }.bind(this),
                
                onFailure : function(httpObj) {
                    if(this.loader != null) {
                        this.loader.hide();
                    }
                }.bind(this),
                
                onComplete: function(httpObj) { 
                    obj = null;
                }
            }
        );
        return true;
    },
    
    /**
     * 地価公示マーカ作成
    */
    _setLandPriceInfo: function(res) {
        for (i = 0; i < res.length; i++) {
            opt = {
                "image": "/img/owner/city/ico_chika.gif",
                "lat": res[i].lat,
                "lon": res[i].lon,
                "width": "24",
                "height": "24",
                "addr" : res[i].addr_str,
                "price" : res[i].price_30,
                "url" : res[i].url
            };
            this.manager.addMarker(this._getLandPriceEvent(opt), this.minZoom);
        }
        this.loader.hide();
    },
    
    /**
     * 地価公示マーカクリックイベント登録
    */
    _getLandPriceEvent: function(data) {
        var eventRet = null;
        var mk = new jNextraGMaps2.Marker.Icon(
            new GLatLng(data.lat, data.lon), 
            {
                image : data.image,
                width : data.width,
                height: data.height
            }
        );
        eventRet = GEvent.addListener(mk, 'click', function() {
                    location.href = data.url;
                    return false;
            }.bind(this));
        this.eventObject.push(eventRet);
        
        //tooltip
        eventRet = GEvent.addListener(mk, "mouseover", function(){
            var html = "";
            html += "<div id=\"chika\" class=\"mapbln\">";
            html += "<div class=\"hed\"><p>地価公示</p>";
            html += "<em>" + data.price + "</em><span>円／m<sup>2</sup></span></div>";
            html += "<div class=\"bdy\">";
            html += "<p>" + data.addr + "</p>";
            html += "</div><!--/bdy-->";
            html += "<div class=\"btm\">クリックで詳細表示</div>";
            html += "</div>";
            var opts = { "marker" : mk,
                         "width": 300,
                         "autoPosType" : true,
                         "closeBtn" : false
                       };
                this.map.openExtInfoWindow(new GLatLng(data.lat, data.lon), html, opts);
            }.bind(this));
        this.eventObject.push(eventRet);
        
        eventRet = GEvent.addListener(mk, "mouseout", function(){
                this.map.closeExtInfoWindow();
            }.bind(this));
        this.eventObject.push(eventRet);
        return mk;
    }
};
///////////////////////////////////////////////////////////////////////////////
/**
 * 街の動向
 * 《ロココム口コミ》
 *   ・ZoomLevel : 14以上
 *   ・Data : ロココムデータ
 * 《周辺施設》
 *   ・ZoomLevel : 14以上
 *   ・Data : ゼンリン施設データ
 */
var GJnMapAddrTownManager = Class.create();
GJnMapAddrTownManager.prototype = {
    initialize: function(map, contFlg, options) {
        this.map = map; //GoogleMap
        this.minZoom = 14; //Minレベル
        this.eventObject = []; //イベント設定オブジェクト
        this.manager = new MarkerManager(map, {"maxZoom" : 19}); //Mapマネージャ(ロココム)
        this.managerTown = new MarkerManager(map, {"maxZoom" : 19}); //Mapマネージャ(施設)
        this.loader = null;
        this.status = null;
        this.centerPosition = null;
        this.lat = null;
        this.lon = null;
        //Event設定
        Event.observe(window, "load", this._getTownInfo.bind(this), false);
        GEvent.addListener(this.map, "zoomend", this._zomeEnd.bind(this));
        jNextraGMaps2.Event.addListener(this.map, "BufferMoveEnd", this._moveEnd.bind(this));
        jNextraGMaps2.Event.addListener(this.map, 'LocationChanged', this._locationText.bind(this));
    },
    _moveEnd : function() {
        var centerPosition = this.map.getCenter();
        var lat = centerPosition.lat();
        var lon = centerPosition.lng();
    	if(lat == this.lat && lon == this.lon) {
    		return;
    	}
    	this._takeOver();
		this._getTownInfo();
    	
    },
    _zomeEnd : function() {
		this._takeOver();
		this._getTownInfo();
    },
    /**
     * 初期表示
     */
    _init : function() {
        for(i = 0; i<this.eventObject.length; i++) {
            this.eventObject[i] = null;
        }
        this.centerPosition = this.map.getCenter();
        this.lat = this.centerPosition.lat();
        this.lon = this.centerPosition.lng();
        
        this.eventObject = null;
        this.eventObject = [];
        this.manager.clearMarkers();
        this.managerTown.clearMarkers();
        this.status = false;
    },
    
    /**
     * ローケーション変更時の住所表示
     */
    _locationText : function(e, l, location) {
        if(location.getFullAddress() != '') {
            $('addr-name').innerHTML = "<span>" + location.getFullAddress() + "を表示中</span>";
        } else {
            $('addr-name').innerHTML = "<span></span>";
        }
    },

    _takeOver : function() {
    	takeOver = new GJnMapTakeOverManager();
    	takeOver.setTakeOver(this.map);
    },
    
    /**
     * データの取得
     */
    _getTownInfo: function(param) {
    
        this._init();
        var zLevel = this.map.getZoom();
        if(zLevel < this.minZoom) {
            return true;
        }
        
        if(this.loader == null) {
            var opts = {
                "image" : "/nextra/static/img/jNextra/gmaps/control/loader.gif",
                "modal":false,
                "overlay" :  {"className":'jnxt-gmaps-control-loader-overlay', 
                				"zIndex":7999, 
                				"color":'#CCC', 
                				"opacity":0.3}
            };
            this.loader = new jNextraGMaps2.Control.Loader(opts);
        }
        this.map.addControl(this.loader);
        this.loader.show();
        
        var center = this.map.getCenter();
        var lat = center.lat();
        var lon = center.lng();
        //口コミ情報取得
        var lat_a = this.map.getBounds().getSouthWest().lat();
        var lat_b = this.map.getBounds().getNorthEast().lat();
        var lon_a = this.map.getBounds().getSouthWest().lng();
        var lon_b = this.map.getBounds().getNorthEast().lng();
        jNextra.Facade.Lococom.Geo(
            {
	            "lat_a": lat_a,
	            "lat_b": lat_b,
	            "lon_a": lon_a,
	            "lon_b": lon_b,
	            "content" : 's'
            },
            this._getLococomInfo, 
            this, 
            null
        );
        //施設情報取得
        var modules = document.getElementsByAttribute('ozein_town_info', '*', '*');
        for (var i = 0; i<modules.length; i++) {
            if(modules[i].checked) {
                jNextra.Facade.Geo.NearFacilityByLatLon(
                    {
                        "lat": lat,
                        "lon": lon,
                        "jnrcpd": modules[i].getAttribute("jnrcpd")
                    },
                    this._setTownInfo, 
                    this, 
                    null
                );
            }
        }
        return true;
    },
    
    /**
     * 施設情報のMarker作成
     */
    _setTownInfo: function(res) {
        if(res.length == 0 ) {
            return false;
        }
           //アイコンの切り分け
           var imgName = null;
           switch(res[0].GENREMENUCODE + res[0].GENRECODE) {
               case '0011000110': //コインパーキング
                   imgName = "/nextra/static/img/jNextra/gmaps/marker/icon/facility/icon_15.gif";
                   break;
               case '0014000170': //スーパー
                   imgName = "/nextra/static/img/jNextra/gmaps/marker/icon/facility/icon_02.gif";
                   break;
               case '0014000180': //コンビニ
                   imgName = "/nextra/static/img/jNextra/gmaps/marker/icon/facility/icon_03.gif";
                   break;
               case '0014000230': //ドラッグストア
                   imgName = "/nextra/static/img/jNextra/gmaps/marker/icon/facility/icon_04.gif";
                   break;
               case '0014000110': //デパート
                   imgName = "/nextra/static/img/jNextra/gmaps/marker/icon/facility/icon_14.gif";
                   break;
               case '0017000110': //銀行
                   imgName = "/nextra/static/img/jNextra/gmaps/marker/icon/facility/icon_07.gif";
                   break;
               case '0017000130': //郵便局
                   imgName = "/nextra/static/img/jNextra/gmaps/marker/icon/facility/icon_08.gif";
                   break;
               case '0016000110': //病院
                   imgName = "/nextra/static/img/jNextra/gmaps/marker/icon/facility/icon_06.gif";
                   break;
               case '0014000250': //レンタルビデオ
                   imgName = "/nextra/static/img/jNextra/gmaps/marker/icon/facility/icon_05.gif";
                   break;
               case '0012000140': //公園
                   imgName = "/nextra/static/img/jNextra/gmaps/marker/icon/facility/icon_01.gif";
                   break;
               case '0025000170': //幼稚園・保育園
                   imgName = "/nextra/static/img/jNextra/gmaps/marker/icon/facility/icon_12.gif";
                   break;
               case '0022000150': //図書館
                   imgName = "/nextra/static/img/jNextra/gmaps/marker/icon/facility/icon_13.gif";
                   break;
               default: //学校
                   imgName = "/nextra/static/img/jNextra/gmaps/marker/icon/facility/icon_11.gif";
                   break;
           }
           
        for (i = 0; i < res.length; i++) {
            opt = {
                "image": imgName,
                "lat": res[i].LAT,
                "lon": res[i].LON,
                "width": "24",
                "height": "24",
                "title": res[i].NAME
            };
            mk = this._getTownEvent(opt);
            this.managerTown.addMarker(mk,this.minZoom);
        }
        return true;
    },
    
    /**
     * 施設情報イベント設定
     */
    _getTownEvent: function(data) {
        var eventRet = null;
        var mk = new jNextraGMaps2.Marker.Icon(new GLatLng(data.lat, data.lon), data);
        
        //tooltip
        eventRet = GEvent.addListener(mk, "mouseover", function(){
        
            var html = "<div id=\"facility\" class=\"mapbln\">" ;
            html += "<div class=\"hed\">";
            html += "<p>";
            html += data.title;
            html += "</p></div></div><!--/facility-->";
            var opts = { "marker" : mk,
                         "width": 300,
                         "autoPosType" : true,
                         "closeBtn" : false
                       };
            this.map.openExtInfoWindow(new GLatLng(data.lat, data.lon), html, opts);
        }.bind(this));
        this.eventObject.push(eventRet);
        
        eventRet = GEvent.addListener(mk, "mouseout", function(){
           this.map.closeExtInfoWindow();
        }.bind(this));
        this.eventObject.push(eventRet);
        return mk;
    },
    
    /**
     * ロココムのMarker作成
     */
    _getLococomInfo: function(res) {
        if(res.length == 0 ) {
            this.loader.hide();
            return false;
        }
        //口コミ情報の取得
        for (i = 0; i < res.length; i++) {
            opt = {
                "image": "/img/owner/city/ico_kuchikomi.png",
                "lat": res[i].LAT,
                "lon": res[i].LON,
                "width": "25",
                "height": "25",
                "url": res[i].TITLEURL,
                "content": res[i].CONTENT,
                "title": res[i].TITLE
            };
            mk = this._getLococomEvent(opt);
            this.manager.addMarker(mk, this.minZoom);
        }
        this.loader.hide();
        return true;
    },
    
    /**
     * ロココムのMarker作成
     */
    _getLococomEvent: function(data) {
        var eventRet = null;
        var mk = new jNextraGMaps2.Marker.Icon(new GLatLng(data.lat, data.lon), data);
        eventRet = GEvent.addListener(mk, 'click', function() {
            html = "<div id=\"kuchikomi\" class=\"mapbln\">" ;
            html += "<div class=\"hed\">";
            html += "<p>口コミ情報</p></div>";
            html += "<div class=\"bdy\"><ul><li><dl>";
            html += "<dt><a href=\"" + data.url + "\" target=\"_blank\">" + data.title + "</a></dt>";
            var content = null;
            (data.content != null)? content=data.content : content="";
            (content.length == 100)? content=content+'...' : content=content;
            html += "<dd>" + content + "</dd>";
            html += "</dl></li></ul></div><!--/bdy--></div>";
            
            var opts = { "marker" : mk,
                         "width": 300,
                         "autoPosType" : true,
                         "closeImg" : "/img/owner/mapblnclose.gif",
                         "closeFlg" : {"frameOutPoint" : true,"zoomChange" : true}
                       };
            this.map.openExtInfoWindow(mk.getPoint(), html, opts);
            return false;
        }.bind(this));
        this.eventObject.push(eventRet);
        return mk;
    }
};
///////////////////////////////////////////////////////////////////////////////
/**
 * 駅ページ（賃貸需要）画面
 * 《ヒートマップの表示 》
 *   ・ZoomLevel : 13～16
 *   ・Data : リラクマデータ
 *《同心円の表示》
 *   ・ZoomLevel : 15～18
 */
var GJnMapStationNeedsManager = Class.create();
GJnMapStationNeedsManager.prototype = {
    initialize: function(map, contFlg, options) {
        this.map = map; //Google Map
        this.heatMap = null; //HeatMap
        this.minZoom = 15; //Min Level
        this.markers = []; //同心円保存配列
        this.loader = null;
        //laoding
        jQuery().ajaxStart(function(){
            if(this.loader == null) {
                var opts = {
                    "image" : "/nextra/static/img/jNextra/gmaps/control/loader.gif",
                    "modal":false,
	                "overlay" :  {"className":'jnxt-gmaps-control-loader-overlay', 
	                				"zIndex":7999, 
	                				"color":'#CCC', 
	                				"opacity":0.3}
                };
                this.loader = new jNextraGMaps2.Control.Loader(opts);
            }
            this.map.addControl(this.loader);
            this.loader.show();
                
        }.bind(this));
        jQuery().ajaxStop(function(){
            if(this.loader != null) {
                this.loader.hide();
            }
        }.bind(this));
        
        //Event設定
        Event.observe(window, "load", this._load.bind(this), false);
        jNextraGMaps2.Event.addListener(this.map, 'LocationChanged', this._locationText.bind(this));
    },
    
    /**
     * 初期表示
     */
    _load : function() {
        //同心円プロット
        this._setCircle();
        
        //ヒートマッププロット
        if(this.heatMap === null) {
            this.heatMap = new GJnHeatMapManager(this.map);
            this.heatMap.show();
        } else {
            this.heatMap.update();
        }
    },
    
    /**
     * ローケーション変更時の住所表示
     */
    _locationText : function(e, l, location) {
        if(location.getFullAddress() != '') {
            $('addr-name').innerHTML = "<span>" + location.getFullAddress() + "を表示中</span>";
        } else {
            $('addr-name').innerHTML = "<span></span>";
        }
        this._takeOver();
    },

    _takeOver : function(param) {
    	takeOver = new GJnMapTakeOverManager();
    	takeOver.setTakeOver(this.map);
    },
    
    /**
     * 同心円情報のクリア
     */
    _clearCircle : function() {
        for (var tmp in this.markers) {
            this.map.removeOverlay(this.markers[tmp]);
        }
        return;
    },
    
    /**
     * 同心円情報の作成
     */
    _setCircle: function(param) {
        this._clearCircle();
        this.circleObject = new GJnCircleMapManager(this.map, this.markers);
        this.markers = this.circleObject.createCircle();
        
        return true;
    },
    
    /**
     * ヒートマップ制御
     */
    _oprHeatMap : function(flg) {
        if(flg) {
            this.heatMap.show();
        } else {
            this.heatMap.hide();        
        }
    }
};
///////////////////////////////////////////////////////////////////////////////
/**
 * 町村番地ページ
 * 中心データはデフォルトのバルーンを表示。
 *《地価公示データの表示》
 *   ・ZoomLevel : 14以上
 */
var GJnMapAddrLandManager = Class.create();
GJnMapAddrLandManager.prototype = {
    initialize: function(map, contFlg, options) {
        this.map = map; //GoogleMap
        this.minZoom = 14; //Minレベル
        this.eventObject = []; //Event設定オブジェクト
        this.managerDefault = new MarkerManager(this.map, {"maxZoom" : 19}); //Mapマネージャ
        this.manager = new MarkerManager(this.map, {"maxZoom" : 19}); //Mapマネージャ
        this.loader = null;
        this.defaultId = null;
        //Event設定
        Event.observe(window, "load", this._load.bind(this), false);
        GEvent.addListener(this.map, "zoomend", this._getLandInfo.bind(this));
        jNextraGMaps2.Event.addListener(this.map, 'LocationChanged', this._locationText.bind(this));
    },
    
    /**
     * 初期表示
     */
    _load: function() {
        this._getLandInfo(true);
    },
    
    /**
     * 各種メモリクリア
     */
    _init: function() {
        for(i = 0; i<this.eventObject.length; i++) {
            this.eventObject[i] = null;
        }
        this.eventObject = null;
        this.eventObject = [];
        this.manager.clearMarkers();
    },
    
    /**
     * ローケーション変更時の住所表示
     */
    _locationText : function(e, l, location) {
        if(location.getFullAddress() != '') {
            $('addr-name').innerHTML = "<span>" + location.getFullAddress() + "を表示中</span>";
        } else {
            $('addr-name').innerHTML = "<span></span>";
        }
        this._getLandInfo(false);
    },
    
    /**
     * 地価公示情報のMarker作成
     */
    _getLandInfo: function(initFlg) {
        
        this._init();
        var zLevel = this.map.getZoom();
        if(zLevel < this.minZoom) {
            return true;
        }
        
        if(this.loader == null) {
            var opts = {
                "image" : "/nextra/static/img/jNextra/gmaps/control/loader.gif",
                "modal":false,
                "overlay" :  {"className":'jnxt-gmaps-control-loader-overlay', 
                				"zIndex":7999, 
                				"color":'#CCC', 
                				"opacity":0.3}
            };
            this.loader = new jNextraGMaps2.Control.Loader(opts);
        }
        this.map.addControl(this.loader);
        this.loader.show();

        var center = this.map.getCenter();
        var lat = center.lat();
        var lon = center.lng();
        //各地価公示データの取得
        var lat1 = this.map.getBounds().getSouthWest().lat();
        var lat2 = this.map.getBounds().getNorthEast().lat();
        var lon1 = this.map.getBounds().getSouthWest().lng();
        var lon2 = this.map.getBounds().getNorthEast().lng();
        var baseUri = '/Map/price/lat1/' + lat1 + '/lat2/' + lat2 + '/lon1/' + lon1 + '/lon2/' + lon2;
        var obj;
        new Ajax.Request(
            baseUri, {
                method: 'get',
                requestHeaders: ['If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT'],
                onSuccess: function(httpObj) {
                    eval("obj=" + httpObj.responseText);
                    this._setLandPriceInfo(obj);
                }.bind(this),
                
                onFailure : function(httpObj) {
                    if(this.loader != null) {
                        this.loader.hide();
                    }
                }.bind(this),
                
                onComplete: function(httpObj) { 
                    obj = null;
                }
                
            }
        );
        //initialの場合はデフォルトマーカをプロット
        if (initFlg) {
            var data = {
                "name" : "land_price_toushi_center",
                "lat": lat,
                "lon": lon
            };
            
            jNextra.Facade.RegInfo.Stat(
                data,
                this._setDefaultBal, 
                this, 
                null
            );
        }
    },
    
    /**
     * 初期表示時のデフォルトバルーン作成
    */
    _setDefaultBal: function(res) {
        for (i = 0; i < res.length; i++) {
            opt = {
                "id" : res[i].id,
                "image": "/img/owner/city/ico_chika_atv.gif",
                "lat": res[i].lat,
                "lon": res[i].lon,
                "width": "28",
                "height": "28",
                "addr" : res[i].addr_str,
                "price" : res[i].price_30
            };
            var mk = new jNextraGMaps2.Marker.Icon(new GLatLng(opt.lat, opt.lon), opt);
            
            var html = "";
            html += "<div id=\"chikaDtl\" class=\"mapbln\">";
            html += "<div class=\"hed\"><p>地価公示</p>";
            html += "<em>" + opt.price + "</em><span>円／m<sup>2</sup></span></div>";
            html += "<div class=\"bdy\">";
            html += "<p>" + opt.addr + "</p>";
            html += "<ul>";
            html += "<li><a onclick=\"return (function(){new Effect.ScrollTo('gaChikaChart');return false;})();\" href=\"#\">地価公示の推移</a></li>";
            html += "<li><a onclick=\"return (function(){new Effect.ScrollTo('gaLandInfo');return false;})();\" href=\"#\">この土地の情報</a></li>";
            html += "</ul>";            
            html += "</div><!--/bdy-->";
            html += "</div>";
            var opts = { "marker" : mk,
                         "width": 300,
                         "autoPosType" : false,
                         "posType" : "U",
                         "closeImg" : "/img/owner/mapblnclose.gif",
                         "closeBtn" : true,
                         "closeFlg" : {"frameOutPoint" : true,"zoomChange" : true}
                       };
            this.map.openExtInfoWindow(mk.getPoint(), html, opts);
            this.managerDefault.addMarker(mk, this.minZoom);
            
            this.defaultId = res[i].id;
        }
    },
    
    /**
     * 各地価公示マーカのデータ作成
    */
   _setLandPriceInfo: function(res) {
        for (i = 0; i < res.length; i++) {
            if(res[i].id != this.defaultId) {
            opt = {
                "image": "/img/owner/city/ico_chika.gif",
                "lat": res[i].lat,
                "lon": res[i].lon,
                "width": "24",
                "height": "24",
                "addr" : res[i].addr_str,
                "price" : res[i].price_30,
                "url" : res[i].url
            };
            this.manager.addMarker(this._getLandPriceEvent(opt), this.minZoom);
            }
        }
        this.loader.hide();
    },
    
    /**
     * 地価公示マーカクリックイベント登録
    */
    _getLandPriceEvent: function(data) {
        var eventRet = null;
        
        var mk = new jNextraGMaps2.Marker.Icon(
            new GLatLng(data.lat, data.lon), 
            {
                image : data.image,
                width : data.width,
                height: data.height
            }
        );
        eventRet = GEvent.addListener(mk, 'click', function() {
            location.href = data.url;
            return false;
        }.bind(this));
        this.eventObject.push(eventRet);
        
        //tooltip
        eventRet = GEvent.addListener(mk, "mouseover", function(){
            var html = "";
            html += "<div id=\"chika\" class=\"mapbln\">";
            html += "<div class=\"hed\"><p>地価公示</p>";
            html += "<em>" + data.price + "</em><span>円／m<sup>2</sup></span></div>";
            html += "<div class=\"bdy\">";
            html += "<p>" + data.addr + "</p>";
            html += "</div><!--/bdy-->";
            html += "<div class=\"btm\">クリックで詳細表示</div>";
            html += "</div>";
            var opts = { "marker" : mk,
                         "width": 300,
                         "autoPosType" : true,
                         "closeBtn" : false
                       };
            this.map.openExtInfoWindow(new GLatLng(data.lat, data.lon), html,opts);
        }.bind(this));
        this.eventObject.push(eventRet);
        
        eventRet = GEvent.addListener(mk, "mouseout", function(){
            this.map.closeExtInfoWindow();
        }.bind(this));
        this.eventObject.push(eventRet);
        
        return mk;
    }
};

///////////////////////////////////////////////////////////////////////////////
/**
 * 街の動向 チェックボックスイベント監視クラス
 */
Ozein.JnMapTownManager = new Class.create();
Ozein.JnMapTownManager.prototype = {
    initialize: function(node) {
    	this.current = null;
        var modules = this._getModule(node);
        for (var i = 0; i<modules.length; i++) {
            Event.observe(modules[i], 'click', this._getTownInfo.bindAsEventListener(this, modules[i]));
        }
    },
    
    _getModule : function (baseNode) {
        return document.getElementsByAttribute('ozein_town_info', '*', '*');
    },
    
    /**
    * GJnMapAddrTownManagerのメソッドを利用。
    * よって、上記クラスを別途インスタンス必要
    * 同一IDの場合は検索を実行しない
    */
    _getTownInfo : function(e, node) {
		if(this.current == node.id) {
			return;
		}
		this.current = node.id
        g._getTownInfo(false, null);
    }
};

///////////////////////////////////////////////////////////////////////////////
/**
 * 物件調査画面
*/
Ozein.JnMapBRentManager = new Class.create();
Ozein.JnMapBRentManager.prototype = {
    initialize: function(node) {
    	this.current = null;
        var modules = this._getModule(node);
        //チェックボックスイベント監視
        for (var i = 0; i<modules.length; i++) {
            Event.observe(modules[i], 'click', this._getBRentInfo.bindAsEventListener(this, modules[i]));
        }
    },
    
    /**
     * 対象ノードの取得
     */    
    _getModule : function (baseNode) {
        return document.getElementsByAttribute('ozein_brent_info', '*', '*');
    },
    
    /**
     * 賃貸物件情報の取得
     * 同一IDの場合は検索を実行しない
     */
    _getBRentInfo : function(e, node) {
		if(this.current == node.id) {
			return;
		}
		this.current = node.id
        g._getRentInfo(null);
    }
};
///////////////////////////////////////////////////////////////////////////////
/**
 * GoogleMapsを初期表示位置へ戻す
 */
Ozein.MapPositionManager = new Class.create();
Ozein.MapPositionManager.prototype = {
    initialize: function(node) {
        var modules = this._getModule(node);
        for (var i = 0; i<modules.length; i++) {
            Event.observe(modules[i], 'click', this._moveSavedPosition.bindAsEventListener(this, modules[i]));
        }
    },
    
    _getModule : function (baseNode) {
        return document.getElementsByAttribute('ozein_map_position', '*', '*');
    },
        
    _moveSavedPosition : function(e, url) {
        g.map.returnToSavedPosition();
        return true;
    }
};