	// show shops on map
	var mymap = 'viewmap_index';
	var map = null;
	var mapbounds = new GLatLngBounds(new GLatLng(36.94, 106.08));
	var markers = [];
	var current_marker = null;
	var geocoder = null;
    
	function map_show_info(i)
	{
		if(current_marker !== i)
		{
			if(current_marker !== null) 
			{
				document.getElementById("div_map_" + markers[current_marker][2]).style.border = "";
				document.getElementById("div_map_" + markers[current_marker][2]).getElementsByTagName("a")[0].style.color = "#000000";
				document.getElementById("div_map_" + markers[current_marker][2]).style.backgroundColor = "#ffffff";
			}
			document.getElementById("div_map_" + markers[i][2]).style.border = "";
			document.getElementById("div_map_" + markers[i][2]).getElementsByTagName("a")[0].style.color = "#006699";
			document.getElementById("div_map_" + markers[i][2]).style.backgroundColor = "#E0E0E0";
			markers[i][0].openInfoWindowHtml(markers[i][1], {"maxWidth": 450}); 
			current_marker = i;
		}
	}

	function map_zoom_in(i)
	{
		map.setCenter(markers[i][0].getPoint(), 16);
	}

	function map_zoom_out()
	{
		if(current_marker !== null) { markers[current_marker][0].closeInfoWindow(); }
		map.setCenter(mapbounds.getCenter(), Math.min(4, map.getBoundsZoomLevel(mapbounds)));
	}
	
	function map_zoom_Ori(i)
	{
		map.setCenter(markers[i][0].getPoint(), 4);
	}

	function map_set_marker(marker, i)
	{
		GEvent.addListener(marker, "click", function() { map_show_info(i); }); 
		GEvent.addListener(marker, "infowindowclose", function() { current_marker = null; }); 
		document.getElementById("div_map_" + map_citys[i].id).onmousemove = function() { map_show_info(i); };
	}

	function map_init()
	{
		if (GBrowserIsCompatible()) 
		{
			map = new GMap2(document.getElementById(mymap));
			//縮放和移動控件

			map.addControl(new GScaleControl());
			map.addControl(new GLargeMapControl());
			map.addControl(new GRulerControl());
            // 地圖類型
			map.addMapType(G_PHYSICAL_MAP);
			map.setMapType(G_HYBRID_MAP);
			map.addControl(new GMapTypeControl());
			
			var center = new GLatLng(36.94, 106.08);
		
			map.setCenter(center, 4);
			
			// 坐標值
			GEvent.addListener(map,"moveend",function(){
			var centerST = map.getCenter();
			centerST = centerST.toString()
			centerST = centerST.replace("(","");
			centerST = centerST.replace(")","");
			centerST = centerST.replace(" ","");
			centerST = centerST.split(",");
			/*
            document.getElementById("coordinate_x").value=centerST[1];
		    document.getElementById("coordinate_y").value=centerST[0];
			*/
            });
			
			geocoder = new GClientGeocoder();
			
			for(var i = 0; i < map_citys.length; i++)
			{
			   if(map_citys[i].categorys == 1)
			    {
				  var icon = new GIcon(G_DEFAULT_ICON, "map/images/marker/marker" + map_citys[i].tag + ".png");
				} else 
				{
				  var icon = new GIcon(G_DEFAULT_ICON, "map/images/marker_sum/marker" + map_citys[i].tag + "sum.png");
				}
				var marker = new GMarker(new GLatLng( map_citys[i].lat, map_citys[i].lng ), {"icon": icon, "title": map_citys[i].name});
				map.addOverlay(marker);
				map_set_marker(marker, i);
				
                if(map_citys[i].name)
				  {
					map_countent = "<div align=\"left\"><span style=\"font-weight:bold;font-size:16px;\">" + map_citys[i].name + "</span>";
					map_countent = map_countent+"<br /><hr style=\"border:solid 1px #cccccc;width:250px\">";
				  }
				if(map_citys[i].content) { 
				    map_countent = map_countent+map_citys[i].content+"<br /><br />";
				   }
				if(map_citys[i].picture) { 
				    map_countent = map_countent+"<img src=\""+map_citys[i].picture+"\" border=\"0\" ><br /><br />";
				   }
				   
				   map_countent = map_countent+"<a href=\"javascript:map_zoom_in(" + i + ");\">放大地圖</a> <a href=\"javascript:map_zoom_Ori(" + i + ");\">還原地圖</a>";
					
			     if(map_citys[i].Links){
				     map_countent = map_countent+" <a href=\""+map_citys[i].Links+"\" target=\"_blank\">詳細頁面</a>";
					}
				   map_countent = map_countent+"</div>";
				
				markers.push([marker, map_countent, map_citys[i].id]);
				/*
				if(markers.length > 1)
				{
					mapbounds = 
						new GLatLngBounds(new GLatLng(Math.min(mapbounds.getSouthWest().lat(), map_citys[i].lat), 
							Math.min(mapbounds.getSouthWest().lng(), map_citys[i].lng)), 
						new GLatLng(Math.max(mapbounds.getNorthEast().lat(), map_citys[i].lat), 
							Math.max(mapbounds.getNorthEast().lng(), map_citys[i].lng)));
				}
				else
				{
					mapbounds = new GLatLngBounds(new GLatLng(map_citys[i].lat, map_citys[i].lng), 
						new GLatLng(map_citys[i].lat, map_citys[i].lng));
				}
				*/
					mapbounds = new GLatLngBounds(new GLatLng(36.94, 106.08), 
						new GLatLng(36.94, 106.08));
					/*
				document.getElementById("div_mapicon_" + map_citys[i].id).innerHTML = 
				"<img src=\"" +  "http://www.google.com/mapfiles/marker" + map_citys[i].tag + ".png" + "\" width=\"20\" height=\"34\" />";
				*/
			}
			
			map_zoom_out();
						
			
		}
	}
	
 function catchAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert("無法獲取坐標或地名不能為空!");
            } else {
				
			  poCoordinate = point.toString();
			  poCoordinate = poCoordinate.replace("(","");
			  poCoordinate = poCoordinate.replace(")","");
			  poCoordinate = poCoordinate.replace(" ","");
			  poCoordinate_S = poCoordinate.split(",");

			  poCoordinate_T = poCoordinate_S[0].split(".");
			  poCoordinate_G = poCoordinate_S[1].split(".");


var bounds = new GLatLngBounds;
bounds.extend(new GLatLng(poCoordinate_T[0], poCoordinate_G[0])); 
bounds.extend(new GLatLng(poCoordinate_S[0], poCoordinate_S[1])); 
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds)); 

			  
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml("<div align=\"left\"><strong>"+address+"</strong><br /> 經緯度："+poCoordinate+"</div>");  
            }
          }
        );
      }
    }
	
function centerAndZoomOnBounds(bounds) { 
  var center = bounds.getCenter(); 
  var newZoom = map.getBoundsZoomLevel(bounds); 
  if (map.getZoom() != newZoom) { 
    map.setCenter(center, newZoom); 
  } else { 
    map.panTo(center); 
  } 

} 