function downloadURL(url,callback) {
 var request = window.ActiveXObject ?
     new ActiveXObject('Microsoft.XMLHTTP') :
     new XMLHttpRequest;

 request.onreadystatechange = function() {
   if (request.readyState == 4) {
   	request.onreadystatechange = doNothing;
     callback(request.responseText, request.status);
   }
 };

 request.open('GET', url, true);
 request.send(null);
}

function initialize(what) {
    var latlng = new google.maps.LatLng(47.0137235, -121.38759);
    var myOptions = {
      zoom: 9,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.TERRAIN
    };
    var map = new google.maps.Map(document.getElementById("google-map"), myOptions);
	var infoWindow = new google.maps.InfoWindow();

	
		var bywayCoordinates = [
			new google.maps.LatLng(47.19951070111655, -121.99270248413086),
			new google.maps.LatLng(47.19846097658329, -121.95167541503906),
			new google.maps.LatLng(47.19502006723379, -121.94334983825684),
			new google.maps.LatLng(47.194757615837034, -121.93905830383301),
			new google.maps.LatLng(47.175274266352, -121.91648483276367),
			new google.maps.LatLng(47.1748366838986, -121.91596984863281),
			new google.maps.LatLng(47.167076289455316, -121.9123649597168),
			new google.maps.LatLng(47.16480047006409, -121.90858840942383),
			new google.maps.LatLng(47.16138655815783, -121.87159538269043),
			new google.maps.LatLng(47.15695106290956, -121.86460018157959),
			new google.maps.LatLng(47.15274867322154, -121.8513822555542),
			new google.maps.LatLng(47.154645626381935, -121.84232711791992),
			new google.maps.LatLng(47.15841014826666, -121.83739185333252),
			new google.maps.LatLng(47.159519026341705, -121.83168411254883),
			new google.maps.LatLng(47.1596357490034, -121.82507514953613),
			new google.maps.LatLng(47.1654132002611, -121.81717872619629),
			new google.maps.LatLng(47.17013973851096, -121.80567741394043),
			new google.maps.LatLng(47.177199586310074, -121.79267406463623),
			new google.maps.LatLng(47.177637149292195, -121.78833961486816),
			new google.maps.LatLng(47.16798075470127, -121.76220417022705),
			new google.maps.LatLng(47.16710546599395, -121.75864219665527),
			new google.maps.LatLng(47.16477129225937, -121.75443649291992),
			new google.maps.LatLng(47.16474211443864, -121.74654006958008),
			new google.maps.LatLng(47.16515060247067, -121.74370765686035),
			new google.maps.LatLng(47.161007221070435, -121.73499584197998),
			new google.maps.LatLng(47.16045280045528, -121.73293590545654),
			new google.maps.LatLng(47.15788488215373, -121.72679901123047),
			new google.maps.LatLng(47.15417869034799, -121.71117782592773),
			new google.maps.LatLng(47.15336154241617, -121.68105125427246),
			new google.maps.LatLng(47.16033607958857, -121.66362762451172),
			new google.maps.LatLng(47.15925639941538, -121.65950775146484),
			new google.maps.LatLng(47.13284117447684, -121.61963939666748),
			new google.maps.LatLng(47.12084053349137, -121.61238670349121),
			new google.maps.LatLng(47.11073570504796, -121.59882545471191),
			new google.maps.LatLng(47.10349175724812, -121.59195899963379),
			new google.maps.LatLng(47.09034497979293, -121.58380508422852),
			new google.maps.LatLng(47.078480879640374, -121.58208847045898),
			new google.maps.LatLng(47.07760411715964, -121.5816593170166),
			new google.maps.LatLng(47.072577067131725, -121.57749652862549),
			new google.maps.LatLng(47.07029720210547, -121.57680988311768),
			new google.maps.LatLng(47.07029720210547, -121.57680988311768),
			new google.maps.LatLng(47.059071829257995, -121.57410621643066),
			new google.maps.LatLng(47.055446464379415, -121.5735912322998),
			new google.maps.LatLng(47.05410150827661, -121.57294750213623),
			new google.maps.LatLng(47.05047580546931, -121.57058715820312),
			new google.maps.LatLng(47.045914087305235, -121.57020092010498),
			new google.maps.LatLng(47.040065159975796, -121.56736850738525),
			new google.maps.LatLng(47.03055928538565, -121.55539512634277),
			new google.maps.LatLng(47.029476970760776, -121.55196189880371),
			new google.maps.LatLng(47.029301458212984, -121.54788494110107),
			new google.maps.LatLng(47.02216345896305, -121.53350830078125),
			new google.maps.LatLng(47.01868187535621, -121.531662940979),
			new google.maps.LatLng(47.013561487034586, -121.52788639068604),
			new google.maps.LatLng(47.00782606920755, -121.52677059173584),
			new google.maps.LatLng(47.00448987962417, -121.52848720550537),
			new google.maps.LatLng(46.998226645262676, -121.52904510498047),
			new google.maps.LatLng(46.98654697185567, -121.53496742248535),
			new google.maps.LatLng(46.9771486900495, -121.53664112091064),
			new google.maps.LatLng(46.974894027856436, -121.53608322143555),
			new google.maps.LatLng(46.9649372399624, -121.52998924255371),
			new google.maps.LatLng(46.96051466035348, -121.52612686157227),
			new google.maps.LatLng(46.957029058564686, -121.52599811553955),
			new google.maps.LatLng(46.95409980585234, -121.52925968170166),
			new google.maps.LatLng(46.94607283183003, -121.53260707855225),
			new google.maps.LatLng(46.93593486004237, -121.53106212615967),
			new google.maps.LatLng(46.93168571723241, -121.5311050415039),
			new google.maps.LatLng(46.92670353424041, -121.53209209442139),
			new google.maps.LatLng(46.92435881718097, -121.53342247009277),
			new google.maps.LatLng(46.922834696057336, -121.53372287750244),
			new google.maps.LatLng(46.90855861085619, -121.53762817382812),
			new google.maps.LatLng(46.901521769445786, -121.54333591461182),
			new google.maps.LatLng(46.899615799267224, -121.5441083908081),
			new google.maps.LatLng(46.895129171247255, -121.54492378234863),
			new google.maps.LatLng(46.88809056706902, -121.54161930084229),
			new google.maps.LatLng(46.884952224984445, -121.54101848602295),
			new google.maps.LatLng(46.88237102099698, -121.5406322479248),
			new google.maps.LatLng(46.881080372430645, -121.53964519500732),
			new google.maps.LatLng(46.87876299367752, -121.53943061828613),
			new google.maps.LatLng(46.87503737754022, -121.54093265533447),
			new google.maps.LatLng(46.87324781641195, -121.5393877029419),
			new google.maps.LatLng(46.86726262110416, -121.54037475585938),
			new google.maps.LatLng(46.866323706379085, -121.53689861297607),
			new google.maps.LatLng(46.86911106147555, -121.53101921081543),
			new google.maps.LatLng(46.86705723491137, -121.5249252319336),
			new google.maps.LatLng(46.865120697886695, -121.52355194091797),
			new google.maps.LatLng(46.86547280072387, -121.52243614196777),
			new google.maps.LatLng(46.86729196192468, -121.52346611022949),
			new google.maps.LatLng(46.86831888053939, -121.52647018432617),
			new google.maps.LatLng(46.869991248803316, -121.52960300445557),
			new google.maps.LatLng(46.86826020000493, -121.53655529022217),
			new google.maps.LatLng(46.86881766249205, -121.5371561050415),
			new google.maps.LatLng(46.871194148141484, -121.52981758117676),
			new google.maps.LatLng(46.870431337054406, -121.5269422531128),
			new google.maps.LatLng(46.869052381807144, -121.52333736419678),
			new google.maps.LatLng(46.86937511918946, -121.52084827423096),
			new google.maps.LatLng(46.869023041948886, -121.51990413665771),
			new google.maps.LatLng(46.86708657584417, -121.51767253875732),
			new google.maps.LatLng(46.86849492175781, -121.51531219482422),
			new google.maps.LatLng(46.87040199794994, -121.51501178741455),
			new google.maps.LatLng(46.87198628664146, -121.51587009429932),
			new google.maps.LatLng(46.87313046605634, -121.51578426361084),
			new google.maps.LatLng(46.87618149190609, -121.51780128479004),
			new google.maps.LatLng(46.878381643279624, -121.5153980255127),
			new google.maps.LatLng(46.885480183227706, -121.50660037994385),
			new google.maps.LatLng(46.88847184845812, -121.49934768676758),
			new google.maps.LatLng(46.89419074406144, -121.47913455963135),
			new google.maps.LatLng(46.89595028156382, -121.46724700927734),
			new google.maps.LatLng(46.89685935331996, -121.45754814147949),
			new google.maps.LatLng(46.89841353707594, -121.44390106201172),
			new google.maps.LatLng(46.90594922325753, -121.4272928237915),
			new google.maps.LatLng(46.90779633098373, -121.42119884490967),
			new google.maps.LatLng(46.91014177287571, -121.41622066497803),
			new google.maps.LatLng(46.91052289748913, -121.4119291305542),
			new google.maps.LatLng(46.91357179683157, -121.40853881835938),
			new google.maps.LatLng(46.913864951089195, -121.40562057495117),
			new google.maps.LatLng(46.91348385024156, -121.40257358551025),
			new google.maps.LatLng(46.914627144654055, -121.39609336853027),
			new google.maps.LatLng(46.915037552083454, -121.38283252716064),
			new google.maps.LatLng(46.916972287629385, -121.37429237365723),
			new google.maps.LatLng(46.920167379753245, -121.36871337890625),
			new google.maps.LatLng(46.924798459447075, -121.36648178100586),
			new google.maps.LatLng(46.926967308487264, -121.3636064529419),
			new google.maps.LatLng(46.93189085600978, -121.36021614074707),
			new google.maps.LatLng(46.94129709005844, -121.3375997543335),
			new google.maps.LatLng(46.94627791549408, -121.32378101348877),
			new google.maps.LatLng(46.946600188235834, -121.31983280181885),
			new google.maps.LatLng(46.94865096931496, -121.31661415100098),
			new google.maps.LatLng(46.96288708295219, -121.27357006072998),
			new google.maps.LatLng(46.966079436215715, -121.25799179077148),
			new google.maps.LatLng(46.966694454865916, -121.25567436218262),
			new google.maps.LatLng(46.966518735973104, -121.24121189117432),
			new google.maps.LatLng(46.9671923219275, -121.23867988586426),
			new google.maps.LatLng(46.96678231409586, -121.23619079589844),
			new google.maps.LatLng(46.96766089845829, -121.23241424560547),
			new google.maps.LatLng(46.96851018295806, -121.22155666351318),
			new google.maps.LatLng(46.96754375471042, -121.21868133544922),
			new google.maps.LatLng(46.967865899399754, -121.21318817138672),
			new google.maps.LatLng(46.96982801151942, -121.20885372161865),
			new google.maps.LatLng(46.97091153512389, -121.20336055755615),
			new google.maps.LatLng(46.974074127125476, -121.19653701782227),
			new google.maps.LatLng(46.97351775875602, -121.19323253631592),
			new google.maps.LatLng(46.974425514692285, -121.18825435638428),
			new google.maps.LatLng(46.97747077688814, -121.17932796478271),
			new google.maps.LatLng(46.977324374020185, -121.17555141448975),
			new google.maps.LatLng(46.97817350507456, -121.16782665252686),
			new google.maps.LatLng(46.97875910484173, -121.16409301757812),
			new google.maps.LatLng(46.97808566455633, -121.15765571594238),
			new google.maps.LatLng(46.98192123275911, -121.14010334014893),
			new google.maps.LatLng(46.98092576821479, -121.12761497497559),
			new google.maps.LatLng(46.982214012921226, -121.12452507019043),
			new google.maps.LatLng(46.98423415234012, -121.12298011779785),
			new google.maps.LatLng(46.98596145738746, -121.11658573150635),
			new google.maps.LatLng(46.987161755144875, -121.11401081085205),
			new google.maps.LatLng(46.98645914509428, -121.11062049865723),
			new google.maps.LatLng(46.98768870662217, -121.10474109649658),
			new google.maps.LatLng(46.98763015671457, -121.10233783721924),
			new google.maps.LatLng(46.9879229056113, -121.10135078430176),
			new google.maps.LatLng(46.98801072996765, -121.09924793243408),
			new google.maps.LatLng(46.98941590004456, -121.09671592712402),
			new google.maps.LatLng(46.989386626044755, -121.09491348266602),
			new google.maps.LatLng(46.98642986947511, -121.09178066253662),
			new google.maps.LatLng(46.98525883155992, -121.09148025512695),
			new google.maps.LatLng(46.98329728557978, -121.09362602233887),
			new google.maps.LatLng(46.97158506576047, -121.0951280593872),
			new google.maps.LatLng(46.96974015729214, -121.09396934509277),
			new google.maps.LatLng(46.967807327782374, -121.09006404876709),
			new google.maps.LatLng(46.96092471622404, -121.08156681060791),
			new google.maps.LatLng(46.95887440544368, -121.07954978942871),
			new google.maps.LatLng(46.95661897283783, -121.07585906982422),
			new google.maps.LatLng(46.9526058252274, -121.07173919677734),
			new google.maps.LatLng(46.94973492185848, -121.07070922851562),
			new google.maps.LatLng(46.947303322028546, -121.07058048248291),
			new google.maps.LatLng(46.94545757612362, -121.0689926147461),
			new google.maps.LatLng(46.942556989687844, -121.06452941894531),
			new google.maps.LatLng(46.9348506280539, -121.05787754058838),
			new google.maps.LatLng(46.93388359181351, -121.05659008026123),
			new google.maps.LatLng(46.93279931829315, -121.05392932891846),
			new google.maps.LatLng(46.92901884162397, -121.04800701141357),
			new google.maps.LatLng(46.9266449175647, -121.04616165161133),
			new google.maps.LatLng(46.92497431534325, -121.04607582092285),
			new google.maps.LatLng(46.92142777653395, -121.04783535003662),
			new google.maps.LatLng(46.920167379753245, -121.04689121246338),
			new google.maps.LatLng(46.91788100294214, -121.0429859161377),
			new google.maps.LatLng(46.91626875551309, -121.0407543182373),
			new google.maps.LatLng(46.91506686677956, -121.03920936584473),
			new google.maps.LatLng(46.911578305351505, -121.03135585784912),
			new google.maps.LatLng(46.91043494589581, -121.02981090545654),
			new google.maps.LatLng(46.90882247444014, -121.02835178375244),
			new google.maps.LatLng(46.90509894592733, -121.02169990539551),
			new google.maps.LatLng(46.903310387522716, -121.01959705352783),
			new google.maps.LatLng(46.90125786992386, -121.01341724395752),
			new google.maps.LatLng(46.89979173781454, -121.01101398468018),
			new google.maps.LatLng(46.89753381595433, -121.00603580474854),
			new google.maps.LatLng(46.895422426375056, -121.00316047668457),
			new google.maps.LatLng(46.89292970667084, -121.00127220153809),
			new google.maps.LatLng(46.88946903312354, -120.99453449249268),
			new google.maps.LatLng(46.888677152698854, -120.98758220672607),
			new google.maps.LatLng(46.88776794223829, -120.98711013793945),
			new google.maps.LatLng(46.8853628596227, -120.98702430725098),
			new google.maps.LatLng(46.883837629407154, -120.98320484161377),
			new google.maps.LatLng(46.876797543383994, -120.97869873046875),
			new google.maps.LatLng(46.871839595208726, -120.97251892089844),
			new google.maps.LatLng(46.86925776036587, -120.96410751342773),
			new google.maps.LatLng(46.865912926022624, -120.95771312713623),
			new google.maps.LatLng(46.8591639415662, -120.95299243927002),
			new google.maps.LatLng(46.85546631211513, -120.95333576202393),
			new google.maps.LatLng(46.85435110405115, -120.95316410064697),
			new google.maps.LatLng(46.84921497852343, -120.94973087310791),
			new google.maps.LatLng(46.84578083777056, -120.94925880432129),
			new google.maps.LatLng(46.83876511579068, -120.94316482543945),
			new google.maps.LatLng(46.82373253571862, -120.93132019042969),
			new google.maps.LatLng(46.82120711959769, -120.93020439147949),
			new google.maps.LatLng(46.816713934865724, -120.92501163482666),
			new google.maps.LatLng(46.81448188653193, -120.92278003692627),
			new google.maps.LatLng(46.809165714146474, -120.92003345489502),
			new google.maps.LatLng(46.80796142530417, -120.91805934906006),
			new google.maps.LatLng(46.80044135348102, -120.90406894683838),
			new google.maps.LatLng(46.79430114040335, -120.87960720062256),
			new google.maps.LatLng(46.791421756131214, -120.8735990524292),
			new google.maps.LatLng(46.786514695338944, -120.86673259735107),
			new google.maps.LatLng(46.784281393803504, -120.8660888671875),
			new google.maps.LatLng(46.78148963659166, -120.86467266082764),
			new google.maps.LatLng(46.772966534871735, -120.85192680358887),
			new google.maps.LatLng(46.768763267393645, -120.83986759185791),
			new google.maps.LatLng(46.76482424351172, -120.82810878753662),
			new google.maps.LatLng(46.76300161260514, -120.82750797271729),
			new google.maps.LatLng(46.760502744206356, -120.8296537399292),
			new google.maps.LatLng(46.758856367575504, -120.82888126373291),
			new google.maps.LatLng(46.75550465970302, -120.8218002319336),
			new google.maps.LatLng(46.752476182962745, -120.81785202026367),
			new google.maps.LatLng(46.75074134777678, -120.81274509429932),
			new google.maps.LatLng(46.748477156842746, -120.7975959777832),
			new google.maps.LatLng(46.748271316586894, -120.7882833480835),
			new google.maps.LatLng(46.74880061851377, -120.7813310623169),
			new google.maps.LatLng(46.74777141555009, -120.77343463897705),
			new google.maps.LatLng(46.72827165883371, -120.70034980773926)
	  ];
	  var byway = new google.maps.Polyline({
		path: bywayCoordinates,
		strokeColor: "#FDDD03",
		strokeOpacity: 1.0,
		strokeWeight: 2
	  });
	
	  byway.setMap(map);

	
	downloadURL("GoogleMap/phpsqlajax.genxml.php?what="+what,function(data) {
        var xml = parseXml(data);
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
			//We have two types of markers - this deals with the "regular" kind
			if(markers[i].getAttribute("icon") != 'camera.png'){
				  var id = markers[i].getAttribute("id");
				  var name = markers[i].getAttribute("name");
				  var category = markers[i].getAttribute("category");
				  var milepost = markers[i].getAttribute("milepost");
				  var photo = markers[i].getAttribute("photo");
				  if(photo == ""){photo = "<p>";}else{photo="<p><div style='display:inline; float:left; margin-right: 10px;'><img src='GoogleMap/thumb/"+photo+"' border='0'></div>"};
				  var point = new google.maps.LatLng(
					  parseFloat(markers[i].getAttribute("lat")),
					  parseFloat(markers[i].getAttribute("lng")));
				  var description = markers[i].getAttribute("description");
				  var contactinformation = markers[i].getAttribute("contactinformation");
				  var ic = markers[i].getAttribute("icon");
				  var icon = "GoogleMap/icons/photos/"+ic;
				  var shadow = getShadow(ic);
				  shadow = "GoogleMap/icons/photos/"+shadow;
				  var html = "<h2 style='text-align:center;'>"+name+"</h2>"+photo+description.substring(0,250)+" ... <a href='detail.php?id="+id+"'>read more</a></p>";
				  var marker = new google.maps.Marker({
					map: map,
					position: point,
					icon: icon,
					shadow: shadow
				  });//close var marker
				  bindInfoWindow(marker, map, infoWindow, html);
			} else {
				
				//Here we are dealing with the 360 camera listings, which are a little different	
				  var id = markers[i].getAttribute("id");
				  var name = markers[i].getAttribute("name");
				  var url = markers[i].getAttribute("description");
				  var milepost = markers[i].getAttribute("milepost");
				  var photo = markers[i].getAttribute("photo");
				  if(photo == ""){photo = "<div>";}else{photo="<div style='text-align: center;'><img src='"+photo+"' border='0'>"};
				  var point = new google.maps.LatLng(
					  parseFloat(markers[i].getAttribute("lat")),
					  parseFloat(markers[i].getAttribute("lng")));
				  var ic = markers[i].getAttribute("icon");
				  var icon = "GoogleMap/icons/photos/"+ic;
				  var html = "<h2 style='text-align: center;'>"+name+"</h2><a href='"+url+"'>"+photo+"</a><br /> <em>click photo to see 360 view</em></div>";
				  	var marker = new google.maps.Marker({
					map: map,
					position: point,
					icon: icon
				  });//close var marker
				  bindInfoWindow(marker, map, infoWindow, html);

			}//close the if/then
        }//close the for()
      });//close downloadURL
    }


function getShadow(icon){
	var data = "";
	switch(icon){
		case 'campground.png':
			data = 'campground.shadow.png';
		break;
		case 'hiker.png':
			data = 'hiker.shadow.png';
		break;
		case 'blue-dot.png':
			data = 'msmarker.shadow.png';
		break;
	
	
	}
return data;
}

function bindInfoWindow(marker, map, infoWindow, html) {
  google.maps.event.addListener(marker, 'click', function() {
    infoWindow.setContent(html);
    infoWindow.open(map, marker);
  });
}

    function parseXml(str) {
      if (window.ActiveXObject) {
        var doc = new ActiveXObject('Microsoft.XMLDOM');
        doc.loadXML(str);
        return doc;
      } else if (window.DOMParser) {
        return (new DOMParser).parseFromString(str, 'text/xml');
      }
    }

    function doNothing() {}


