//<![CDATA[

if (GBrowserIsCompatible()) {
// this variable will collect the html which will eventualkly be placed in the side_bar
var menu_html = "";
var menu_bench ="";

// 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;
var myicons =[];
   myicons["62239"] = new GIcon(G_DEFAULT_ICON, "http://www.cityofvancouver.us/parks-recreation/benchmap/iconr.png");		  
   myicons["62240"] = new GIcon(G_DEFAULT_ICON, "http://www.cityofvancouver.us/parks-recreation/benchmap/iconb.png");
   myicons["62241"] = new GIcon(G_DEFAULT_ICON, "http://www.cityofvancouver.us/parks-recreation/benchmap/icong.png"); 


// A function to create the marker and set up the event window
function createMarker(point,index,mapinscription,maploc,mapname,mapphoto,mapphoto2,benchtype,icontype) {

var marker = new GMarker(point, myicons[icontype]);

GEvent.addListener(marker, "click", function() {
 marker.openInfoWindowTabsHtml([new GInfoWindowTab("Info", "<p align=center style=width:325px;><b>"+ mapinscription +"</b></p><br><p align=left style=width:300px;><b>Location:</b> " + maploc + "<br><br><b>Inscription: </b><br><p align=center style=width:300px;><i> " + mapname + " </i></p><br><b><p align=left style=width:300px;>Bench type: </b>" + benchtype + "<br><br><a href=http://maps.google.com/maps?saddr=&daddr=" + point.toUrlValue() + " target =_blank>Click for Directions<\/a></p>"),
new GInfoWindowTab("Photo","<p align=center style=width:325px;><b>"+ mapinscription +"</b><br><br><br><img align=center src=/upload/contents/987/"+ mapphoto +"></p>"), 
 new GInfoWindowTab("Photo2", "<p align=center style=width:325px;><b>"+ mapinscription +"</b><br><br><br><img align=center src=/upload/contents/987/"+ mapphoto2 +"></p>")]);
});

// save the info we need to use later for the side_bar
gmarkers[i] = marker;
htmls[i] = ([new GInfoWindowTab("Info", "<p align=center style=width:325px;><b>"+ mapinscription +"</b></p><br><p align=left style=width:300px;><b>Location:</b> " + maploc + "<br><br><b>Inscription: </b><br><p align=center style=width:300px;><i> " + mapname + " </i></p><br><b><p align=left style=width:300px;>Bench type: </b>" + benchtype + "<br><br><a href=http://maps.google.com/maps?saddr=&daddr=" + point.toUrlValue() + " target =_blank>Click for Directions<\/a></p>"),
new GInfoWindowTab("Photo","<p align=center style=width:325px;><b>"+ mapinscription +"</b><br><br><br><img align=center src=/upload/contents/987/"+ mapphoto +"></p>"), 
 new GInfoWindowTab("Photo2", "<p align=center style=width:325px;><b>"+ mapinscription +"</b><br><br><br><img align=center src=/upload/contents/987/"+ mapphoto2 +"></p>")]);

// add a line to the side_bar html
menu_html += '<p style=margin-top:5px;margin-bottom:5px;><a href="javascript:myclick(' + i + ')">'  + mapinscription + '</a></p>';
i++;
return marker;
}

// A function to create the for undedicated benches marker and set up the event window
function createMarkerBench(point,index,mapinscription,maploc,mapname,mapphoto,mapphoto2,benchtype,icontype) {

var marker = new GMarker(point, myicons[icontype]);

GEvent.addListener(marker, "click", function() {
 marker.openInfoWindowTabsHtml([new GInfoWindowTab("Info", "<p align=center style=width:325px;><b>"+ mapinscription +"</b></p><br><p align=left style=width:300px;><b>Location:</b> " + maploc + "<br><br><b>Information: </b><br><p align=center style=width:300px;><i> " + mapname + " </i></p><br><b><a href=http://www.cityofvancouver.us/parks-recreation/how_to_help/BenchDonationForm.pdf target =_blank>Click here</a> to download a bench donation form</b><br><b><p align=left style=width:300px;>Bench type: </b>" + benchtype + "<br><br><a href=http://maps.google.com/maps?saddr=&daddr=" + point.toUrlValue() + " target =_blank>Click for Directions<\/a></p>"),
 new GInfoWindowTab("Photo","<p align=center style=width:325px;><b>"+ mapinscription +"</b><br><br><br><img align=center src=/upload/contents/987/"+ mapphoto +"></p>"), 
 new GInfoWindowTab("Photo2", "<p align=center style=width:325px;><b>"+ mapinscription +"</b><br><br><br><img align=center src=/upload/contents/987/"+ mapphoto2 +"></p>")]);
});

// save the info we need to use later for the side_bar
gmarkers[i] = marker;
htmls[i] = ([new GInfoWindowTab("Info", "<p align=center style=width:325px;><b>"+ mapinscription +"</b></p><br><p align=left style=width:300px;><b>Location:</b> " + maploc + "<br><br><b>Information: </b><br><p align=center style=width:300px;><i> " + mapname + " </i></p><br><b><a href=http://www.cityofvancouver.us/parks-recreation/how_to_help/BenchDonationForm.pdf target =_blank>Click here</a> to download a bench donation form </b><br><b><p align=left style=width:300px;>Bench type: </b>" + benchtype + "<br><br><a href=http://maps.google.com/maps?saddr=&daddr=" + point.toUrlValue() + " target =_blank>Click for Directions<\/a></p>"),
new GInfoWindowTab("Photo","<p align=center style=width:325px;><b>"+ mapinscription +"</b><br><br><br><img align=center src=/upload/contents/987/"+ mapphoto +"></p>"), 
 new GInfoWindowTab("Photo2", "<p align=center style=width:325px;><b>"+ mapinscription +"</b><br><br><br><img align=center src=/upload/contents/987/"+ mapphoto2 +"></p>")]);

// add a line to the side_bar html
menu_bench += '<p style=margin-top:5px;margin-bottom:5px;><a href="javascript:myclick(' + i + ')">'  + mapinscription + '</a></p>';
i++;
return marker;
}

// This function picks up the click and opens the corresponding info window
function myclick(i) {
gmarkers[i].openInfoWindowTabsHtml(htmls[i]);
}


// create the map
var map = new GMap2(document.getElementById("map"));
map.setMapType(G_SATELLITE_MAP);
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());	
map.setCenter(new GLatLng( 45.646598,-122.628837), 11);


// Read the data from example.xml
var request = GXmlHttp.create();
request.open("GET", "/stage/mapdataParkBenches.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 mapinscription = markers[i].getAttribute("name");
   var maploc = markers[i].getAttribute("location");
   var mapname = markers[i].getAttribute("name2");
   var mapphoto = markers[i].getAttribute("photo01");
   var mapphoto2 = markers[i].getAttribute("photo02");
   var benchtype = markers[i].getAttribute("type");
   var icontype = markers[i].getAttribute("icontype");
	
   // create the marker
   if (benchtype=="Dedicated"){
   var marker = createMarker(point,i,mapinscription,maploc,mapname,mapphoto,mapphoto2,benchtype,icontype);
   }else{
   var marker = createMarkerBench(point,i,mapinscription,maploc,mapname,mapphoto,mapphoto2,benchtype,icontype);
   } 
   map.addOverlay(marker); 
   }
  
 // put the assembled side_bar_html contents into the side_bar div
 document.getElementById("map_menu").innerHTML = menu_html;
 document.getElementById("map_bench").innerHTML = menu_bench;
 
}
}
request.send(null);

}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/

//]]>