    var map;
    var marker_list = [];

    function load(estate_id, zoom) {
     	var photo_name = Array("j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","aa","ab","ac");    	

    	if (GBrowserIsCompatible()) {
    		
    		var town_map = map_ajax.getTownAccess(estate_id);

			var estate = map_ajax.getEstateGeo(estate_id);
			center = new GLatLng(estate["estate_glat"], estate["estate_glng"]);	
	    	map = new GMap2(document.getElementById("map"));
	        map.setCenter(center, zoom);
	        map.addControl(new GSmallMapControl());

	        map.addOverlay(createMarkerEstate(new GLatLng(estate["estate_glat"], estate["estate_glng"])));
	        for (key in town_map) {

	        	for (i=1; i<=20; i++) {
//document.getElementById("debug").value += i + " ";

//	        		if(town_map[key]["estate_syuhen_lat_" + i]){
			        	photo_index = i - 1;
						points = [];
						meta = [];
						
						if(town_map[key]["estate_syuhen_name_" + i]){
						
							if(town_map[key]["estate_syuhen_lat_" + i] != ""){
								points[i] = new GLatLng(town_map[key]["estate_syuhen_lat_" + i], town_map[key]["estate_syuhen_lng_" + i]);	
							}else{
								points[i] = new GLatLng(town_map[key]["estate_glat"], town_map[key]["estate_glng"]);
							}

							j = i - 1;
							if(town_map[key]["estate_syuhen_photo_" + photo_name[j]]){
//								meta["html"] = town_map[key]["estate_syuhen_photo_" + photo_name[j]] + town_map[key]["estate_syuhen_path_" + photo_name[i]] + "<div style='font-size:14px'>" + '<img src="/share/img/estate_photos/' + town_map[0]["estate_code"] + '_' + photo_name[photo_index] + '.jpg" /><br /><center>' + town_map[key]["estate_syuhen_name_" + i] + "</center></div>";
								meta["html"] = "<div style='font-size:14px'>" + '<img src="/share/img/estate_photos/' + town_map[0]["estate_code"] + '_' + photo_name[photo_index] + '.jpg" width="300" height="227" /><br /><center>' + town_map[key]["estate_syuhen_name_" + i] + "</center></div>";
							}else{
//								meta["html"] = town_map[key]["estate_syuhen_photo_" + photo_name[j]] + town_map[key]["estate_syuhen_path_" + photo_name[j]] + "<div style='font-size:14px'>" + '<img src="/share/img/estate_photos/' + town_map[0]["estate_code"] + '_' + photo_name[photo_index] + '.jpg" /><br /><center>' + town_map[key]["estate_syuhen_name_" + i] + "</center></div>";
								meta["html"] = "<br /><div style='font-size:14px'>" + '<center>' + town_map[key]["estate_syuhen_name_" + i] + "</center></div>";	
							}

							meta["id"]   = i;
	
							if(town_map[key]["estate_syuhen_name_" + i] != "") {
	//document.getElementById("debug").value += key + " ";
	
								map.addOverlay(createMarker(points[i], meta));
							}
						}
//	        		}
	        	}
	        }
    	}
    }

    
    function getPass(){
    	var from = document.getElementById('pass_from').value;
    	var to   = document.getElementById('pass_to').value;
    	var span = document.getElementById('pass_span').value;
    	var html = pass.getPass(from, to, span);

    	if(html){
        	document.getElementById('pass_html').innerHTML = html;
    	}else{
    		alert('ルートが見つかりませんでした。別の名称で再度検索してください。');
    	}
    }

    
	function createMarker(points, meta){

		var icon = new GIcon();
		icon.image = "/share/img/maps/icon/icon_red_" +  meta["id"] + ".gif";
		icon.iconSize = new GSize(20, 20);
		icon.iconAnchor = new GPoint(7, 7);
		icon.infoWindowAnchor = new GPoint(10, 10);
		var marker = new GMarker(points, icon);
		marker_list.push(marker);

		//alert(marker);
		if (meta["html"]!="") {
			GEvent.addListener(marker, "mouseover", function(){
				marker.openInfoWindowHtml(meta["html"]);
			});
			GEvent.addListener(marker, "mouseout", function(){
				setTimeout(function(){ marker.closeInfoWindow() }, 3000);	
			});			
		}

/*		GEvent.addListener(marker, "mouseout", function(){
			_sleep(1000);
			marker.closeInfoWindow();
		});*/
		
//		document.getElementById("debug").value = meta["html"];
		return marker;
	}


	function openWindow(index){
		GEvent.trigger(marker_list[index], "mouseover");
//		document.getElementById("debug").value = marker_list[index];
	}


	function createMarkerEstate(points){
		var icon = new GIcon();

		icon.image = "/share/img/maps/icon/red.png";
//		icon.iconSize = new GSize(20, 20);
		icon.iconAnchor = new GPoint(20, 20);
		icon.infoWindowAnchor = new GPoint(10, 10);
		var marker = new GMarker(points, icon);

/*		if (meta["html"]!="") {
			GEvent.addListener(marker, "click", function(){
				marker.openInfoWindowHtml(meta["html"]);
			});
		}*/
		return marker;
	}
	
	function _sleep(time){

		var d1 = new Date().getTime();

		var d2 = new Date().getTime();

		while( d2 < d1 + time ){

		d2=new Date().getTime();

		}

		return; 

	}
