//global var
var geocoder = new google.maps.Geocoder();
  
function initialize(titleOfMap,addressOfMap,zipCodeOfMap,townOfMap,country)
{
  var textLocation = addressOfMap+" "+zipCodeOfMap+" "+townOfMap+","+country;
  var latlng = new google.maps.LatLng(-34.397, 150.644);
  var myOptions = {
      				zoom: 13,
      				center: latlng,
      				mapTypeId: google.maps.MapTypeId.ROADMAP
       			  };
  var map = new google.maps.Map(document.getElementById("map"), myOptions);

  //default map
  showLocation(textLocation,map,1,"img/map/logo_intercorp_map.png","Intercorp");
}

function addMarkerToMap(mapInstance,position,titleOfMarker)
{
	var marker = new google.maps.Marker
	(
		{
			map: mapInstance, 
			position: position,
			title:titleOfMarker
		}
	);	
}

function addSimpleImageToMap(mapInstance,position,simpleImage,titleOfMarker)
{
	var marker = new google.maps.Marker
	(
		{
			map: mapInstance, 
			position: position,
			icon: simpleImage,
			title:titleOfMarker
		}
	);	
}

function showLocation(address,mapInstance,withImageBool,simpleImage,titleOfMarker)
{
  geocoder.geocode
  ( 
	{ 
		'address': address
	}, 
	function(results, status) 
	{
		if (status == google.maps.GeocoderStatus.OK) 
		{
			mapInstance.setCenter(results[0].geometry.location,titleOfMarker);
			
			if(withImageBool == 0)
			{
				addMarkerToMap(mapInstance,results[0].geometry.location);
			}
			else if(withImageBool == 1)
			{
				addMarkerToMap(mapInstance,results[0].geometry.location,titleOfMarker);
				addSimpleImageToMap(mapInstance,results[0].geometry.location,simpleImage,titleOfMarker);
			}
		}
	}
  );

  //geocoder.getLocations(address, addAddressToMap); v2 api
}
