
//<![CDATA[
	// Google Maps interface for UNAVCO Member Institutions   
	// Author: Jim Riley
	// Date: 10-13-2005
	// Modified: 10-17-2005, 3-1-2006, 5-24-2006 (Upgrade to rev2 API + enhancements)
	
	//To Do:	Write code to count members
	//			Write code to create table listing from xml, allow user to select link from table and have it center/zoom map and open
	//				infowindow location
	//			Have Susan J. output xml file

var map;
var gmarkers = [];
var htmls = [];
var table_html_1 = "";
var table_html_2 = "";

window.onload = createMap;
window.onunload = GUnload();

// This function picks up the click and opens the corresponding info window
function myclick(i) {
	gmarkers[i].openInfoWindowHtml(htmls[i]);	
}

function zoomZoom(inout) {
	if(inout==1){
		var zoomChange=1;
	}else if(inout==0) {
		var zoomChange=-1;
	} else{
		return null;
	}
	map.setZoom(map.getZoom() + zoomChange);				
}

function createMap(){
	if (GBrowserIsCompatible()) {
		var sidebar_html = "";    
		var i = 0;
		var a = 0;
		table_html_1 += '<table cellpadding="6"><tbody><tr valign="top" align="left" bgcolor="#c0c0c0"><th>Institution</th><th>Representative</th><th>E-mail</th></tr>';
		table_html_2 += '<p><br></p><h3>UNAVCO Associate Members</h3><table cellpadding="6"><tbody><tr valign="top" align="left" bgcolor="#c0c0c0"><th>Institution</th><th>Representative</th><th>E-mail</th></tr>';
	   
		// Creates a marker whose info window displays the given html for that marker
		function createMarker(point, label, html) {
			//end of information window construction from GDownloadUrl function
			//this adds a paragraph ender to make sure we're xhtml compliant
			html += "\<div style\='font-size:10px'\>\<a href\=\'javascript:zoomZoom\(1\)\'\>Zoom In\<\/a\>\/ \<a href\=\'javascript:zoomZoom\(0\)\'\>Zoom Out\<\/a\> on this institution\<\/div\>\<\/p\>"	
			
			// FF 1.5 fix
			html = '<div style="white-space:nowrap;">' + html + '</div>';
			//
			var marker = new GMarker(point, {title:label});	
			GEvent.addListener(marker, "click", function() {
			  marker.openInfoWindowHtml(html);
			});
			gmarkers[i] = marker;
			htmls[i] = html;
			if (i==0){
				sidebar_html += 'UNAVCO Members\&nbsp\;\<\/h3\>\<p style\=\"font-style\: italic\; text\-align\: center\; font\-size\: 10px\; margin-top\: 0px\; margin\-bottom\: 5px\;">(F) = Founding Member</p>\<p style\=\"margin-top\: 0px\; margin\-bottom\: 5px\;\"\>\<a style\=\"text-decoration: none; font\-family\: Arial\, Helvetica\, sans-serif\; font\-size\: 11px\;\" href\=\"javascript\:myclick\(' + i + '\)\"\>' + label + '\<\/a\>\<\/p\>';
			} else {
				sidebar_html += '\<p style\=\"margin-top\: 0px\; margin\-bottom\: 5px\;"\>\<a style\=\"text-decoration: none; font\-family\: Arial\, Helvetica\, sans-serif\; font\-size\: 11px\;\" href\=\"javascript\:myclick\(' + i + '\)\"\>' + label + '\<\/a\>\<\/p\>';
			}
			i++;
		
			map.addOverlay(marker);
		}		
		
		
		// Create the map, center it and set zoom level
		// map = new GMap2(document.getElementById("map")); old way not good for including maps with significant other non-map content
		var m = document.getElementById("map");
		//take in zoom level parameter set by comment in map div
		if (m.firstChild && m.firstChild.nodeType == 8) {
			// 8 means Node.COMMENT_NODE.  We're using numeric values because IE6 does not support constant names.
			var zoomInit = parseInt(m.firstChild.data);			
		}		
		//
    map = new GMap2(m);
		map.addMapType(G_SATELLITE_3D_MAP);
		map.enableScrollWheelZoom();
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		//map.addControl(new GScaleControl( ));
		map.setCenter(new GLatLng(35, 6), zoomInit, G_HYBRID_MAP);
		
		// Read the data in member-data.xml and load it on the map. 
		// Lat and Lon should be in decimal degrees... I can add some math to convert degrees, minutes, seconds to decimal degrees
		//The format we expect is:
		// <markers>
		//   <members>
		//    	<marker lat="31.548025204819144" lng="-97.11333632469177" institution="Baylor University" rep="V. Cronin" email="Vince_Cronin@baylor.edu" web="http://www.baylor.edu/csr/" membertype="Member Institution" founder="no" />
		//	 </members>
		//	 <associates>
		//			<marker lat="31.548025204819144" lng="-97.11333632469177" institution="Baylor University" rep="V. Cronin" email="Vince_Cronin@baylor.edu" web="http://www.baylor.edu/csr/" membertype="Member Institution" founder="no" />
		//	 </associates>
		// </markers>
		GDownloadUrl("member-data.xml", function(data, responseCode) {		
			var xmlDoc = GXml.parse(data);
			var markers = xmlDoc.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {
				var lat = parseFloat(markers[i].getAttribute("lat"));
				var lon = parseFloat(markers[i].getAttribute("lng"));
				var point = new GLatLng(lat,lon);
				var institute = markers[i].getAttribute("institution");
				var web = markers[i].getAttribute("web");
				var membertype = markers[i].getAttribute("membertype");
				if (markers[i].getAttribute("web")!= null) {
					var web = markers[i].getAttribute("web");
				}
				var rep = markers[i].getAttribute("rep");
				var email = markers[i].getAttribute("email"); 
					// using reg exp to remove @ sign and replace with "(at)"
					email = email.replace(/\@/, '<img src="/lib/images/at.gif" alt="" width="14" height="12" border="0">');
				var founder = markers[i].getAttribute("founder");
				if ((founder == "Yes") || (founder == "yes")) {
					institute += "--(F\)";
				}				
				else { html += "\<br \/\>";
				};
				// Begin building table listing
				//if (((i + 1) % 2) == 0) {var rowColor = "#eeeeee"} else {var rowColor = "#ffffff"};
				var rowColor = "#eeeeee"
				if (membertype == "Member Institution") {
					table_html_1 += '<tr valign="top" bgcolor="' + rowColor + '"><td><a href="' + web + '" target="_blank">' + institute + '</a></td><td>' + rep + '</td><td>' + email + '</td></tr>';
				}
				else if (membertype != "Member Institution" && a == 0){  
					sidebar_html += '<h4 style="margin\-top\: 10px\; margin\-bottom\: 4px\; background\-color\: Silver\;">UNAVCO Associate Members\&nbsp\;</h4>';
					table_html_2 += '<tr valign="top" bgcolor="' + rowColor + '"><td><a href="' + web + '" target="_blank">' + institute + '</a></td><td>' + rep + '</td><td>' + email + '</td></tr>';
					a = 1;
				}
				else { table_html_2 += '<tr valign="top" bgcolor="' + rowColor + '"><td><a href="' + web + '" target="_blank">' + institute + '</a></td><td>' + rep + '</td><td>' + email + '</td></tr>';
				};
				// End building table listing
				
				//Start common html elements for infowindows
				var html = "\<p\>\<div class\=\'gMapInfoWindow'\>";
			  
				if (web) {
					html += "\<b style\='font-size: 12px'\>\<a href\=\'" + web + "\' target\=\'\_blank\'\>" + institute + "\<\/a\>\<\/b\>\<br \/\>";
				} 
				else { html += institute + "\<\/h3\>\<br \/\>";
				};
				html += "\<b\>" + membertype + "<\/b\>\<br \/\>\<b\>Rep\:\<\/b\> " + rep + "\<br \/>\<b\>e\-mail\:\<\/b\> " + email + "\<\/b\>";			  
				if ((founder == "Yes") || (founder == "yes")) {
					html += "\<br \/\>\<b\>Founding Member\<\/b\>\<br \/\>";
				}				
				else { html += "\<br \/\>";
				};
			  
				var marker = createMarker(point, institute, html);
															  
		    } // end for loop
			// put the assembled sidebar_html contents into the sidebar div
			sidebar_html = '<h3 style="margin\-top\: 4px\; margin\-bottom\: 10px\; background\-color\: Silver\;">\&nbsp\;' + gmarkers.length + '&nbsp;' + sidebar_html;
			document.getElementById("sidebar").innerHTML = sidebar_html;
			// put the assembled table contents into their respective divs
			table_html_1 += "</tbody></table><p>&nbsp;&nbsp;&nbsp;&nbsp;<em>(F) = Founding Member</em></p>";
			table_html_2 += "</tbody></table>";
			document.getElementById("tablelist1").innerHTML = table_html_1;
			document.getElementById("tablelist2").innerHTML = table_html_2;
		}); //end GDownloadUrl function	
			
	} // end iscompatible funtion
	else {
		alert("Sorry, the Google Maps API is not compatible with this browser");
	};
} // end of creatMap/onLoad function	
//]]>

