    var map;
	var center;
	var zoom;
	var ctrl;
	var school_geo;
	var markers = [];
	var default_estate_code;

	var get_value = new Array();
	function getValue() {
		var query = window.location.search.substring(1);
		var parms = query.split('&');
		for (var i=0; i<parms.length; i++) {
			var pos = parms[i].indexOf('=');
			if (pos > 0) {
				var key = parms[i].substring(0,pos);
				var val = parms[i].substring(pos+1);
//				get_value[key] = val;
				get_value[i] = key;
			}
		}
		return get_value;
	}
	getValue();


    function load(default_lan,default_lon, school_id, school_zoom) {
    	alert(aaa);
    	if (GBrowserIsCompatible()) {
    		
    	if(!school_zoom){
    		school_zoom = 13;
    	}

    	map = new GMap2(document.getElementById("map"));

        map.addControl(new GSmallMapControl());

        center = new GLatLng(default_lan, default_lon);
        map.setCenter(center, school_zoom);

		school_geo = center;
		loadobjects();

		// ドラッグ＆ドロップ時の動作
        GEvent.addListener(map, "dragend", function() {
			loadobjects();
        });
		// ドラッグ＆ドロップ時の動作
        GEvent.addListener(map, "zoomend", function() {
			loadobjects();
        });
      }
    }


	function loadobjects(){
//		document.getElementById("map").style.display = "none";

		document.getElementById("maploading").style.display = "block";

		center = map.getCenter();

		url = window.location.href;
		var estates = map_ajax.getNearEstate(center.x, center.y, map.getZoom(), get_value, url);

//document.write(estates[1000]["debug"]);
//alert(estates[0]["debug"]);
//d(estates);

		var points = [];
		var line;

		map.clearOverlays();

//		var gschool = map_ajax.getSchool(school_id);

		// 学校アイコンを表示
		var meta = [];
		meta["icon"]  = "school.png";
		meta["color"] = "FF0000";
		meta["width"] = "50";
		meta["height"]= "77";
//		meta["html"]  = school["school_name"];
		map.addOverlay(createMarker(school_geo, meta));

		var estate_icon_size = [];
		estate_icon_size[18] = 37;
		estate_icon_size[17] = 37;
		estate_icon_size[16] = 37;
		estate_icon_size[15] = 30;
		estate_icon_size[14] = 25;
		estate_icon_size[13] = 18;
		estate_icon_size[12] = 10;
		estate_icon_size[11] = 8;
		estate_icon_size[10] = 6;
		estate_icon_size[9]  = 4;
		estate_icon_size[8]  = 4;
		estate_icon_size[7]  = 4;
		estate_icon_size[6]  = 4;

		for (key in estates) {
			var meta = [];

			if (estates[key]["estate_glat"] && estates[key]["estate_glng"]) {
				points[key] = new GLatLng(estates[key]["estate_glat"], estates[key]["estate_glng"]);

				// 物件アイコンを表示
				if(estates[key]["estate_type"] == "学生会館"){
					meta["icon"]  = "orange.png";
				}else{
					meta["icon"]  = "red.png";
				}
				meta["color"] = "FF0000";
				meta["width"] = estate_icon_size[map.getZoom()];
				meta["height"] = estate_icon_size[map.getZoom()];
//				meta["html"]  = '<table><tr><td><img src="/share/img/photos/' + estates[key]["estate_code"] + '_a_1.jpg" /></td><td><td>&nbsp;</td><a href="/estate/' + estates[key]["estate_code"] + '">' + estates[key]["estate_name"] + '</a><br />' + estates[key]["estate_house_rent_freespace"] + '<br />' + estates[key]["photo_title"] + '</td></tr></table>';

				link_url = "/estate/" + estates[key]["estate_code"];
				if(estates[key]["photo_exists"]){
//					var html = '<table><tr><td><img src="/share/img/estate_photos/' + estates[key]["estate_code"] + '_a_1.jpg" width="160" height="119" /></td><td>&nbsp;</td><td><a href="/estate/' + estates[key]["estate_code"] + '">' + estates[key]["estate_name"] + '</a></td></tr></table>';
//					var html = '<table border="0"><tr><td><img src="/share/img/estate_photos/' + estates[key]["estate_code"] + '_a_1.jpg" width="160" height="119" /></td><td>&nbsp;</td><td><a href="javascript:changeUrl(\'' + link_url + '\')"><span style="font-size: 10px; line-height: 25px;">' + estates[key]["estate_name"] + '</span><br /><span style="font-size: 12px;">' + estates[key]["koutu"] + '<br />家賃： ' + estates[key]["estate_house_rent_min"] + '円 ～ ' + estates[key]["estate_house_rent_max"] + '円</a></span></td></tr></table>';
					var html = '<div style="float: left;"><img src="/share/img/estate_photos/' + estates[key]["estate_code"] + '_a_1.jpg" width="160" height="119" /></div><div style="float: left; height: 119px; margin-left: 10px; border: 0px solid red;"><br /><a href="javascript:changeUrl(\'' + link_url + '\')"><span style="font-size: 10px; line-height: 25px;">' + estates[key]["estate_name"] + '</span><br /><span style="font-size: 12px;">' + estates[key]["koutu"] + '<br />家賃： ' + estates[key]["estate_house_rent_min"] + '円 ～ ' + estates[key]["estate_house_rent_max"] + '円</a></span></div><div style="clear: both;"></div>';

//					html = '<table border="1" width="300" style="width: 300px;">  <tr>  <td width="100" style="width: 100px;">111</td>  <td>222</td>  <td width="100" style="width: 100px;">333</td>  </tr>  </table>';

				}else{
//					var html = '<table><tr><td>&nbsp;</td><td><a href="/estate/' + estates[key]["estate_code"] + '">' + estates[key]["estate_name"] + '</a></td></tr></table>';	
					var html = '<table><tr><td>&nbsp;</td><td><a href="javascript:changeUrl(\'' + link_url + '\')"><span style="font-size: 10px; line-height: 25px;">' + estates[key]["estate_name"] + '</span><br /><span style="font-size: 12px;">' + estates[key]["koutu"] + '<br />家賃： ' + estates[key]["estate_house_rent_min"] + '円 ～ ' + estates[key]["estate_house_rent_max"] + '円</a></span></td></tr></table>';
				}
				
				meta["html"]  = html;
				markers[estates[key]["estate_code"]] = createMarker(points[key], meta);
				map.addOverlay(markers[estates[key]["estate_code"]]);
				
				if(markers[default_estate_code]){
					markers[default_estate_code].openInfoWindow(meta["html"]);
				}
			
			}
		}

		document.getElementById("maploading").style.display = "none";


	}

	function createMarker(points, meta){
		var icon = new GIcon();

		icon.image = "/share/img/maps/icon/" + meta["icon"];
		//icon.image = "/img/maps/icon/c_" + meta["color"] + ".png";

		if(meta["width"] && meta["height"]){
			icon.iconSize = new GSize(meta["height"], meta["width"]);
		}

		icon.iconAnchor = new GPoint(0, 0);
		icon.infoWindowAnchor = new GPoint(10, 10);

		var marker = new GMarker(points, icon);

		if (meta["html"]) {
			GEvent.addListener(marker, "mouseover", function(){
				marker.openInfoWindowHtml(meta["html"]);
			});
			GEvent.addListener(marker, "mouseout", function(){
				setTimeout(function(){ marker.closeInfoWindow() }, 3000);	
			});			
		}
		return marker;
	}


	// 拡大・縮小のボタン
	function TextualZoomControl() {}
	TextualZoomControl.prototype = new GControl();

	TextualZoomControl.prototype.initialize = function(map) {
		var container = document.createElement("div");

	if (map.getZoom() < 16) {
		var zoomInImg = document.createElement("img");
		zoomInImg.src = "/share/img/maps/icon/zoom-in.png"
		container.appendChild(zoomInImg);
		GEvent.addDomListener(zoomInImg, "click", function(){
			map.zoomIn();
		});
	}

	if (map.getZoom() > 12) {
		var zoomOutImg = document.createElement("img");
		zoomOutImg.src = "/share/img/maps/icon/zoom-out.png"
		container.appendChild(zoomOutImg);
		GEvent.addDomListener(zoomOutImg, "click", function(){
			map.zoomOut();
		});
	}
	  map.getContainer().appendChild(container);
	  return container;
	}

	TextualZoomControl.prototype.getDefaultPosition = function() {
	  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
	}

	function searchMap(address){

		if(!address){
			alert('キーワードを入力してください。');
			return false;
		}

		geocoder = new GClientGeocoder();

		geocoder.getLatLng(
			address,
			function(point){
				if(!point){
					alert(address +" \u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002");
	            }
				else{
        			map.setCenter(point, 14);
					loadobjects();
	            }
        	}
		);
	}

function checkParentUrl(){
	window.onerror = function(arg1,arg2,arg3){
		return true;
	}
	if(window.opener != null){
		currentUrl = location.href.replace('detail=1&','');	
		parentUrl = window.opener.location.href.replace('#','');
		newUrl = "http://" + window.opener.location.hostname + window.opener.location.pathname + window.opener.location.search;
		newUrl = newUrl.replace('?','?detail=1&');
		if(currentUrl != parentUrl){
			if(newUrl.indexOf("/estate/s") != -1){
				location.href = newUrl;
			}
		}
	}
}

// 地図のウィンドウから親ウィンドウをチェック
if(location.href.indexOf("?detail=1") != -1){
	setInterval("checkParentUrl()",1000);	
}

