/**
 * Function to generate google map with specific option and location
 * 
 * @param address string The target to put on map
 * @param target string The HTML tag where the google map code is inject
 **/

// GLOBAL VARIABLEs
// Longitude and latitude of the location
var loc;
// Google Map Object
var map;
// String identificator for location
var address;

function gmap(add,target) {
	// Set the location to be localized
	address = add;
	// Object for localize the location
	var geoloc = new google.maps.Geocoder();
	// Find the geographic coordinate of location and return this to a map
	geoloc.geocode({ 'address':address}, function (results, status) {
		if (status == google.maps.GeocoderStatus.OK) {
			if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
				loc = results[0].geometry.location;
				// SET MAP'S OPTIONS
				var mapOptions = {
			      zoom: 16,
			      center: loc,
				  disableDefaultUI:true,
				  keyboardShortcuts:true,
			      /*mapTypeControl:false,
			      mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DEFAULT},*/
			      /*navigationControl:false,
			      navigationControlOptions: {style: google.maps.NavigationControlStyle.ANDROID},*/
			      mapTypeId: google.maps.MapTypeId.ROADMAP
			    };
				// Generate the location map
				map = new google.maps.Map(document.getElementById(target), mapOptions);
				/*google.maps.event.addListener(map,'zoom_changed', function(){
					alert("The zoom value is: "+map.get_zoom());
				});
				google.maps.event.addListener(map,'dragend', function(){
					alert("Draged map! New center is: "+map.get_center());
				});*/
				setMarker(map,loc);
		    } else {
		            alert("No results found");
		      }
		} else {
			alert("Geocode was not successful for the following reason: " + status);
		  }
	});
}

function setMarker(map,loc){
	// SET MAARKER'S OPTIONS
	var markerOption = {
			map:map,
			flat:false,
			clickable:true,
			title:"Urbangap - Verona",
			//icon:"i/marker.gif",
			position:loc
	};
	// Put the marker on the map
	var marker = new google.maps.Marker(markerOption);
	// SET MARKER'S INFOWINDOW 
	var infoOption = {
		content:address
	};
	// Generate and associate the info to the marker
	var info = new google.maps.InfoWindow(infoOption);
	// Marker event 
	google.maps.event.addListener(marker, 'mouseover', function() {
		info.open(map,marker);
    });	
}

function setZoom(map,zoom){
	var actual_zoom = map.get_zoom();
	switch (zoom){
		case '+':
		map.set_zoom(actual_zoom+1);
		break;

		case '-':
		map.set_zoom(actual_zoom-1);
		break;
		
		default:
		break;
	}
}

function setMapType(map,type){
	map.set_mapTypeId(type);
}