<!--
// declare global variables

var map;
var markerOptions;
var ZoomFactor;
var cLat;
var cLng;

// Call this function when the page has been loaded
function initialize(view) {

map = new GMap2(document.getElementById("map_canvas"));

// center map on the different continents
switch(view)
{
case 'world':
  cLat=22.00; cLng=0.00; ZoomFactor=2;
  drawMap();
  break;
case 'n_america':
  cLat=52; cLng=-97; ZoomFactor=3;
  drawMap();
  break;
case 's_america':
  cLat=-17; cLng=-59; ZoomFactor=3;
  drawMap();
  break;
case 'europe':
  cLat=51; cLng=9; ZoomFactor=4;
  drawMap();
  break;
case 'asia':
  cLat=40; cLng=103; ZoomFactor=3;
  drawMap();
  break;
case 'africa':
  cLat=8; cLng=23; ZoomFactor=3;
  drawMap();
  break;
case 'australia':
  cLat=-25; cLng=135; ZoomFactor=4;
  drawMap();
  break;
case 'oceania':
  cLat=4; cLng=125; ZoomFactor=4;
  drawMap();
  break;
case 'antarctica':
  cLat=-80; cLng=0.00; ZoomFactor=2;
  drawMap();
  break;
}
}

// function to draw the popup for the key to symbols
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=48,height=590,scrollbars=yes');
return false;
}

// close the popup window
function closeWin()
  {
  window.close()
  }


function drawMap() {

// add the Google map controls

addControls();

// clear previous overlays

map.clearOverlays();

// read the marker data from the xml file and draw them

readMarkers();

  }  // end drawMap function
  
  
function addControls() {
  
  // add the map controls zoom and pan and place the map center
  
  	map.addControl(new GSmallMapControl());
  	map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(cLat, cLng), ZoomFactor);

  } 
 
 function readMarkers() {
 
 // set the arraw which determines which elements and which scale are being displayed
  
   element_array=document.forms[0].element;
   scale_array=document.forms[0].scale;
   var xmlDir = "xml_files/";
 
 // go through the element array, and for each one that is checked, display the points
 
  for (var i = 0; i < element_array.length; i++) {
 
  if (element_array[i].checked) {  
  
 // read the markers from that particular xml file
    
    var displayElement = element_array[i].value

    theMarkers(displayElement, xmlDir)
 	
   }   // end if
 	
   } // end for
        
 } //end function


       function createMarker(map, lat, lng, message, iconName) {
	 
	  var displayIcon = getIcon(iconName);
	  markerOptions = { icon:displayIcon };
  	  var marker = new GMarker(new GLatLng(lat, lng), markerOptions);
  	  marker.message = message;
  	  GEvent.addListener(marker, "click", function() {
  		map.openInfoWindowHtml(new GLatLng(lat, lng), message);
  	  });
  	  return marker;
	}
	
// create icon according to weather type
	function getIcon(wType) {
	
		var weatherIcon = new GIcon();
		weatherIcon.image = "icons/" + wType + ".png";
		weatherIcon.iconAnchor = new GPoint(16, 16);
		weatherIcon.infoWindowAnchor = new GPoint(16, 0);
		weatherIcon.iconSize = new GSize(32, 32);
		return weatherIcon;
	}

// function to get the markers

	function theMarkers(displayElement, xmlDir) {

     	var xmlFile = displayElement.toLowerCase() + ".xml"

	GDownloadUrl(xmlDir + xmlFile, function(data) {
	   var xml = GXml.parse(data);
	   var markers = xml.documentElement.getElementsByTagName("marker");
	      
	// loop through all the markers in the xml file and create a message and a marker
	         
	     for (var j = 0; j < markers.length; j++) {    
	
	     // create the message to be listed in the info window
			          
		var recordCharacteristic = markers[j].getElementsByTagName("recordCharacteristic")[0].childNodes[0].nodeValue + "<br/>";
		var recordAmt = markers[j].getElementsByTagName("value")[0].childNodes[0].nodeValue + "<br/>";
		var location = markers[j].getElementsByTagName("locationName")[0].childNodes[0].nodeValue + "<br/>";
				
		if (markers[j].getElementsByTagName("measureDate")[0].childNodes[0].nodeValue = " ") {
		  measureDate = "";
		     	}
			else {
			 var measureDate = "Recorded on: " + markers[j].getElementsByTagName("measureDate")[0].childNodes[0].nodeValue + "<br/>";
			}
			       	
		// Get the links to the information pages and create the message	
			      	
			 linkMessage = 'For more information: ';
			 recordType = ''
			  var record_links = markers[j].getElementsByTagName("record_links")[0].getElementsByTagName("link");
			  for (var n = 0; n < record_links.length; n++) {
			  	var linkText = record_links[n].getAttribute("name");
			  	var linkAddress = record_links[n].childNodes[0].nodeValue;
			  	linkMessage = linkMessage + '<a href=\"' + linkAddress + '\">' + linkText + '<\/a>&nbsp;';
			  	recordType = recordType + linkText + " "
			      }
			      
			     var message = recordType + recordCharacteristic + recordAmt + location + measureDate + linkMessage   
  
	       	// determine the scale to be display and the icon
			         
			            var displayType = markers[j].getElementsByTagName("recordType")[0].getElementsByTagName("type");
			            var iconStyle;
			            iconStyle = '';
			            var displayIndex = 0;
			                for (var n = 0; n < displayType.length; n++) {
			                
			                        var toDisplay = displayType[n].childNodes[0].nodeValue;
			      	         
			          	  	switch (toDisplay) 
							{
						case 'Global':
							displayIndex = displayIndex + 1;
							iconStyle = toDisplay; 
							break;
						case 'Hemisphere': 
							displayIndex = displayIndex + 2;
							if (iconStyle != 'Global') {
							iconStyle = toDisplay; } 
							break;
						case 'Continent': 
							displayIndex = displayIndex + 4;
							if ((iconStyle != 'Global') && (iconStyle != 'Hemisphere')) {
							iconStyle = toDisplay; } 
							break;
			          		} // end case
			          			
			          	} // end for loop
			          	
			          // create the marker
			          					          		
			          	var high_low = markers[j].getElementsByTagName("recordType")[0].getAttribute("level");
			          			          		
			          // if the display element is a cyclone, determine if it is northern or southern hemisphere
				  			          		          					
				     var latitude = parseFloat(markers[j].getAttribute("lat"))
			       			          		
			          		switch (displayElement) 
						{
						case 'Cyclone':
						if (latitude > 0) {
						iconName = "northcyclone_" + iconStyle.toLowerCase() + "_" + high_low;
						}
						else {
						iconName = "southcyclone_" + iconStyle.toLowerCase() + "_" + high_low;
						}
						break;
																	
						default:
						iconName = displayElement.toLowerCase() + "_" + iconStyle.toLowerCase() + "_" + high_low;
						break;
			          		} // end switch
			          				          					          		
			          		
			          		var aMarker = createMarker(map,
			          			   parseFloat(markers[j].getAttribute("lat")),
			          			   parseFloat(markers[j].getAttribute("lng")),
			          			   message,
			          			   iconName
			          			   );
			       
			          	// determine which scales are to be displayed
			          	for (var n = 0; n < scale_array.length; n++) {
			          	
			          	if (scale_array[n].checked == true) {
			        
			          	switch (n) {
			          	case 0: 
			          		if ((displayIndex == 1) || (displayIndex == 3) || (displayIndex == 5) || (displayIndex ==7 ))
			          		{ map.addOverlay(aMarker); }
			          		break;
			          	case 1:
			          		if ((displayIndex == 2) || (displayIndex == 3) || (displayIndex == 6) || (displayIndex == 7))
			          		{ map.addOverlay(aMarker); }
			          		break;
			          	case 2:
			          		if ((displayIndex == 4) || (displayIndex == 5) || (displayIndex == 6) || (displayIndex == 7 ))
			          		{ map.addOverlay(aMarker); }
			          		break;
			          	}
			    		}
			    		} 
          				
	      	} // end for, the one that loops through the markers
	      		
    	}); // end GDownloadURL
    	
    	}
// -->
