/*
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.
+++++++++++++
Modifications
+++++++++++++
Editor:		
DD-MMM-YYYY:
Watcha did:	
~~~~~~~~~~~~~
*/

var internMap;
var internGeocoder;

//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]);
	
	//create marker
	point 			= new GLatLng(lat, lng);
	internMap.setCenter(point, zoom);
	var marker 		= new GMarker(point);
	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) {
	internMap = new GMap2(document.getElementById("map_canvas"));
	internMap.setCenter(new GLatLng(42, -26), zoom);
	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);
			}
		});   
	}
}