// copyright (c) 2005-2008 @dcphototour.com

var markersArray = new Array();

function focusOnMap(markerId) {
    GEvent.trigger(markersArray[markerId], 'click');
}


function loadmap() {
var icon = new GIcon(G_DEFAULT_ICON);
icon.infoWindowAnchor = new GPoint(10, 0);
var lng = -77.0392; // default lng
var lat = 38.8894;  // 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), 3);
var request = GXmlHttp.create();
request.open("GET", "dc_travel_list.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");
	  
	  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=360 cellpadding=2 class=bubble>";
	  html += "<tr><td>" + attraction_img + "</font></td>";
	  html += "<td valign=\"top\"><h1>"+ anchor(attraction, attraction_url) + "</h1>";
	  html += "<br>Address:" +location+ "</td></tr>";   
      html += "</table>";
      map.addOverlay(createMarker(point,html,n));
    }
  }
}
request.send(null);    
}

