/*   UoA campuses and maps,  googlemap api script */

  // global JS variable
  var our_map;

  // call to api to google load maps 
  google.load("maps", "2.x");

// an associative array to hold marker points and info window data
var campuses = {
    'roseworthy': {
	  lat: -34.527349,
	  lng: 138.711576,
	  scale: 9,
	  name: 'Roseworthy',
	  icon: "B",
	  info: "<strong>Roseworthy Campus</strong><br>University of Adelaide<br>Roseworthy SA 5371<br> Australia <br>Telephone: +61 8 8303 7812<br>Facsimile: +61 8 8303 7960"
	},
	 'waite': {
	  lat: -34.967737,
	  lng: 138.631088,
	  scale: 12,
	 name: 'waite',
	 icon: "C",
	  info: "<strong>Waite Campus</strong><br>University of Adelaide<br>PMB 1 Glen Osmond SA 5064<br>Australia<br>Telephone: +61 8 8303 5673<br>Facsimile: +61 8 8303 4386"
	},
	'thebarton': {
	  lat: -34.912194,
	  lng: 138.57391,
	  scale: 13,
	 name: 'thebarton',
	 icon: "D",
	  info: "<strong>Thebarton Campus</strong><br>3/49 Holland Street Thebarton SA 5031<br>Australia<br>Telephone: +61 8 8303 4471<br>Facsimile: +61 8 8303 4473"
	},
	'singapore': {
	  lat: 1.295488,
	  lng: 103.843426,
	  scale: 10,
	 name: 'singapore',
	 icon: "E",
	  info: "<strong>University of Adelaide - Singapore Ngee Ann-Adelaide Education Centre</strong><br>97 Tank Road Teochew Building Level 4<br>Singapore<br>Phone: +65 6738 2910"
	},
	'winecentre': {
	  lat: -34.920001,
	  lng: 138.615918,
	  scale: 14,
	  name: 'winecentre',
	  icon: "F",
	  info: "<strong>National Wine Centre of Australia</strong><br>Hackney Road<br>Adelaide SA 5000<br>Phone: +61 8 8303 3355<br>Fax: +61 8 8303 7444"
	},
	 'northterrace': {
	  lat: -34.92112652745268,
	  lng: 138.60480308532715,
	  scale: 13,
	  name: 'North Terrace',
	  icon: "A",
	  info: "<strong>North Terrace Campus</strong><br>The University of Adelaide<br>SA 5005 Australia<br>Telephone: +61 8 8303 5208<br>(Country and interstate callers toll free on 1800 061 459)<br>Facsimile: +61 8 8303 4401"
	}
	 
};


// function with two arguments
function map_goto(map, campus_name) {
		
	// sets the maps type to normal view
	map.setMapType(G_NORMAL_MAP);  
	  
    // sets campus to equal the hash lookup
	var campus = campuses[campus_name];
	
	// set 'spot' to equal a latLing object based on values in the hash lookup;
	var spot = new google.maps.LatLng(campus['lat'], campus['lng']);
	
	// centre map at latlng and scale required;
    map.setCenter(spot, campus['scale']);

 	// use the default marker option
	var letterIcon = new GIcon(G_DEFAULT_ICON);
	// hash lookup for icon
	var letter = campus['icon'];
	// set the image for default marker
	letterIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
	// use letters for the markers instead of default number
	markerOptions = {icon: letterIcon};
    
	// create a new marker at the required latlng and requred display options
	var marker = new GMarker(spot, markerOptions);

    //display the marker as an overlay
	map.addOverlay(marker);
	
	// display a marker my default - in this case the last one in the hash.
	marker.openInfoWindow(campus['info']);
	
	
	// assocaiate a listener function to the marker to display info window onclick
	GEvent.addListener(marker, "click", function() {	
	  marker.openInfoWindow(campus['info']);
	})
  }


 
function initialize() {
	// create a map object name our_map 
    our_map = new google.maps.Map2(document.getElementById('map_canvas'));
	for (var id in campuses) {
	    map_goto(our_map, id);
	
	}
	  
	  
	our_map.setUIToDefault();
  }
  
 // Calls the function intialize when GMap has been loaded 
window.onload = google.setOnLoadCallback(initialize);
  
