var markersArray = [];
var infoWindows = [];

var MYMAP = {
  bounds: null,
  map: null
}

// function to initialize Google Map
MYMAP.init = function(selector, latLng, zoom, maxZoom) {
  var myOptions = {
    zoom:zoom,
    center: latLng,
    mapTypeId: google.maps.MapTypeId.ROADMAP, 
    maxZoom:maxZoom,
	streetViewControl:true,
	scaleControl:true,
	overviewMapControl:true
  }
  this.map = new google.maps.Map($(selector)[0], myOptions);
  this.bounds = new google.maps.LatLngBounds();
}

// function to place marker on the map
MYMAP.placeMarker = function(id, name, description, latitude, longitude, url, type) {
	
	if(latitude != '' && longitude != ''){
      
      var point = new google.maps.LatLng(parseFloat(latitude),parseFloat(longitude));
      
      MYMAP.bounds.extend(point);

		switch (type)
		{
		case "Public":
			//set url to image here for Public courses
			var icon = "../images/mapmarker/flag.gif";
			break;
		case "Private":
			//set url to image here for Private courses
			var icon = "../images/mapmarker/flag2.gif";
			break;
		case "Resort":
			//set url to image here for Resort courses
			var icon = "../images/mapmarker/flag3.gif";
			break;
		case "Semi-Private":
			//set url to image here for Semi-Private courses
			var icon = "../images/mapmarker/flag4.gif";
			break;
		case "Military":
			//set url to image here for Military courses
			var icon = "../images/mapmarker/flag5.gif";
			break;
		default:
			//set url to image here for courses without a type
			var icon = "../images/mapmarker/flag6.gif";
		}	  

	  //marker with custom icon
      var marker = new google.maps.Marker({
        position: point,
        map: MYMAP.map,
        icon: icon
      });

      var infoWindow = new google.maps.InfoWindow();
	  
	  // html that is displayed in the info bubble
	  var html="<div style='font-size:12px'>";
	  if ( url.length > 0 )
	  {
	      html += "<a href='"+url+"' target='_blank'>"+name+'</a><br>';
	  }
	  else
	  {
	      html += name+'<br>';
	  }
	  html += description;
	  html += '</div>';

		//on click, popup is displayed
		google.maps.event.addListener(marker, 'click', function() {
			for(var i = 0; i < infoWindows.length; i++){
				infoWindows[i].close();
			}           
			infoWindow.setContent(html);
			infoWindow.open(MYMAP.map, marker);       
		});
		  infoWindows.push(infoWindow);
	  
	  
}
}


