//<![CDATA[

if (GBrowserIsCompatible()) {
// this variable will collect the html which will eventualy be placed in the side_bar
var side_bar_html = "";

// arrays to hold copies of the markers and html used by the side_bar
// because the function closure trick doesnt work there
var gmarkers = [];
var htmls = [];
var i = 0;

// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
var baseIcon = new GIcon();
baseIcon.shadow = "http://www.cityofvancouver.us/_map/icon_tree_shadow2.png";
baseIcon.iconSize = new GSize(30, 30);
baseIcon.shadowSize = new GSize(40, 40);
baseIcon.iconAnchor = new GPoint(16, 27);
baseIcon.infoWindowAnchor = new GPoint(15, 8);
baseIcon.infoShadowAnchor = new GPoint(18, 25);  


// A function to create the marker and set up the event window
function createMarker(point,index,mapdonor,maploc,maphonor,mapspecies,mapplantdate,mapdedi,mapphoto) {
//var letter = String.fromCharCode("A".charCodeAt(0) + index);  
var icon = new GIcon(baseIcon);  
icon.image = "http://www.cityofvancouver.us/_map/icon_tree1_mod.png";
var marker = new GMarker(point, icon);
GEvent.addListener(marker, "click", function() {
 marker.openInfoWindowHtml("<p align=left class=content style=width:300px;><img align=right src=/upload/contents/900/"+ mapphoto +"><b>"+ maphonor +"<br><span class=balloon>Location:</b> " + maploc + "<br><b>Donor:</b> " + mapdonor + "<br><b>Species:</b> " + mapspecies + "<br><b>Planting Date:</b> " + mapplantdate +"<br><i>" + mapdedi +"</i></span></p>");
});
// The new marker "mouseover" listener        
GEvent.addListener(marker,"mouseover", function() {
 marker.openInfoWindowHtml("<p align=left class=content style=width:300px;><img align=right src=/upload/contents/900/"+ mapphoto +"><b>"+ maphonor +"<br><span class=balloon>Location:</b> " + maploc + "<br><b>Donor:</b> " + mapdonor + "<br><b>Species:</b> " + mapspecies + "<br><b>Planting Date:</b> " + mapplantdate +"<br><i>" + mapdedi +"</i></span></p>");
}); 
// save the info we need to use later for the side_bar
gmarkers[i] = marker;
//htmls[i] = ("<b>" + siteaddress + "</b>");
htmls[i] = ("<p align=left class=content style=width:300px;><img align=right src=/upload/contents/900/"+ mapphoto +"><b>"+ maphonor +"<br><span class=balloon>Location:</b> " + maploc + "<br><b>Donor:</b> " + mapdonor + "<br><b>Species:</b> " + mapspecies + "<br><b>Planting Date:</b> " + mapplantdate +"<br><i>" + mapdedi +"</i></span></p>");
// add a line to the side_bar html
side_bar_html += '<p style=margin-top:5px;margin-bottom:5px;><a href="javascript:myclick(' + i + ')">'  + maphonor + '</a></p>';
//side_bar_html += '<p style=margin-top:5px;margin-bottom:5px;><a class=subnav href="javascript:myclick(' + i + ')">'  + maphonor + '</a></p>';
i++;
return marker;
}


// Alternate function to create the marker and set up the event window when there is no picture
function createMarkerNoPic(point,index,mapdonor,maploc,maphonor,mapspecies,mapplantdate,mapdedi,mapphoto) {
//var letter = String.fromCharCode("A".charCodeAt(0) + index);  
var icon = new GIcon(baseIcon);  
icon.image = "http://www.cityofvancouver.us/_map/icon_tree1_mod.png";
var marker = new GMarker(point, icon);
GEvent.addListener(marker, "click", function() {
 marker.openInfoWindowHtml("<p align=left class=content style=width:250px;><b>"+ maphonor +"<br><span class=balloon>Location:</b> " + maploc + "<br><b>Donor:</b> " + mapdonor + "<br><b>Species:</b> " + mapspecies + "<br><b>Planting Date:</b> " + mapplantdate +"<br><i>" + mapdedi +"</i></span></p>");
});
// The new marker "mouseover" listener        
GEvent.addListener(marker,"mouseover", function() {
 marker.openInfoWindowHtml("<p align=left class=content style=width:250px;><b>"+ maphonor +"<br><span class=balloon>Location:</b> " + maploc + "<br><b>Donor:</b> " + mapdonor + "<br><b>Species:</b> " + mapspecies + "<br><b>Planting Date:</b> " + mapplantdate +"<br><i>" + mapdedi +"</i></span></p>");
}); 
// save the info we need to use later for the side_bar
gmarkers[i] = marker;
//htmls[i] = ("<b>" + siteaddress + "</b>");
htmls[i] = ("<p align=left class=content style=width:250px;><b>"+ maphonor +"<br><span class=balloon>Location:</b> " + maploc + "<br><b>Donor:</b> " + mapdonor + "<br><b>Species:</b> " + mapspecies + "<br><b>Planting Date:</b> " + mapplantdate +"<br><i>" + mapdedi +"</i></span></p>");
// add a line to the side_bar html
side_bar_html += '<p style=margin-top:5px;margin-bottom:5px;><a href="javascript:myclick(' + i + ')">'  + maphonor + '</a></p>';
//side_bar_html += '<p style=margin-top:5px;margin-bottom:5px;><a class=subnav href="javascript:myclick(' + i + ')">'  + maphonor + '</a></p>';
i++;
return marker;
}





// This function picks up the click and opens the corresponding info window
function myclick(i) {
gmarkers[i].openInfoWindowHtml(htmls[i]);
}


// create the map
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());	
map.setCenter(new GLatLng( 45.661567,-122.648621), 12);


// Read the data from example.xml
var request = GXmlHttp.create();
request.open("GET", "/mapdataWitTrees.asp", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
 var xmlDoc = request.responseXML;
 // obtain the array of markers and loop through it
 var markers = xmlDoc.documentElement.getElementsByTagName("marker");
 
 for (var i = 0; i < markers.length; i++) {
   // obtain the attribues of each marker
   var lat = parseFloat(markers[i].getAttribute("lat"));
   var lng = parseFloat(markers[i].getAttribute("lng"));
   var point = new GLatLng(lat,lng);
var mapdonor = markers[i].getAttribute("donor");
   var maploc = markers[i].getAttribute("location");
   var maphonor = markers[i].getAttribute("honor");
var mapspecies = markers[i].getAttribute("species");
   var mapplantdate = markers[i].getAttribute("plantdate");
   var mapdedi = markers[i].getAttribute("dedi");	
   var mapphoto = markers[i].getAttribute("picture");		
   // create the marker
   if (mapphoto ||""){
   var marker = createMarker(point,i,mapdonor,maploc,maphonor,mapspecies,mapplantdate,mapdedi,mapphoto);
   }else{
   var marker = createMarkerNoPic(point,i,mapdonor,maploc,maphonor,mapspecies,mapplantdate,mapdedi,mapphoto);
   }
   map.addOverlay(marker);
 }
 // put the assembled side_bar_html contents into the side_bar div
 document.getElementById("side_bar").innerHTML = side_bar_html;
}
}
request.send(null);

//  ======== Add a map overview ==========
//  ======== save a reference to the control =========
//var ovcontrol = new GOverviewMapControl(new GSize(150,150)); 
//map.addControl(ovcontrol);
//  ======== A function to adjust the positioning of the overview ========
//function positionOverview(x,y) {
//var omap=document.getElementById("map_overview");
//omap.style.left = x+"px";
//omap.style.top = y+"px";     
// == restyling ==
//omap.firstChild.style.border = "1px solid gray";
//omap.firstChild.firstChild.style.left="1px";
//omap.firstChild.firstChild.style.top="1px";
//omap.firstChild.firstChild.style.width="146px";
//omap.firstChild.firstChild.style.height="146px";
//}

// ======== get a reference to the GMap2 ===========
// var ovmap = ovcontrol.getOverviewMap();     
// GEvent.addListener(ovmap,"click",function() {alert("you clicked the overview");} );
//  ======== Cause the overview to be positioned AFTER IE sets its initial position ======== 
//setTimeout("positionOverview(250,250)",1);   
//  ======== change the overview map type AFTER the overview finisges initializing =====
// setTimeout("ovmap.setMapType(G_SATELLITE_MAP);",1);

}else {
alert("Sorry, the Google Maps API is not compatible with this browser");
}
// This Javascript is based on code provided by the
// Blackpool Community Church Javascript Team
// http://www.commchurch.freeserve.co.uk/   
// http://www.econym.demon.co.uk/googlemaps/

//]]>
