
/*###############################################################################################*/
/*#############  Globals  #######################################################################*/
/*###############################################################################################*/


var map;
var centerOfMap = new GLatLng(39.880235, 116.411133);
var initialZoomFactor = 5;
var wayPoints = new Array();
var currentLoc;
var geoCoder;
var leftContainerId = "left_container";
var scroller = null;
var mouseCoordinates = new Object;
var oldMouseCoordinates = new Object;
var mainMenuVisible = true;
var zoom_icon_top;
var circleRadius, centerMarker, circle, circleUnits, checked_location, checked_place, echeck_html; 
var circle = null;
var checked_point = null;
var point_renewed = false;
/*###############################################################################################*/
/*#############  Helper functions ###############################################################*/
/*###############################################################################################*/


function slideLeftMenu(id, state) {

	$("#" + id).animate({
	    width: ['toggle', 'swing'],
	    opacity: 'toggle'
	  }, 2000, 'linear', function() {

	  });
	
	mainMenuVisible = !mainMenuVisible;
	
	$("#scroller").animate({
	    left: [(!mainMenuVisible==true?'-=220':'+=220'),'swing']
	  }, 2000, 'linear', function() {

	});
}




function onLoadFunctions() {
	

	
}


/*###############################################################################################*/
/*#############  Map functions ##################################################################*/
/*###############################################################################################*/



/**
 * Custom zoom control buttons for google map
 * 
 * @return
 */

function RouteZoomControl() {

}

RouteZoomControl.prototype = new GControl();

RouteZoomControl.prototype.initialize = function(map) {
	// TODO: implement the button and the zoom bar
	// For buttons see example :
	// http://code.google.com/apis/maps/documentation/controls.html#Custom_Controls

	var container = document.createElement("div");
	container.setAttribute("id", "zoom-container");
	var zoomIn = document.createElement("div");
	zoomIn.setAttribute("id", "zoom-in");
	this.setButtonStyle(zoomIn);

	container.appendChild(zoomIn);
	zoomIn.appendChild(document.createTextNode("+"));
	GEvent.addDomListener(zoomIn, "click", function() {
		map.zoomIn();
	});

	var zoomOut = document.createElement("div");
	zoomOut.setAttribute("id", "zoom-out");
	
	this.setButtonStyle(zoomOut);

	container.appendChild(zoomOut);
	zoomOut.appendChild(document.createTextNode("-"));
	GEvent.addDomListener(zoomOut, "click", function() {
		map.zoomOut();
	});

	map.getContainer().appendChild(container);
	return container;
};

RouteZoomControl.prototype.getDefaultPosition = function() {
	var zoom_icon_top = (typeof window.innerHeight !='undefined')?window.innerHeight:document.documentElement.clientHeight;
	if(zoom_icon_top == '0')
		zoom_icon_top = document.body.offsetHeight;
	return new GControlPosition(G_ANCHOR_TOP_RIGHT , new GSize(7, zoom_icon_top/2-43));
	
	
};

RouteZoomControl.prototype.setButtonStyle = function(button) {

	button.style.backgroundColor = "#000000";
	button.style.width = "60px";
	button.style.height = "40px";
	button.style.color = "#FFFFFF";
	button.style.fontSize = "3em";
	button.style.textAlign = "center";
	button.style.cursor = "pointer";
	button.style.cssFloat = "left";
	button.style.styleFloat = "left";
	button.style.marginLeft = "4px";
	button.style.opacity = "0.8";

};

function RouteMapTypeControl() {

}

RouteMapTypeControl.prototype = new GControl();

RouteMapTypeControl.prototype.initialize = function(map) {

	this.links = new Object();
	var container = document.createElement("div");
	var container2 = document.getElementById("zoom-container");
	container.setAttribute("id", "map-view-container");
	this.setContainerStyle(container);

	var mapDiv = document.createElement("div");
	mapDiv.setAttribute("id", "map-view-map");
	var mapDivLink = document.createElement("a");
	mapDivLink.appendChild(document.createTextNode("+ 地图"));
	this.links["mapDivLink"] = mapDivLink;
	this.setLinkStyle(mapDivLink);
	mapDiv.appendChild(mapDivLink);
	container.appendChild(mapDiv);
	GEvent.addDomListener(mapDivLink, "click", function() {
		map.setMapType(G_NORMAL_MAP);
		updateHighlight(mapDivLink);
	});

	var satelliteDiv = document.createElement("div");
	satelliteDiv.setAttribute("id", "map-view-satellite");
	var satelliteDivLink = document.createElement("a");
	satelliteDivLink.appendChild(document.createTextNode("+ 卫星"));
	this.links["satelliteDivLink"] = satelliteDivLink;
	this.setLinkStyle(satelliteDivLink);
	satelliteDiv.appendChild(satelliteDivLink);
	container.appendChild(satelliteDiv);
	GEvent.addDomListener(satelliteDivLink, "click", function() {
		map.setMapType(G_SATELLITE_MAP);
		updateHighlight(satelliteDivLink);
	});

	var terrainDiv = document.createElement("div");
	terrainDiv.setAttribute("id", "map-view-terrain");
	var terrainDivLink = document.createElement("a");
	terrainDivLink.appendChild(document.createTextNode("+ 地形"));
	this.links["terrainDivLink"] = terrainDivLink;
	this.setLinkStyle(terrainDivLink);
	terrainDiv.appendChild(terrainDivLink);
	container.appendChild(terrainDiv);
	GEvent.addDomListener(terrainDivLink, "click", function() {
		map.setMapType(G_PHYSICAL_MAP);
		updateHighlight(terrainDivLink);
	});

	if (map.getCurrentMapType() == G_NORMAL_MAP) {
		updateHighlight(mapDivLink);
	} else if (map.getCurrentMapType() == G_SATELLITE_MAP) {
		updateHighlight(satelliteDivLink);
	} else {
		updateHighlight(terrainDivLink);
	}

	container2.appendChild(container);
	return container;

};

RouteMapTypeControl.prototype.setContainerStyle = function(container) {
	container.style.backgroundColor = "#000000";
	container.style.color = "#FFFFFF";
	container.style.height = "48px";
	container.style.width = "116px";
	container.style.textAlign = "right";
	container.style.opacity = "0.8";
	container.style.padding = "4px";
}

RouteMapTypeControl.prototype.setLinkStyle = function(link) {
	link.style.backgroundColor = "#000000";
	link.style.color = "#FFFFFF";
	link.style.fontWeight = "bold";
	link.style.textDecoration = "none";
	link.style.cursor = "pointer";
}

RouteMapTypeControl.prototype.getLinks = function() {
	return this.links;
}

function updateHighlight(button) {

	var links = new Array();
	links.push(button);

	var parent = button.parentNode;
	var p = parent.nextSibling;

	while (p != null) {
		links.push(p.firstChild);
		p = p.nextSibling;
	}
	p = parent.previousSibling;
	while (p != null) {
		links.push(p.firstChild);
		p = p.previousSibling;
	}

	if (links.length > 1) {
		for ( var i = 1; i < links.length; i++) {
			links[i].style.color = "#FFFFFF";
		}
	}
	button.style.color = "#00CCFF";
}
RouteMapTypeControl.prototype.getDefaultPosition = function() {

	return new GControlPosition(G_ANCHOR_TOP_RIGHT , new GSize(0, 43));
	
};



function GeoAddress(name, latlng, street, accuracy, country) {
	this.name= name;
	this.latlng = latlng;
	this.street = street;
	this.accuracy= accuracy;
	this.country=country;
	this.toString = function() {
		var s =  '<table border="0" cellspacing="0" cellpadding="2">'
				+'<tr><td>Name</td><td>'+this.name+'</td></tr>'
				+'<tr><td>Point</td><td>'+this.latlng.lat()+ ' : ' + this.latlng.lng() +'</td></tr>'
				+'<tr><td>Street/City</td><td>'+this.street+'</td></tr>'
				+'<tr><td>Accuracy</td><td>'+this.accuracy+'</td></tr>'
				+'<tr><td>Country</td><td>'+this.country+'</td></tr>'
				+'</table>';
		return s;
	}
}

/****************
function mapSingleRightClick(point, src, overlay)
{
    OpenInfoWindow(point);

}

function OpenInfoWindow(point)
{
    var html = "Test";
    map.openInfoWindowHtml(map.fromContainerPixelToLatLng(point), html);

} 
*/

/************** right click menu ********************/
function WriteAddress(response) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
    alert("Status Code:" + response.Status.code);
  } else {
    place = response.Placemark[0];
    document.getElementById('cityname').value = place.address;
  }
}  




function ContextMenu(oMap){this.initialize(oMap);}

//Construct the DOM tree of the menu
ContextMenu.prototype.initLink = function(oMap){
	var that=this;
	
	a_link = document.createElement("li");
	a_link.innerHTML="<a href='javascript:void(0);'>Check the location</a>";
	this.activeLabel=null;
	this.timer=null;
//This will manage the request for the altitude: once the result will be shown on a TLabel, and will disappear after 7 seconds.
	GEvent.addDomListener(a_link, 'click', function(){
		var point = that.map.fromContainerPixelToLatLng(that.clickedPixel);
		var url = 'get_altitude.php?alt_lat='+point.lat()+'&alt_lng='+point.lng();	
		that.contextmenu.style.display="none";
		GDownloadUrl(url, function(data, responseCode) {
		//This is the returned value if no data is available
			if(data=="-32768"){
				var retval = "N/A";
			}else{
				var retval = data + " m.";
			}
			if(that.activeLabel!=null || that.timer!=null){
				map.removeTLabel(that.activeLabel);
				window.clearTimeout(that.timer);
				that.timer=null;
			}	
			
			var layer_html = "<div style='height:300px; width:300px;'>testetstetstetstetst</div>";
			Infowin(point, layer_html);
			//geocoder.getLocations(point, WriteAddress);  
			
		});
	});
	this.ul_container.appendChild(a_link);
	
	a_link = document.createElement("li");
	a_link.innerHTML="<a href='javascript:void(0);'>Zoom In  </a>";
	GEvent.addDomListener(a_link, 'click', function() {
		that.map.zoomIn();
		that.contextmenu.style.display='none';
	});
	this.ul_container.appendChild(a_link);
	
	a_link = document.createElement("li");
	a_link.innerHTML="<a href='javascript:void(0);'>Zoom Out  </a>";
	GEvent.addDomListener(a_link, 'click', function() {
		that.map.zoomOut();
		that.contextmenu.style.display='none';
	});
	this.ul_container.appendChild(a_link);
	
	a_link = document.createElement("li");
	a_link.innerHTML="<a href='javascript:void(0);'>Zoom Here  </a>";
	GEvent.addDomListener(a_link, 'click', function() {
		var point = that.map.fromContainerPixelToLatLng(that.clickedPixel);
		that.map.zoomIn(point,true);
		that.contextmenu.style.display="none";
	});
	this.ul_container.appendChild(a_link);
	
	a_link = document.createElement("li");
	a_link.innerHTML="<a href='javascript:void(0);'>Center Map Here  </a>";
	GEvent.addDomListener(a_link, 'click', function() {
		var point = that.map.fromContainerPixelToLatLng(that.clickedPixel);
		that.map.panTo(point);
		that.contextmenu.style.display="none";
	});
	this.ul_container.appendChild(a_link);
	
	
}
ContextMenu.prototype.bind = function(method) {
	var self = this;
	var opt_args = [].slice.call(arguments, 1);
	return function() {
		var args = opt_args.concat([].slice.call(arguments));
		return method.apply(self, args);
	}
}

//The object 'constructor'
ContextMenu.prototype.initialize = function(oMap){
	this.map = oMap;
	var that=this;
	
	this.contextmenu = document.createElement("div");
	this.contextmenu.style.display="none";
//CSS class name of the menu
	this.contextmenu.className="contextmenu";
	this.ul_container = document.createElement("ul");
	this.ul_container.id="context_menu_ul";
	this.contextmenu.appendChild(this.ul_container);	
	this.initLink();
	this.map.getContainer().appendChild(this.contextmenu);	

//Event listeners that will interact with our context menu
	GEvent.addListener(oMap,"singlerightclick",function(pixel,tile) {
		that.clickedPixel = pixel;
		var x=pixel.x;
		var y=pixel.y;
//Prevents the menu to go out of the map margins, in this case the expected menu size is 150x110
		if (x > that.map.getSize().width - 160) { x = that.map.getSize().width - 160 }
		if (y >that.map.getSize().height - 120) { y = that.map.getSize().height - 120 }
		var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(x,y));  
		pos.apply(that.contextmenu);
		that.contextmenu.style.display = "";
	});	
	GEvent.addListener(oMap, "move", function() {
		that.contextmenu.style.display="none";
	});
	GEvent.addListener(oMap, "click", function(overlay,point) {
		that.contextmenu.style.display="none";
	});	
}
/************ end of right click nemu ***************/

var ew = null;
function initialize() {
	 if (GBrowserIsCompatible()) {
		 resizeMap();
		 map = new GMap2(document.getElementById("map_canvas"));
		 geocoder = new GClientGeocoder();
		 //centerOfMap
		 map.setCenter(new GLatLng(39.164141,102.919922), initialZoomFactor);
		 map.addControl(new RouteZoomControl());
		 map.addControl(new RouteMapTypeControl());
		 $("#zoom-container").css('top', '42%');
		 //new ContextMenu(map);
		 //GEvent.addListener(map, "singlerightclick", mapSingleRightClick); 
		
		 GEvent.addListener(map, 'click', function(overlay, point){
			 hide_menu('left_container_dynamic');
			});
		
	 } else {
		 alert("Incompatible browser, your current browser cannot show anything due to incompatibilites.");
	 }
	 //resolution_check();
	 ewindow_initial();
}





/*###############################################################################################*/
/*#############  UI control elements ############################################################*/
/*###############################################################################################*/




function resizeRouteFormIframe(h) {
	$("#route_form_frame").height(h);
}








$(document).ready( function() {}
	//empty
);


/*###############################################################################################*/
/*#############  Efficiency check	 ############################################################*/
/*###############################################################################################*/



function drawCircle() {
	circleUnits = 'KM';
	var oRadius = document.getElementById('radiusInput');
	oRadius.value = oRadius.value ? oRadius.value : 500;
	
	if (oRadius.value.match(/[^\d.]/)) {
		alert("Don't be silly. Enter a number for radius");
		return;
	}
	if (oRadius.value > 9999) {
		alert("The radius is too large");
		return;
	}
	circleRadius = oRadius.value;
	getAddress();
}


function doDrawCircle(){
	if (circle != null) {
		map.removeOverlay(circle);
		map.removeOverlay(centerMarker);
	}
	getAddress();
	
}

function getAddress() {
		checked_location = document.getElementById('cityname');
		if (checked_location != null) {
			//geocoder = new GClientGeocoder();
			geocoder.getLocations(checked_location.value, loadAddress);
		}
}
function loadAddress(response) {
		if (circle != null) {
				map.removeOverlay(circle);
				map.removeOverlay(centerMarker);
		}	
		if (!response || response.Status.code != 200) {
			alert("Status code: " + response.Status.code);
		} else if (G_GEO_UNKNOWN_ADDRESS==response.Status.code) {
			alert("Unknown address");
		} else {
			//console.log(dumpObject(response));
			var checked_place = response.Placemark[0];
			checked_point = new GLatLng(checked_place.Point.coordinates[1], checked_place.Point.coordinates[0]);
			var oRadius = document.getElementById('radiusInput');
			document.getElementById('echeck_menu').innerHTML="<br><div>RADIUS: "+oRadius.value+"KM, LOCATION: "+checked_location.value+"</div>"+
														  "<div style='cursor:pointer' onclick='clear_selection()'>+CLEAR SELECTION</div>"+
														  "<div style='cursor:pointer' onclick='draw_circle()'>+SHOW CHECK ON MAP</div>";
			
			//draw_circle();
			
		}
		
}	

function clear_selection(){
	document.getElementById('cityname').value = "";
	document.getElementById('radiusInput').value = "";
	if (circle != null) {
				map.removeOverlay(circle);
				map.removeOverlay(centerMarker);
	}	
}

function draw_circle(){
					
			var bounds = new GLatLngBounds();	
			var circlePoints = Array();

			with (Math) {
				if (circleUnits == 'KM') {
					var d = circleRadius/6378.8;	// radians
				}
				else { //miles
					var d = circleRadius/3963.189;	// radians
				}

				var lat1 = (PI/180)*checked_point.lat(); // radians
				var lng1 = (PI/180)*checked_point.lng(); // radians
				
				//if (circle != null) { map.removeOverlay(circle);}	
				for (var a = 0 ; a < 361; a++ ) {
					if (a%2==0){
					if (circle != null) { map.removeOverlay(circle);}					
				
					var tc = (PI/180)*a;
					var y = asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc));
					var dlng = atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(y));
					var x = ((lng1-dlng+PI) % (2*PI)) - PI ; // MOD function
					var point = new GLatLng(parseFloat(y*(180/PI)),parseFloat(x*(180/PI)));
					circlePoints.push(point);
					bounds.extend(point);					
					circle = new GPolygon(circlePoints, '#000000', 2, 0.3, '#000000', 0.3);	
					
					map.addOverlay(circle);
					}
				}
				//map.addOverlay(circle);
				//var baseIcon = new GIcon(G_DEFAULT_ICON);
				//baseIcon.image = "http://www.opencms.org/export/system/galleries/images/logos/opencms_punkt_160.png_913563173.png";
				//baseIcon.imageSize = new GSize(20, 20);
 				//markerOptions = {icon:baseIcon};
 				
				echeck_html = "<div>LOCATION: "+checked_location.value+"</div><br>"+
						   "<div>RADIUS: "+circleRadius+"KM</div><br>";
				map.openInfoWindowHtml(checked_point, echeck_html);
				centerMarker = new GMarker(checked_point,{draggable:false});
				GEvent.addListener(centerMarker,'drug',drawCircle)
				GEvent.addListener(centerMarker,'click', function(){	
					map.openInfoWindowHtml(checked_point,echeck_html);}
				)	
				
				map.addOverlay(centerMarker);	
				map.setCenter(checked_point, initialZoomFactor);
				map.setZoom(map.getBoundsZoomLevel(bounds));
						
			}
	
}		
function dumpObject( obj) {
		var s = "";
		function dump(o) {
			var z="";
			for (var x in o) {
				if (typeof o[x] =='object') {
					if (o[x]!=obj) {
						z+="\n" + dump(o[x]);
					}
				} else {
					z+=x +" : " + o[x].toString() +"\n";
				}
			}
			return z;
		}
		s = dump(obj);
		return s;

}



/*###############################################################################################*/
/*#############  HTML pop up Window  ############################################################*/
/*###############################################################################################*/

function  Infowin(latlng, html) {
        this.latlng_ = latlng;
        this.html_ = html;
        this.prototype = new GOverlay();
		win_initialize(map);
        // Creates the DIV representing the infowindow
        function win_initialize (map) {
                var div = $('<div />');
                div.css({
                        'position' : 'absolute',
                        'width' : '300px'
                }).appendTo(map.getPane(G_MAP_FLOAT_PANE))

                this.map_ = map;
                this.div_ = div;

                update(html);
        }
        function  update(html){
                this.html_ = html;			
                this.div_.empty();
                var content = $('<div />').addClass('infowin-content').css({
                        'position' : 'relative',
                         'overflow' : 'hidden',
                        'height' : '300px',
                        'width' : '300px',              
                        'background-color':'white'                        
                }).html(html);
                
                 var close_tab = $('<div />').addClass('layer_close_tab').css({
                        'position' : 'absolute',
                        'height' : '12px',
                        'width' : '12px',    
                        'top' : '3px',
                        'right' : '3px',
                        'cursor' : 'pointer'                                  
                }).html("X");
				
               this.div_.append(content).append(close_tab);

                redraw(true);
        }

        // Remove the main DIV from the map pane
        function remove() {
          this.div_.remove();
        }

        // Copy our data to a new instance
        function copy() {
          return new Infowin(this.latlng_, this.html_);
        }
        // Redraw based on the current projection and zoom level
     /*  function redraw(force) {
                if (!force) return;
                var point = this.map_.fromLatLngToDivPixel(this.latlng_);
                // Now position our DIV based on the DIV coordinates of our bounds
                this.div_.css({
                        left : point.x - 108,
                        top : point.y - this.div_.height() - 22
                });
                //add the close_tab controller
                $('.layer_close_tab').click(
                	function(){
                		$(this).parent().remove();
                	}
                )
        } 
       
       */
       
      
       function redraw(force) {
                if (!force) return;
                var point = this.map_.fromLatLngToDivPixel(this.latlng_);
                var x = point.x;
       var y = point.y;
                var mapSize = this.map_.getSize();
       
       if (x < 10) { x = 10; }
       if (y < 10) { y = 10; }
       if (x > mapSize.width  - this.div_.width())  { x = mapSize.width  - this.div_.width()  - 10; }
       if (y > mapSize.height - this.div_.height()) { y = mapSize.height - this.div_.height() - 10; }
       
       var position = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(x, y));
        position.apply(this.div_[0]);
                //add the close_tab controller
                $('.layer_close_tab').click(
                 function(){
                  $(this).parent().remove();
                 }
                )
        }
              
}	




// EWindow.js 
//
//   This Javascript is provided by Mike Williams
//   Community Church Javascript Team
//   http://www.bisphamchurch.org.uk/   
//   http://econym.org.uk/gmap/
//
//   This work is licenced under a Creative Commons Licence
//   http://creativecommons.org/licenses/by/2.0/uk/
//
// Version 0.0  Initial version 
// Version 0.1  10/10/2006 Added E_STYLE_7 
// Version 0.2  17/05/2007 Added .isHidden() and .supportsHide()
// Version 0.3  14/09/2007 added .zindex()
// Version 0.4  09/02/2008 moved the window to the G_MAP_FLOAT_PANE
// Version 0.5  16/10/2008 updated the fudge factors


      function EStyle(stemImage, stemSize, boxClass, boxOffset) {
        this.stemImage = stemImage;
        this.stemSize = stemSize;
        this.boxClass = boxClass;
        this.boxOffset = boxOffset;
        //this.border = border;
        
        // Known fudge factors are:
        // Firefox 1.0, 1.5, 2.0      5, -1
        // Firefox 3.0                4, -1
        // IE 6.0                     0, -1
        // Opera 8.54                 3, -1
        // Opera 9                    4, -1
        // Netscape (7.2, 8.0)        5, -1
        // Safari                     5, -1
        // Chrome                     5, -1        
        
        var agent = navigator.userAgent.toLowerCase();
        
        var fudge = 5;  // assume Netscape if no match found
       
        if (agent.indexOf("opera/9") > -1) {
          fudge = 4;
        }   
        else if (agent.indexOf("opera") > -1) {
          fudge = 3;
        }   
        else if (agent.indexOf("firefox/3") > -1) {
          fudge = 4;
        }   
        else if (agent.indexOf("firefox") > -1) {
          fudge = 5;
        }   
        else if (agent.indexOf("chrome") > -1) {
          fudge = 5;
        }   
        else if (agent.indexOf("safari") > -1) {
          fudge = 5;
        }   
        else if (agent.indexOf("msie") > -1) {
          fudge = 0;
        }
        this.fudge = fudge;
      }
      
      var E_STYLE_1 = new EStyle("", new GSize(24,13),  "estyle1", new GPoint(-10,23));


      function EWindow(map,estyle) {
        // parameters
        this.map=map;
        this.estyle=estyle;
        // internal variables
        this.visible = false;
        // browser - specific variables
        this.ie = false;
        var agent = navigator.userAgent.toLowerCase();
        if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){ this.ie = true} else {this.ie = false}
      } 
      
      EWindow.prototype = new GOverlay();

      EWindow.prototype.initialize = function(map) {
        var div1 = document.createElement("div");
        div1.style.position = "absolute";
        map.getPane(G_MAP_FLOAT_PANE).appendChild(div1);
        var div2 = document.createElement("div");
        div2.style.position = "absolute";
        div2.style.width = this.estyle.stemSize.width+"px";
        map.getPane(G_MAP_FLOAT_PANE).appendChild(div2);
        this.div1 = div1;
        this.div2 = div2;
      }

      EWindow.prototype.openOnMap = function(point, html, offset) {
        this.offset = offset||new GPoint(0,0);
        this.point = point;
        this.div1.innerHTML = '<div class="' + this.estyle.boxClass + '">' + html + '</div>';
       /*
        if (this.ie && this.estyle.stemImage.toLowerCase().indexOf(".png")>-1) {
          var loader = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.estyle.stemImage+"', sizingMethod='scale');";
          this.div2.innerHTML = '<div style="height:' +this.estyle.stemSize.height+ 'px; width:'+this.estyle.stemSize.width+'px; ' +loader+ '" ></div>';
        } else {
          this.div2.innerHTML = '<img src="' + this.estyle.stemImage + '" width="' + this.estyle.stemSize.width +'" height="' + this.estyle.stemSize.height +'">';
        }
        */
        var z = GOverlay.getZIndex(this.point.lat());
        this.div1.style.zIndex = z;
        this.div2.style.zIndex = z+1;
        this.visible = true;
        this.show();
        this.redraw(true);
      }
      
      EWindow.prototype.openOnMarker = function(marker,html) {
        var vx = marker.getIcon().iconAnchor.x - marker.getIcon().infoWindowAnchor.x;
        var vy = marker.getIcon().iconAnchor.y - marker.getIcon().infoWindowAnchor.y;
        //alert(vx+"      "+vy)
        this.openOnMap(marker.getPoint(), html, new GPoint(vx,vy));
      }
      

      EWindow.prototype.redraw = function(force) {
        if (!this.visible) {return;}
        var p = this.map.fromLatLngToDivPixel(this.point);
        this.div2.style.left   = (p.x + this.offset.x) + "px";
        this.div2.style.bottom = (-p.y + this.offset.y -this.estyle.fudge) + "px";
        this.div1.style.left   = (p.x + this.offset.x + this.estyle.boxOffset.x) + "px";
        this.div1.style.bottom = (-p.y + this.offset.y + this.estyle.boxOffset.y) + "px";
      }

      EWindow.prototype.remove = function() {
        this.div1.parentNode.removeChild(this.div1);
        this.div2.parentNode.removeChild(this.div2);
        this.visible = false;
      }

      EWindow.prototype.copy = function() {
        return new EWindow(this.map, this.estyle);
      }

      EWindow.prototype.show = function() {
        this.div1.style.display="";
        this.div2.style.display="";
        this.visible = true;
      }
      
      EWindow.prototype.hide = function() {
        this.div1.style.display="none";
        this.div2.style.display="none";
        this.visible = false;
      }
      
      EWindow.prototype.isHidden = function() {
        return !this.visible;
      }
      
      EWindow.prototype.supportsHide = function() {
        return true;
      }

      EWindow.prototype.zindex = function(zin) {
        var z = GOverlay.getZIndex(this.point.lat());
        this.div1.style.zIndex = z+zin;
        this.div2.style.zIndex = z+1+zin;
      }
      var layer_firstin = true;
      function createMarker(point,temp_marker, html) {
        //var temp_marker = marker1;
        // ========== Open the EWindow instead of a Google Info Window ==========
        GEvent.addListener(temp_marker, "click", function() {
        	//ew = new EWindow(map, E_STYLE_1);  
          if(layer_firstin){	
          		ew = new EWindow(map, E_STYLE_1);    
     	  		map.addOverlay(ew); 
     	  		layer_firstin = !layer_firstin;
     	  }		 
          	ew.openOnMarker(temp_marker,html);
		  
		var half_height = (typeof window.innerHeight !='undefined')?window.innerHeight:document.documentElement.clientHeight;
		if(half_height == '0')
			half_height = document.body.offsetWidth;
		var half_width = (typeof window.innerWidth !='undefined')?window.innerHeight:document.documentElement.clientWidth;
		if(half_width == '0')
			half_width = document.body.offsetWidth;
		
		half_height = half_height/2;
		half_width = half_width/2;
		
			
			  		
            var gpoint = map.fromLatLngToDivPixel(point);
						        var bpoint = map.fromLatLngToDivPixel(map.getCenter());
						       
						        var xCenter=bpoint.x;
						        var yCenter=bpoint.y;

						        var xOffSet=gpoint.x - bpoint.x;
						        var yOffSet=gpoint.y - bpoint.y;
						        //alert(gpoint.x+"    "+half_width)
						        if(half_width - xOffSet < 100){
						        	xCenter+=xCenter + 110;
						        }
						        if(half_width - xOffSet > half_width && half_width + xOffSet<100){
						        	xCenter+=xCenter -110;
						        }

						        if(half_height - yOffSet < 320){
						        	yCenter+=yCenter + 110;
						        }
						        /*if(half_height - yOffSet > half_height && half_height + yOffSet<100){
						        	yCenter+=yCenter -110;
						        }
						*/
						      /*  if(yOffSet > 0 - ew.estyle.ie6_fudge - ew.estyle.ie7_fudge - 20){
						        	yCenter +=yOffSet -0 + ew.estyle.ie6_fudge+ ew.estyle.ie7_fudge + 20;
						        }
						        */
						        var new_center_point = map.fromDivPixelToLatLng(new GPoint(gpoint.x, gpoint.y));
						        map.panTo(new_center_point);
			       
          
        });
        //map.addOverlay(temp_marker);
        return temp_marker;
      }
      
      
      
      
      
      
      function ewindow_initial(){

      		// ========== Close the EWindow if theres a map click ==========
      		GEvent.addListener(map, "click", function(overlay,point) {
        	if (!overlay) {
        		if(ew != undefined && ew != null){
        			ew.hide();
        		}          		
        	}
      		});
      
	}
	function resolution_check(){
		var height = (typeof window.innerHeight !='undefined')?window.innerHeight:document.documentElement.clientHeight;
		if(height == '0')
			height = document.body.offsetHeight;
		var width = (typeof window.innerWidth !='undefined')?window.innerWidth:document.documentElement.clientWidth;
		if(width == '0')
			width = document.body.offsetWidth;
			//alert(width+"   "+height)
		if (width<800||height<600){
				var messageTop = height/2 -160/2;
				var mesageLeft= width/2 -300/2;
				
				if(messageTop <0){
					messageTop =0;
				}
				if(mesageLeft <0){
					mesageLeft =0;
				}
				
				
				if (typeof document.body.style.maxHeight == "undefined"){ //IE6
							$("#mask").css('height',height+'px');							
				}			
				
				document.getElementById("mask").innerHTML= "<div id=\"i_message_block\" style=\"display:block; top:"+messageTop+"px; left:"+mesageLeft+"px;background-color:black; height:160px\">"+				
										"<div id=\"i_message\" style=\"color:white; top:36px;height:120px; width:260px; left:22px;\">您目前使用的浏览器窗口过小，我们推荐您使用1024*768px浏览器窗口访问本网站。</div>"+
										"<div class='size_alert' id=\"i_message_close\"><a href=\"javascript:void(0)\"></a></div>"+
										"<div id=\"ok_button\">OK</div>"+
									    "</div>";
													    
				$("#mask").css({"display":"block", opacity:0});
				$("#mask").fadeTo(500, 0.79);
				
				
				$(".size_alert, #ok_button").click(function(){
					$("#mask").fadeOut(500);	
					
					window.moveTo(0, 0);
					window.resizeTo(window.screen.availWidth, window.screen.availHeight);
				
				});
				
				/*	
				$("#ok_button").click(function(){
					window.moveTo(0, 0);
					window.resizeTo(window.screen.availWidth, window.screen.availHeight);
				});
				
				*/
				$("#ok_button").hover(
					function(){
						$(this).css('color','#00CCFF');
					},
					function(){
						$(this).css('color','white');
					}				
				);
													    
		}else{
			$("#mask").css("display","none");
		}											    
			
	}
	
	function open_washingmachine(){
			var height = (typeof window.innerHeight !='undefined')?window.innerHeight:document.documentElement.clientHeight;
			if(height == '0')
			height = document.body.offsetHeight;
			var width = (typeof window.innerWidth !='undefined')?window.innerWidth:document.documentElement.clientWidth;
			if(width == '0')
			width = document.body.offsetWidth;
			
			var messageTop = height/2 -44/2;
			var mesageLeft= width/2 -44/2;
			
			if(messageTop <0){
				messageTop =0;
			}
			if(mesageLeft <0){
				mesageLeft =0;
			}
			
			if (typeof document.body.style.maxHeight == "undefined") //IE6
					$("#mask").css('height',height+'px');
			document.getElementById("mask").innerHTML= "<img style=\"position:absolute; width:44px; height:44px; top:"+messageTop+"px; left:"+mesageLeft+"px;\" src='/_common/icons/loading.gif'>";
			$("#mask").css({"display":"block", opacity:0});
			$("#mask").fadeTo(500, 0.79);
	}
	
	function close_washingmachine(){
			$("#mask").fadeOut(500);
	}
	
	function open_flashlayer(){
			var height = (typeof window.innerHeight !='undefined')?window.innerHeight:document.documentElement.clientHeight;
			if(height == '0')
					height = document.body.offsetHeight;
			var width = (typeof window.innerWidth !='undefined')?window.innerWidth:document.documentElement.clientWidth;
			if(width == '0')
				width = document.body.offsetWidth;
			layer_width = 574;
			layer_height = 445;
			layer_top = (height - layer_height)/2;
			layer_left = (width - layer_width)/2;
					
			if (typeof document.body.style.maxHeight == "undefined"){ //IE6
					$("#mask, , #flash_mask").css('height',height+'px');				
			}		
			//document.getElementById("mask").innerHTML= "<embed id=\"flash_movie1\" style=\"position:absolute; width:"+layer_width+"px; height:"+layer_height+"px; top:"+layer_top+"px; left:"+layer_left+"px;\" src='/_common/swf/plan_routs.swf'></embed>"+
			//											"<div id=\"flash_layer_close\" style=\"position:absolute; width:18px; height:18px; overflow:hidden; top:"+layer_top+"px; left:"+(Number(layer_left)+Number(layer_width))+"px; "+
			//											"cursor:pointer; _cursor:hand; background-image:url(/_common/icons/close_x.png);\"></div>"
														
			document.getElementById("mask").innerHTML= "";											
			document.getElementById("flash_mask").innerHTML= "<div id='flash_movie' style=\"position:absolute; opacity:1; _filter:alpha(opacity:100); width:"+layer_width+"px; height:"+layer_height+"px; top:"+layer_top+"px; left:"+layer_left+"px;\"></div>"+
														"<div id=\"flash_layer_close\" style=\"position:absolute; width:18px; height:18px; overflow:hidden; top:"+layer_top+"px; left:"+(Number(layer_left)+Number(layer_width))+"px; "+
														"cursor:pointer; _cursor:hand; background-image:url(/_common/icons/close_x.png);\"></div>"										
			$("#mask").css({"display":"block", opacity:0});
			$("#mask").fadeTo(500, 0.79);
			$("#flash_mask").css('display','block');
			var flashObject = new SWFObject("/_common/swf/plan_routs.swf", "mainFlash", layer_width, layer_height, "9.0.45", "#ffffff");
			flashObject.addVariable("movieurl","/_common/swf/movie.swf");
			flashObject.addVariable("status","big");
			flashObject.addParam("allowFullScreen","false");
			flashObject.addParam("quality","high");
			flashObject.addParam("allowScriptAccess","sameDomain");
			flashObject.addParam("wmode", "transparent");								
			flashObject.write("flash_movie");		
			
			$("#flash_layer_close").click(function(){
				document.getElementById("flash_mask").innerHTML="";
				$("#mask, #flash_mask").css('display','none');
			})
			$("#flash_layer_close").hover(
				function(){
						$(this).css('background-image','url(/_common/icons/close_x_over.png)')
				},
				function(){
						$(this).css('background-image','url(/_common/icons/close_x.png)')
				}
			)
			
			
			
	}
	
	
	
	$(document).ready(function(){
			resolution_check();
			$("#bottom_teaser").css("display", "block");
	});
