﻿  $(document).ready(function(){
        	initialize();        	
        });

var map;
var geocoder;
var address;

function initialize() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(-33.735254, 150.946291), 16);
        map.setUIToDefault();
        
        placeSingleMarker();        
        
        /* Reverse Geocode on map click */
        //GEvent.addListener(map, "click", getAddress);
        //geocoder = new GClientGeocoder();       
    }
    screenResize();
}

function placeSingleMarker(){
    var point = new GLatLng(-33.735254, 150.946291);
    var marker = new GMarker(point);
    map.addOverlay(marker);

    marker.openInfoWindowHtml('<p><b>Rave Café</b></p>' + '<p>The Sky City Building</p><p>A115/20 Lexington Drive</p><p>Bella Vista, NSW 2153, Australia</p>' + '<p>Phone: 02 8824 7944</p><p>Fax: 02 8824 4772</p>');

    GEvent.addListener(marker, "click", whenMarkerClick);
}

function whenMarkerClick(latlng) {

    this.openInfoWindowHtml('<p><b>Rave Café</b></p>' + '<p>The Sky City Building</p><p>A115/20 Lexington Drive</p><p>Norwest Buisness Park</p>Bella Vista, NSW 2153, Australia</p>' + '<p>Phone: 02 8824 7944</p><p>Fax: 02 8824 4772</p>');
    
}

function getAddress(overlay, latlng) {
  if (latlng != null) {
    address = latlng;
    geocoder.getLocations(latlng, showAddress);
  }
}

function showAddress(response) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
    alert("Status Code:" + response.Status.code);
  } else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.addOverlay(marker);
    marker.openInfoWindowHtml(
        '<b>orig latlng:</b>' + response.name + '<br/>' + 
        '<b>latlng:</b>' + place.Point.coordinates[1] + "," + place.Point.coordinates[0] + '<br>' +
        '<b>Status Code:</b>' + response.Status.code + '<br>' +
        '<b>Status Request:</b>' + response.Status.request + '<br>' +
        '<b>Address:</b>' + place.address + '<br>' +
        '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
        '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
  }
}