var map;
var restaurantMapMarkers = [];

/********************************************
* NAME: loadMap
* PARAMETER: 
* RETURN: none
* DESCRIPTION: loads map depending on service selected
***********************************************/
function loadMap(type, mapDiv, statusDiv, latitude, longitude){

	//if latitude or longitude is is not passed in, display an error
	if(latitude=="" || longitude==""){
		document.getElementById(mapDiv).innerHTML = '<div align="center" class="errorText">Sorry,<br />Map could not be displayed.</div>';
	}
	//if latitude and longitude are passed in, display the map
	else{
		loadGoogleMap(type, mapDiv,latitude, longitude);	
	}
	
	//add the marker to the map
	addMarkerGoogle(1,latitude, longitude,'Restaurant Location');
	
}//end loadGoogleMap (function)



function loadGoogleMap(type, mapDiv,latitude, longitude){
	
	//if the browser is compatible display the map
	if (GBrowserIsCompatible()) {
		
		//create a new map
    	map = new GMap2(document.getElementById(mapDiv));
		
		if(type=='1'){
			//add zoom and pan controls
			map.addControl(new GSmallMapControl());
		}
		else{
			//add zoom and pan controls
			map.addControl(new GLargeMapControl);
		}
			
		//add map type controls
		map.addControl(new GMapTypeControl());
		
		//set the map center and zoom level (must occur before adding a marker)
		map.setCenter(new GLatLng(latitude, longitude), 13);
		
    }
	//if browser is not compatible display an error message
	else{
		document.getElementById(mapDiv).innerHTML = '<div align="center" class="errorText">Sorry,<br />Your browser is not supported by Google maps.</div>';
	}
		


	
}//end loadGoogleMap (function)

/********************************************
* NAME: addMarkerGoogle
* PARAMETER: long, lat
* RETURN: none 
* DESCRIPTION: Adds a marker to a Google map
* at the long/lat as per the parameters
***********************************************/
function addMarkerGoogle(index, latitude, longitude, label){
			
	//crete a new point - at the given latitude/longitude
	var point = new GLatLng(parseFloat(latitude), parseFloat(longitude));
	
	//create the marker
	var marker = createGoogleMarker(point,label);
	
	//save the marker
	restaurantMapMarkers[index] = marker;
	
	//add the point to the map
	map.addOverlay(marker);
	
	//set the map center and zoom level
	map.setCenter(point, 14);
	
	
}//end addMarkerGoogle (function)



/********************************************
* NAME: createGoogleMarker
* PARAMETER: long, lat
* RETURN: none 
* DESCRIPTION: Creates a marker at the specified
* point with the specified label
***********************************************/
function createGoogleMarker(point, label) {
  
	var marker = new GMarker(point);
  
	GEvent.addListener(marker, "click", function() {
    	marker.openInfoWindowHtml(label);
  		}
	);
	
  return marker;
  
}//end createGoogleMarker (function)




/********************************************
* NAME: jumpToMarker
* PARAMETER: index of the marker in the array
* RETURN: none 
* DESCRIPTION: Jumps to the specified marker
* on the map
***********************************************/
function jumpToMarker(index){
	
	//get reference to the marker
	var marker = restaurantMapMarkers[index];
	
	//re-center over the marker
	map.setCenter(marker.getPoint(), map.getZoom());
	alert(map.getZoom());
	//open the info window above the marker
	GEvent.trigger(marker, "click"); 
	
}//end jumpToMarker



	



   
