    var map, geocoder, searchControl; 
      
    function load() 
    {
      if (GBrowserIsCompatible()) 
      {

        var opts = {
           googleBarOptions : {
           style : 'new',
           adsOptions : {
            client : 'partner-pub-9490590989861158'
           }
         }
        }

        map = new google.maps.Map2(document.getElementById("map"), opts);
        geocoder = new google.maps.ClientGeocoder();

        map.addControl(new google.maps.LargeMapControl());
        map.addControl(new google.maps.MapTypeControl());

        map.enableGoogleBar(); 

        initMap(lat,lng,zml);

        map.setCenter(new google.maps.LatLng(eval(lat),  eval(lng)), eval(zml), google.maps.G_NORMAL_MAP);

        google.maps.Event.addListener(map,"moveend",function()
         {setCookie('gllat',map.getCenter().lat(),365);
          setCookie('glltd',map.getCenter().lng(),365);
          setCookie('glzml',map.getZoom(),365);});     

        google.maps.Event.addListener(map, "click", clickFunction); 

        var publisher_id = "pub-9490590989861158"; 
                       
        adsManagerOptions = {
        maxAdsOnMap : 1,
        style: 'adunit',
        channel: '' // This field is optional - replace with a channel number that you created for GooYAMLgle AdSense tracking
       };

       adsManager = new GAdsManager(map, publisher_id, adsManagerOptions);
       adsManager.enable(); 
      }

      // Create a search control
      //searchControl = new google.search.SearchControl();

      // Add in a full set of searchers
      //var localSearch = new google.search.LocalSearch();
      //searchControl.addSearcher(localSearch);
      //searchControl.addSearcher(new google.search.WebSearch());
      //searchControl.addSearcher(new google.search.NewsSearch());
      //searchControl.addSearcher(new google.search.ImageSearch());
      //searchControl.addSearcher(new google.search.VideoSearch());
      //searchControl.addSearcher(new google.search.BlogSearch());

      // Set the Local Search center point
      //localSearch.setCenterPoint(google.loader.ClientLocation.address.city+","+google.loader.ClientLocation.address.country);

     
      // Tell the searcher to draw itself and tell it where to attach
      //searchControl.draw(document.getElementById("searchcontrol"));
    }

     function getExpirydate( nodays)
      {
        var UTCstring;
        Today = new Date();
        nomilli=Date.parse(Today);
        Today.setTime(nomilli+nodays*24*60*60*1000);
        UTCstring = Today.toUTCString();
        return UTCstring;
      }

      function getCookie(cookiename) 
      {
      var cookiestring=""+document.cookie;
       var index1=cookiestring.indexOf(cookiename);
       if (index1==-1 || cookiename=="") return ""; 
       var index2=cookiestring.indexOf(';',index1);
       if (index2==-1) index2=cookiestring.length; 
       return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
      }

     function setCookie(name,value,duration)
     {
      cookiestring=name+"="+escape(value)+";EXPIRES="+getExpirydate(duration);
      document.cookie=cookiestring;
     }


     function initMap(_lat,_lng,_zml)
     {      
      if (_lat) lat = _lat;
      else 
       lat = getCookie('gllat');

      if (google.loader.ClientLocation)
       if (lat.length==0) lat = google.loader.ClientLocation.latitude; 

      if (!lat) lat = 55.68455275165637;

      if (_lng) lng = _lng;
      else 
       lng = getCookie('glltd');

      if (google.loader.ClientLocation)
       if (lng.length==0) lng = google.loader.ClientLocation.longitude;

      if (!lng) lng = 37.733917236328125;

      if (_zml) zml = _zml;
      else 
       zml = getCookie('glzml');

      if (zml.length==0) zml=8;
     }


    function clickFunction(overlay, latlng) {
      if (latlng) 
      {
        geocoder.getLocations(latlng, function(addresses) {
          if(addresses.Status.code != 200) {
            alert("Google reverse geocoder failed to find an address for " + latlng.toUrlValue());
          }
          else 
          {
            var address = addresses.Placemark[0];
            var lng = address.Point.coordinates[0];
            var lat = address.Point.coordinates[1];
           
            var myHtml = address.address;
            map.openInfoWindow(latlng, myHtml);

            cjAjaxEngine("/twitloc/gpslink.jsp?lat="+lat+"&lng="+lng, myHandler, myError);
          }
        });
      }
    }

    function myError()
    {
       alert("Could not create location link");
    }

    function myHandler(txt, xmlDoc)
    {
       var l = eval("("+txt+")");
       var s = "http://twitter.com/home?status=GPS%20location%3A%20"+l.link
       if (def_text!="")
          s+="%20"+encodeURIComponent(def_text);

       s+="%20via%20"+"http://bit.ly/88d3uZ"; 

       location.replace(s);       
    }

    function getStreet(addr)
    {
       if (addr.AddressDetails)
       {
         var o = addr.AddressDetails;
         if (o.Country)
         {
           o = o.Country;
           if (o.AdministrativeArea)
           {
             o = o.AdministrativeArea;

             if (o.Thoroughfare)
             { 
              if (o.Thoroughfare.ThoroughfareName) 
                return o.Thoroughfare.ThoroughfareName;
             }
             else
              if (o.SubAdministrativeArea)
              {
                o = o.SubAdministrativeArea.Locality;
                if (o)
                {  
                  if (o.Thoroughfare)
                  return o.Thoroughfare.ThoroughfareName;
                else
                  if (o.LocalityName)
                    return o.LocalityName;
                }
              }
              else
                if (o.Locality)
                { 
                  if (o.Locality.Thoroughfare) 
                       return o.Locality.Thoroughfare.ThoroughfareName;
                }
           } 
         }
       }
       return addr.address;
    }