// copyright (c) 2005-2008 @allchinanet.com

var markersArray = new Array();

function focusOnMap(markerId) {
    GEvent.trigger(markersArray[markerId], 'click');
}

function loadmap() {
var icon = new GIcon();
icon.image = "marker.png";
icon.shadow = "shadow50.png";
icon.iconSize = new GSize(20, 34);
icon.shadowSize = new GSize(40, 34);
icon.iconAnchor = new GPoint(10, 34);
icon.infoWindowAnchor = new GPoint(10, 0);
var lng = 114.6; // default lng
var lat = 32.5;  // default lat


function createMarker(point, text, i) {
  var marker = new GMarker(point, icon);
   markersArray[i] = marker;
  // Show this marker's index in the info window when it is clicked
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(text);
  });
  return marker;
}  


function anchor(txt, href){
if (href ==null){
		return txt;
}
return "<a href='http://" + href + "'> " + txt + "</a>";
}



function anchor_img(img, href){
	if (href ==null){
		return "<img src=\"http://"+ img + "\">"
	}
	
   return "<a href='http://" + href + "'> " + "<img src=\"http://"+ img + "\">" + "</a>";
}
	
var map = new GMap(document.getElementById("map"));
    map.setMapType(G_NORMAL_MAP);
    map.addControl(new GSmallMapControl());
    map.centerAndZoom(new GPoint(lng, lat), 13);
var request = GXmlHttp.create();
request.open("GET", "china_tour_hightlight.xml", true);
request.onreadystatechange = function() {
  if (request.readyState == 4) {
    var xmlDoc = request.responseXML;
    var rootElement = xmlDoc.documentElement;
    if (rootElement == undefined) {return;}
    var markers = rootElement.getElementsByTagName("marker");
    var point, city, maker, url, location, attraction, attraction_url, attraction_type, n, attraction_img;
	
	
	for (var i = 0; i < markers.length; i++) {
      point = new GPoint(parseFloat(markers[i].getAttribute("lng")),
                         parseFloat(markers[i].getAttribute("lat")));
      marker = new GMarker(point);
	  attraction_type = markers[i].getAttribute("attraction_type");
	  n= markers[i].getAttribute("index");
	  
	  if(attraction_type =="H"){
		  icon.image = "hmarker.png";
	  }
	  
	  attraction = markers[i].getAttribute("attraction");
	  attraction_url = markers[i].getAttribute("attraction_url");
      city= markers[i].getAttribute("city");
	  if(city==null){
		  city="";
	  }

      url = markers[i].getAttribute("url");      
      location = markers[i].getAttribute("location");
       if(location==null){
		  location="";
	  }
	  
	 attraction_img = markers[i].getAttribute("attraction_img");      
       if(attraction_img==null){
		  attraction_img="No Pics";
	  } else{
		  
		  attraction_img = anchor_img(attraction_img,attraction_url);
	  }
	/*  html = "<table border=0 width=300 cellpadding=1 class=bubble>";
	  html += "<tr><td>";
	  html += "<H1>"+ anchor (city, url) + "</H1>";
	  html += "<br>Location:" +location+ "</td></tr>";   
	  html += "<tr><td>" + attraction_img +"</td></tr>";
	  html += "<tr><td>" + anchor(attraction, attraction_url) +"</td></tr>";
      html += "</table>";  
	*/  
	  html = "<table border=0 width=\"20px\" class=bubble>";
	  html += "<tr><td valign=\"top\"><h3>"+ anchor (city, url) + "</h3>";
	  html += "<br>" + attraction_img;+ "</td></tr>";   
      html += "</table>";
	  
      map.addOverlay(createMarker(point,html,n));
    }
	
		/* adding the route line*/  
		/* Beijing point 39.915990, 116.390619 */
         /* Shanghai point 31.165810" lng="121.464844 */
		 /*Xian lat="34.379713" lng="108.984375" */
		 /*Guilin lat="25.244696" lng="110.269775"*/
		 
		 
	  var polyline = new GPolyline([
  		  /* Beijing*/
		  new GLatLng(39.915990, 116.390619),
		  /*Xian*/
		  new GLatLng(34.379713, 108.984375),
		  /*Guilin*/
		  new GLatLng(25.244696, 110.269775),
		  /*Shanghai*/
  		  new GLatLng(31.165810, 121.464844)
		], "#CC0000", 5);
		map.addOverlay(polyline);
  }
}
request.send(null);    

}
//]]>
