/*
File: internship/scripts/intern-map-script.js

MAKE SURE YOU KEEP TRACK OF EVERYTHING YOU DO!

Author: Dwight VanTuyl
DD-MMM-YYYY: 14-Mar-2008
Purpose: Google map generation.
For more information on google map api, please visit:
http://code.google.com/apis/maps/
+++++++++++++
Modifications
+++++++++++++
Editor:		
DD-MMM-YYYY:
Watcha did:	
~~~~~~~~~~~~~
*/

var internMap;  //holds the map object

//Creates marker location and adds to map
//Input loc: {id: submissionid, latlng: intern_geocode}
function addLocation(loc, zoom) {
	//split latlng into two valuse and parse to float
	latlngSplit 	= loc.latlng.split(',');
	lat 			= parseFloat(latlngSplit[0]);
	lng 			= parseFloat(latlngSplit[1]);
	
	//set the center to the location's latitude and longitude
	point 			= new GLatLng(lat, lng);  //GLatLng takes a latitude and longitude and creates an invisible point on the map
	internMap.setCenter(point, zoom);
  
  //place an icon marker on the map at the location's latitude and longitude
	var marker 		= new GMarker(point);   //GMarker takes a point and places a marker icon on the point's location
	internMap.addOverlay(marker);
	
	//if loc has an id then create a click event to open announcment
	if(loc.id){
		GEvent.addListener(marker, "click", function(){
			document.location.href="/internship/browse/intern-browse-announceProcess.cfm?id=" + loc.id;
		});
	}
}

//Initialize the google map and add to page
//Input locations: [{id: submissionid, latlng: intern_geocode}, {id: submissionid, latlng: intern_geocode}, ...]
function initializeMap(locations, zoom) {
  //create map by specifying the location in the html doc to put it.
	internMap = new GMap2(document.getElementById("map_canvas"));
	internMap.setCenter(new GLatLng(42, -26), zoom);
	
  //init the map by clearing all markers and adding controls
  internMap.clearOverlays();  
	internMap.addControl(new GSmallMapControl());
	
	//iterate through location objects and call addLocation on each one
	if(locations){
		jQuery.each(locations, function(){
			if(this){
				addLocation(this, zoom);
			}
		});   
	}
}


