//<![CDATA[

// Copyright ©2009 Bryn Charlton, all rights reserved.

	// Declare global variables
    var map;
	var areaCentreLat = 36.495268;
	var areaCentreLng = -4.691672;
	var locationCentreLat = 36.495268;
	var locationCentreLng = -4.691672;
    var baseIcon;

	//Initialise the map
	function initialise() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(areaCentreLat, areaCentreLng), 8);
        map.addControl(new GSmallZoomControl());
        map.addControl(new GMenuMapTypeControl());
		map.setMapType(G_NORMAL_MAP);
		
        // Create a base icon for all of our markers that specifies the
        // shadow, icon dimensions, etc.
        baseIcon = new GIcon(G_DEFAULT_ICON);
        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(20, 34);
        baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
      }
	  // Place markers on the map
	  showLocationOnMap(36.495268, -4.691672, "green", "0", "Aunty Betty's Apartment");
	  showLocationOnMap(36.495643,-4.691001, "yellow", "0", "Supermarket");
	  showLocationOnMap(36.496118,-4.691248, "yellow", "0", "Restaurants & Bars");
	  showLocationOnMap(36.496553,-4.691763, "yellow", "0", "Tennis Court");
	  showLocationOnMap(36.495472,-4.688933, "yellow", "0", "Beach Bar");
	  showLocationOnMap(36.498511,-4.688641, "yellow", "0", "Restaurants & Bars");
	  showLocationOnMap(36.150351, -5.344849, "yellow", "0", "Gibraltar");
	  showLocationOnMap(36.753189,-5.161514, "yellow", "0", "Ronda");
	  showLocationOnMap(36.485694,-4.953032, "yellow", "0", "Puerto Banus");
	  showLocationOnMap(36.511913,-4.887543, "yellow", "0", "Marbella");
	  showLocationOnMap(36.484573,-4.741952, "yellow", "0", "Puerto Cabopino");
	  showLocationOnMap(36.504427,-4.677172, "yellow", "0", "La Cala");
	  showLocationOnMap(36.541846,-4.624043, "yellow", "0", "Fuengirola");
	  showLocationOnMap(36.596993,-4.638247, "yellow", "0", "Mijas");
	  showLocationOnMap(36.600426,-4.542117, "yellow", "0", "Tivoli World");
	  showLocationOnMap(36.670622,-4.486542, "blue", "0", "Malaga International Airport");
    }

   	// showLocationOnMap() adds a coloured marker to the map with a title and an open info window
   	function showLocationOnMap(lat, long, colour, index, title) {

	  point = new GLatLng(lat, long);
	  var number = String(index);
      var letteredIcon = new GIcon(baseIcon);
      letteredIcon.image = "http://www.charltonvillas.com/global/markers/" + colour + number + ".png";

      // Set up our GMarkerOptions object
      markerOptions = { icon:letteredIcon, title: title};
      var marker = new GMarker(point, markerOptions);
      map.addOverlay(marker);
      GEvent.addListener(marker, "click", function() 
      {
		marker.openInfoWindowHtml(title);
      });  
	}

	// Position map to show location
	function showLocation() {
	  map.setCenter(new GLatLng(locationCentreLat, locationCentreLng), 15);
	}

	// Position map to show local area
	function showLocalArea() {
	  map.setCenter(new GLatLng(areaCentreLat, areaCentreLng), 10);
	}

	// Position map to show Region
	function showRegion() {
	  map.setCenter(new GLatLng(areaCentreLat, areaCentreLng), 8);
	}
	
//]]>

