﻿//	<![CDATA[
    function loadPosition(map) {
      if (GBrowserIsCompatible()) {
        var mapId=map;
		map = new GMap2(document.getElementById(map));
		map.addControl(new GSmallMapControl());//移动、缩放地图（小）

		//为HomePoint创建一个"基准"图标
		homeIcon = new GIcon();
		homeIcon.shadow = "images/shadow50.png";
		homeIcon.iconSize = new GSize(26, 34);
		homeIcon.shadowSize = new GSize(40, 34);
		homeIcon.iconAnchor = new GPoint(13, 34);
		homeIcon.infoWindowAnchor = new GPoint(13, 2);

        // 为所有的标注创建一个“基准”图标，并指定它的阴影、尺寸、锚点等
		var baseIcon = new GIcon();
		baseIcon.shadow = "images/shadow50.png";
		baseIcon.iconSize = new GSize(20, 34);
		baseIcon.shadowSize = new GSize(37, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		baseIcon.infoShadowAnchor = new GPoint(18, 25);

//		从页面上获取Title,xLat,xLng的值,如果没有从Cookie获取,如果Cookie没有则指定一个默认值
		var title="您当前所处的位置";
		var expirationDate=365
		var homeLat=getCookie("homeLat");
		var homeLng=getCookie("homeLng");
		setCookie("homeLat",homeLat,expirationDate);
		setCookie("homeLng",homeLng,expirationDate);
/*
		var xLat=parent.document.getElementById("Lat").value;
		var xLng=parent.document.getElementById("Lng").value;
*/		
		
		function SetNewPosition(point){
 			//map.openInfoWindowHtml(point, "您移动到了新的位置");
			if(getCookie("homeLat")!=point.lat() || getCookie("homeLng")!=point.lng()){
				setCookie("homeLat",point.lat(),expirationDate);
				setCookie("homeLng",point.lng(),expirationDate);
				map.clearOverlays();
				map.addOverlay(new creatHomeMarker(point,title));
				map.panTo(point);
				mainGetBusiness(); /*重新计算周围的商户并显示*/
				ihome99Ad();//更新广告
			}
		}
		
		function creatHomeMarker(point,title){
			var icon = new GIcon(homeIcon);
			icon.image = "images/marker_home.png";
			var tempMarker=new GMarker(point, {icon: icon,title: title,draggable: true});
			GEvent.addListener(tempMarker, "click", function() {
	   			//tempMarker.openInfoWindowHtml(title);
 	 		});
			GEvent.addListener(tempMarker, "dragstart", function() {
  				//map.closeInfoWindow();
 			});
			
			
			GEvent.addListener(tempMarker, "dragend", function() {
				SetNewPosition(tempMarker.getLatLng());
	  		});
			
			return tempMarker;
		}
		
		var HomePoint=new GLatLng(homeLat,homeLng);//定义地图中心点
		map.setCenter(HomePoint, 14);//嘉键大厦坐标为地图中心点,16级缩放
		var HomeMarker=new creatHomeMarker(HomePoint,title);// 在给定的点上创建标注
		map.addOverlay(HomeMarker);
//		HomeMarker.openInfoWindowHtml(title+"的位置");	

		
		//地图拖动开始
		GEvent.addListener(map,"movestart", function() {
			
		});
		
		//地图拖动结束，存储中心地点
		GEvent.addListener(map,"moveend", function() {
			//setCookie("homeLat",map.getCenter().lat(),expirationDate);
			//setCookie("homeLng",map.getCenter().lng(),expirationDate);
			//GLog.write(getCookie("zoomLevel"));
			SetNewPosition(map.getCenter());
		});	

      }
    }
	
    //]]>
