  // type this javascript on address bar to get lat/lon - javascript:void(prompt('',gApplication.getMap().getCenter()));
// Builds an array of geocode responses for the 5 cities.
  var city = [
    {
      name: "Melbourne, Australia",
      Status: {
        code: 200,
        request: "geocode"
      },
      Placemark: [
        {
          address: "Level 7, 267 Collins Street, Melbourne, Victoria, 3000, AUSTRALIA",
		  phone: "+61 1300 DIAMONDS",
		  fax: "+61 3 9650 8332",
		  website: "www.diamondexchange.com.au",
		  image: "loc_melbourne.jpg",
          Point: {
            coordinates: [144.96472835540771, -37.81614091976875, 0]
          }
        }
      ]
    },
	{
      name: "Sydney, Australia",
      Status: {
        code: 200,
        request: "geocode"
      },
      Placemark: [
        {
          address: "Level 1, 14 Martin Place, Sydney NSW 2000, AUSTRALIA",
		  phone: "+61 2 9229 8000, +61 1300 DIAMONDS",
		  fax: "+61 2 9233 7442",
		  website: "www.diamondexchange.com.au",
		  image: "loc_sydney.jpg",
          Point: {
            coordinates: [ 151.208232, -33.867214, 0]
          }
        }
      ]
    },
	{
      name: "Brisbane, Australia",
      Status: {
        code: 200,
        request: "geocode"
      },
      Placemark: [
        {
          address: "Brisbane Club Tower, Post Office Square, <br/>Level 15, 241 Adelaide St, Brisbane Qld 4000, AUSTRALIA",
		  phone: "+61 7 322 11 888, +61 1300 DIAMONDS",
		  fax: "+61 7 3221 8858",
		  website: "<a href='http://www.diamondexchange.com.au/queensland'>www.diamondexchange.com.au/queensland</a>",
		  image: "loc_brisbane.jpg",
          Point: {
            coordinates: [153.03001284599304, -27.467002830498536, 0]
          }
        }
      ]
    }, 
	{
      name: "Toranto, Canada",
      Status: {
        code: 200,
        request: "geocode"
      },
      Placemark: [
        {
          address: "27th Floor, 161 Bay Street, Toronto, M5J 2S1 CANADA",
		  phone: "+1 866 339 9988",
		  fax: "+1 416 572 2201",
		  website: "www.diamondexchange.ca",
		  image: "loc_toronto.jpg",
          Point: {
            coordinates: [-79.37941789627075, 43.64648693255759, 0]
          }
        }
      ]
    },
	{
      name: "New York, USA",
      Status: {
        code: 200,
        request: "geocode"
      },
      Placemark: [
        {
          address: "39th Floor, 245 Park Avenue, New York, 10167 USA",
		  phone: "+1 866 339 9988",
		  fax: "+1 416 572 2201",
		  website: "www.diamondexchangenewyork.com",
		  image: "loc_new-york.jpg",
          Point: {
            coordinates: [ -73.97561967372894, 40.75476083153475, 0]
          }
        }
      ]
    }		   
  ];


  var map;
  var geocoder;

  // CapitalCitiesCache is a custom cache that extends the standard GeocodeCache.
  // We call apply(this) to invoke the parent's class constructor.
  function CapitalCitiesCache() {
    GGeocodeCache.apply(this);
  }

  // Assigns an instance of the parent class as a prototype of the
  // child class, to make sure that all methods defined on the parent
  // class can be directly invoked on the child class.
  CapitalCitiesCache.prototype = new GGeocodeCache();

  // Override the reset method to populate the empty cache with
  // information from our array of geocode responses for capitals.
  CapitalCitiesCache.prototype.reset = function() {
    GGeocodeCache.prototype.reset.call(this);
    for (var i in city) {
      this.put(city[i].name, city[i]);
    }
  }

	// Creates a marker whose info window displays the given data
	/*function createMarker(point, data)
	{
		// Create our "tiny" marker icon
		var tinyIcon = new GIcon();
		tinyIcon.image = "i/mm_20_blue.png";
		tinyIcon.shadow = "i/mm_20_shadow.png";
		tinyIcon.iconSize = new GSize(12, 20);
		tinyIcon.shadowSize = new GSize(22, 20);
		tinyIcon.iconAnchor = new GPoint(6, 20);
		tinyIcon.infoWindowAnchor = new GPoint(5, 1);
		// Set up our GMarkerOptions object literal
		markerOptions = { icon:tinyIcon };		   
		var marker = new GMarker(point, markerOptions);
		// Show this markers index in the info window when it is clicked
		var html = data;
		GEvent.addListener(marker, "mouseover", function() {marker.openInfoWindowHtml(html);});
		return marker;
	}*/

	function initialize(city) {
		map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(new GLatLng(45.4419, -5.1419), 1);
		geocoder = new GClientGeocoder();
		geocoder.setCache(new CapitalCitiesCache());
		//findCity1('Melbourne, Australia');	
		
		if(city == "Melbourne")
			findCity1('Melbourne, Australia')
		else if(city == "Sydney")
			findCity1('Sydney, Australia')
		else if(city == "Brisbane")
			findCity1('Brisbane, Australia')
		else if(city == "Toronto")
			findCity1('Toranto, Canada')
		else if(city == "NewYork")
			findCity1('New York, USA')
		else if(city == "")
			findCity1('Melbourne, Australia')		

		
		/*mgr = new GMarkerManager(map);
		var point = new GLatLng(144.96472835540771, -36.597889133070204);
		mgr.addMarker(createMarker(point, 'Melbourne, Australia'));
		*/
		//Add new map default control
		map.setUIToDefault();
	}

  function addAddressToMap(response) {
    map.clearOverlays();
	
    if (response && response.Status.code != 200) {
      alert("Unable to locate " + decodeURIComponent(response.name));
    } else {
      var place = response.Placemark[0];
      var point = new GLatLng(place.Point.coordinates[1],
                              place.Point.coordinates[0]);
      map.setCenter(point, 9);
      //small map zoom control
	  //map.addControl(new GSmallMapControl());
      //map.addControl(new GMapTypeControl());	  
	
		map.openInfoWindowHtml(point, "<p class='tagfont'><b>Diamond Exchange Ltd.<br>Address:</b> " + place.address
	   + "<br><b>Phone:</b> " + place.phone
	   + "<br><b>Fax:</b> " + place.fax
	   + "<br><b>Website:</b> " + place.website 
	   + "<br><br><img src='i/dxx/" +  place.image + "'  />"
	   + "</p>"
	   );
	  
    }
    
	//GEvent.addListener(point, "click", function() {point.openInfoWindowHtml("test message");});
	//map.addOverlay(new GMarker(point));
 
 		var marker = new GMarker(point, {draggable: true});

        GEvent.addListener(marker, "dragstart", function() {
          map.closeInfoWindow();
        });

        GEvent.addListener(marker, "dragend", function() {
          marker.openInfoWindowHtml("Just bouncing along...");
        });

        map.addOverlay(marker);

  }

  function findCity(which) {
    if (which != 0) {
      geocoder.getLocations(city[which - 1].name, addAddressToMap);
    }
  }
  
  function findCity1(which) {
	  //alert(which);
    if (which != "") {
      geocoder.getLocations(which, addAddressToMap);
    }
  } 
  