//trio_googlemap_api.js

    var map = null;
    var geocoder = new GClientGeocoder();
    // Create a search control
    var searchControl = new GSearchControl();
  
    // Add in a full set of searchers
    var localSearch = new GlocalSearch();

    var options = new GsearcherOptions();

    var app;
    var prefix_image_file = "";

   var main_marker;

   function App(zoomLevel, showInfo) {
      var divMap = document.getElementById("map");
      
      if(home == "" || home == null){
        if(divMap != null){
          if(divMap.style != null){
             divMap.style.display = 'none';
          }
        }
      }

      //Don't do anything when can't find the map
      if (divMap != null && GBrowserIsCompatible()) {

        map = new GMap2(divMap);
        //map.addControl(new GSmallMapControl());
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        //here we need to call c# method "GeoCoder.GetLatLng(address)" to return Latitude & longitude and use them below.
        //showAddress(home);

        showHome(home, homeInfoHtml, zoomLevel, showInfo);
      }
      return;
    }


    function createMarker(posn, title, icon_image, icon_image_shadow) {
      var icon = getIcon(icon_image,icon_image_shadow);
      var marker = new GMarker(posn, {title: title, icon: icon, draggable:false });
      return marker;
    }

    function addMarkerObjectToMap(app,markerObject){
      if(app.markerList == null){
        app.markerList = new Array();
      }
      app.markerList.push(markerObject);
    }

    //The openInfoHtml styling done here
    App.prototype.OnMarkerClick = function(markerObject) {
      map.closeInfoWindow();
      
      var htmlNode ="<div class=gs-localResult gs-result>";
      htmlNode +=  "<div class=gs-title><a target=_blank class=gs-title href=";
      htmlNode += markerObject.result.url;
      htmlNode += ">";
      htmlNode += markerObject.result.title;
      htmlNode += "</a></div><div class=gs-address>";

      if (markerObject.result.streetAddress)
      {
      	htmlNode += "<div class=gs-street>" + markerObject.result.streetAddress + "</div>";
      }
      
      if (markerObject.result.city){
      	htmlNode += "<div class=gs-city>" + markerObject.result.city + ", </div>";
      }
      
      if (markerObject.result.region){
      	htmlNode += "<div class=gs-region>" + markerObject.result.region + "</div>";
      }

      if (markerObject.result.country)
      {
      	htmlNode += "<div class=gs-country>" + markerObject.result.country + "</div>";
      }

      htmlNode += "</div>";
      
      if (markerObject.result.phoneNumbers)
      {
      	htmlNode += "<div class=gs-phone>" + markerObject.result.phoneNumbers[0].number	+ "</div>";
      }
      
      if (markerObject.result.ddUrl)      
      {
      	htmlNode += "<div class=gs-directions><a class=gs-directions target=_blank href=";
      	htmlNode += markerObject.result.ddUrl;
      	htmlNode += ">directions</a></div>"
      }
      htmlNode += "</div>";
      //markerObject.gmarker.setInfoWindow(htmlNode);
      markerObject.gmarker.openInfoWindow(htmlNode);

    }


    function method_closure(object, method, opt_argArray) {
      return function() {
        return method.apply(object, opt_argArray);
      }
    }

     function getIcon(imgFile, shadowFile) {
        var icon = new GIcon();
        icon.image = prefix_image_file + imgFile;
        icon.iconAnchor = new GPoint(16, 16);
        icon.infoWindowAnchor = new GPoint(16, 0);
        icon.iconSize = new GSize(32, 32);
        icon.shadow = prefix_image_file + shadowFile;
        icon.shadowSize = new GSize(59, 32);
        return icon;
    }

    function showAddress(address, html_title) {
        searchAndShowAddress(address, html_title, address, false);
    }

    function searchAndShowAddress(address, html_title, address_title,  showInfo) {
      if (address == null || address == "") return;
      if (geocoder) {
          geocoder.getLatLng(
          address,
          function(point) {
              if (!point) {
                  //alert(address + " not found");
              } else {
                  //var market = new GMarker(point);
              //console.log(point);
                //map.setCenter(point);
                  var marker = new GMarker(point);
                  GEvent.addListener(marker, "click",
                function() {
                    marker.openInfoWindowHtml(html_title);
                }
              );
                  map.addOverlay(marker);
                  if (showInfo) {
                      marker.openInfoWindowHtml(html_title);
                  }
              }
          }
        );
      }
    }

    function showHome(address, homeInfoHtml, zoomLevel, showInfo) {
      if(address == null || address == "") return;
      if (geocoder) {
          geocoder.getLatLng(
          address,
          function(point) {
              if (!point) {
                  //alert(address + " not found");
              } else {
                  map.setCenter(point, zoomLevel);

                  var marker = new GMarker(point);
                  GEvent.addListener(marker, "click",
                function() {
                    marker.openInfoWindowHtml(homeInfoHtml);
                }
              );

                  main_marker = marker;

                  map.addOverlay(marker);
                  if (showInfo) {
                      marker.openInfoWindowHtml(homeInfoHtml);
                  }
              }

              //Show highlights
              showHighlights();

          }
        );
      }      
    }