
// create array of locations
var locations = [
	// oak ridge
	{
		arrLngLat: [36.010892,-84.259402],
		strMsgHTML: '<p><strong>ORAU</strong><br />210 Badger Road<br /> Oak Ridge, TN 37830</p>',
		strAddress: '210 Badger Road Oak Ridge, TN 37830',
		strAirport: 'Knoxville McGhee Tyson Airport',
		arrAirportLngLat: [],
		eMapTrigger: 'map1',
		eDirTrigger: 'dir1'
	},
	// arvada
	{
		arrLngLat: [39.844625,-105.10986],
		strMsgHTML: '<p><strong>Arvada, CO, Worker Health Surveillance</strong><br />9950 W. 80th Avenue, Suite 17<br />Arvada, CO 80005</p>',
		strAddress: '9950 W. 80th Avenue Arvada, CO 80005',
		strAirport: 'Denver International Airport Denver CO',
		arrAirportLngLat: [],
		eMapTrigger: 'map2',
		eDirTrigger: 'dir2'
	},
	// washington1
	{
		arrLngLat: [38.905766,-77.043171],
		strMsgHTML: '<p><strong>National Security and Emergency Management</strong><br />1140 Connecticut Ave. NW Suite 350<br />Washington, DC 20036</p>',
		strAddress: '1140 Connecticut Avenue Washington DC 20036',
		strAirport: 'Ronald Reagan National Airport Arlington VA',
		arrAirportLngLat: [38.872592,-77.034073],
		strAltAirport: 'Dulles International Airport Washington D.C.',
		arrAltAirportLngLat: [38.924161,-77.044029],
		eMapTrigger: 'map3',
		eDirTrigger: 'dir3a'
	},
	// washington2
	{
		arrLngLat: [38.905244,-77.041218],
		strMsgHTML: '<p>1120 Connecticut Ave<br/>Suite 1050<br/>Washington DC 20036</p>',
		strAddress: '1120 Connecticut Ave Washington DC 20036',
		strAirport: 'Washington Dulles International Airport',
		arrAirportLngLat: [38.924161, -77.044029],
		strAltAirport: '1 Aviation Circle Washington D.C. 20001',
		arrAltAirportLngLat: [38.924161,-77.044029],
		eMapTrigger: 'map6',
		eDirTrigger: 'dir6a'
	},
	// cincinnati
	{
		arrLngLat: [39.162472,-84.454374],
		strMsgHTML: '<p><strong>Cincinnati, Ohio Dose Reconstruction</strong><br />4850 Smith Road, Suite 200<br />Cincinnati, OH 45212</p>',
		strAddress: '4850 Smith Road Cincinnati, OH 45212',
		//strAirport: '3286 Loomis Road Cincinnati OH 45275', //Cincinnati/Northern Kentucky 
		strAirport: 'Cincinnati Northern Kentucky International Airport', //Cincinnati/Northern Kentucky 
		arrAirportLngLat: [39.055718,-84.649315],
		eMapTrigger: 'map4',
		eDirTrigger: 'dir4'	
	},
	//aberdeen
	{
		arrLngLat: [39.467492,-76.235842],
		strMsgHTML: '<p><strong>U.S. Army Research Participation Programs</strong><br />4692 Millennium Drive Suite 101<br />Belcamp, MD 21017</p>',
		strAddress: '4692 Millennium Drive Belcamp, MD 21017',
		strAirport: 'Baltimore Washington International Thurgood Marshall Airport', //Baltimore-Washington 
		arrAirportLngLat: [39.1855,-76.675107],
		eMapTrigger: 'map5',
		eDirTrigger: 'dir5'	
	},
	// stafford
	{
		arrLngLat: [38.354008,-77.512257],//(38.35355388466458, -77.51172065734863)
		strMsgHTML: '<p>5 Le Way Drive<br />Suite 125<br />Fredericksburg, VA 22406</p>',
		strAddress: '5 Le Way Drive Fredericksburg VA 22406',
		strAirport: 'Ronald Reagan National Airport, Arlington VA',
		arrAirportLngLat: [38.861298,-77.038622],
		eMapTrigger: 'map7',
		eDirTrigger: 'dir7a'
	},
	// sacramento
	{
		arrLngLat: [38.578611,-121.491644],
		strMsgHTML: '<p>1130 K Street<br />Suite 100<br />Sacramento, California 95825-3563</p>',
		strAddress: '1130 K Street Sacramento, California 95825-3563',
		strAirport: 'Sacramento International Airport', // Airport Sacramento CA
		arrAirportLngLat: [38.691941,-121.583118],
		eMapTrigger: 'map8',
		eDirTrigger: 'dir8'
	}
];



// run when DOM is ready
	$(document).ready(function() {

	    // default values	
	    var eMap = document.getElementById('map');
	    var eDirections = document.getElementById('directions');

	    var objSearchOptions = {
	        resultList: eDirections,
	        searchFormHint: "Search nearby (i.e.; Hotels)",
	        suppressInitialResultSelection: true
	    };

	    // getMap
	    function getMap(objLocation) {
	        GEvent.addDomListener(document.getElementById(objLocation.eMapTrigger), 'click', function() {
	            var point = new GLatLng(objLocation.arrLngLat[0], objLocation.arrLngLat[1]);
	            var html = objLocation.strMsgHTML;
	            var marker = new GMarker(point);
	            var map = new GMap2(eMap);
	            map.setCenter(point, 15);
	            map.addControl(new GSmallMapControl());
	            map.addControl(new GMapTypeControl());
	            map.enableScrollWheelZoom();
	            map.addOverlay(marker);
	            var localSearch = new google.maps.LocalSearch(objSearchOptions);
	            map.addControl(localSearch);
	            GEvent.addListener(marker, "click", function() {
	                marker.openInfoWindowHtml(html);
	            });
	        });

	    }

	    // getDirections
	    function getDirections(objLocation) {
	        GEvent.addDomListener(document.getElementById(objLocation.eDirTrigger), 'click', function() {
	            eDirections.innerHTML = '';
	            var oMap = new GMap2(eMap);
	            var oDirections = new GDirections(oMap, eDirections);
	            oDirections.load("from: " + objLocation.strAirport + " to: " + objLocation.strAddress + "");
	        });
	    }

	    // initialize page view with Oak Ridge map
	    function initPageView() {
	        var point = new GLatLng(locations[0].arrLngLat[0], locations[0].arrLngLat[1]);
	        var html = locations[0].strMsgHTML;
	        var marker = new GMarker(point);
	        var map = new GMap2(eMap);
	        map.setCenter(point, 15);
	        map.addControl(new GSmallMapControl());
	        map.addControl(new GMapTypeControl());
	        map.enableScrollWheelZoom();
	        var localSearch = new google.maps.LocalSearch(objSearchOptions);
	        map.addControl(localSearch);
	        GEvent.addListener(marker, 'click', function() {
	            marker.openInfoWindowHtml(html);
	        });
	        map.addOverlay(marker);
	    }


	    function initialize() {
	        if (GBrowserIsCompatible()) {

	            // init page view with main campus location
	            initPageView();

	            // add click handlers to links for other maps
	            for (i = 0; i < locations.length; i++) {
	                var location = locations[i];
	                getMap(location);
	            };

	            // add  event listeners for directions links
	            for (i = 0; i < locations.length; i++) {
	                var location = locations[i];
	                getDirections(location);
	            };


	        } // end isCompatible
	    } // end initialize

	    google.setOnLoadCallback(initialize);

		// init locationsMenu accordion widget 
		$('#locationsMenu').accordion({
			active: true,
			alwaysOpen: false,
    		header: '.trigger', 
    		event: 'click', 
			autoHeight: false ,
			clearStyle: true,
			selectedClass: 'active'						  
		});
		//$('#locationsMenu').accordion("activate", 0);

	}); // end jQuery DOM ready	

	$(document.body).unload(function() {
	if (GBrowserIsCompatible()) {
	GUnload();
		}
	});
	
/*	
// Reverse GeoCoding Example

var map;
var geocoder;
var address;

function initialize() {
  map = new GMap2(document.getElementById("map_canvas"));
  map.setCenter(new GLatLng(40.730885,-73.997383), 15);
  map.addControl(new GLargeMapControl);
  GEvent.addListener(map, "click", getAddress);
  geocoder = new GClientGeocoder();
}

function getAddress(overlay, latlng) {
  if (latlng != null) {
    address = latlng;
    geocoder.getLocations(latlng, showAddress);
  }
}

function showAddress(response) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
    alert("Status Code:" + response.Status.code);
  } else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.addOverlay(marker);
    marker.openInfoWindowHtml(
        '<b>orig latlng:</b>' + response.name + '<br/>' + 
        '<b>latlng:</b>' + place.Point.coordinates[1] + "," + place.Point.coordinates[0] + '<br>' +
        '<b>Status Code:</b>' + response.Status.code + '<br>' +
        '<b>Status Request:</b>' + response.Status.request + '<br>' +
        '<b>Address:</b>' + place.address + '<br>' +
        '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
        '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
  }
}*/