     var map=null;
     var geocoder=null;
     var mrk=null;
     var lastMarker = null;

     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.addMapType(google.maps.G_SATELLITE_3D_MAP);

         map.enableScrollWheelZoom();
         map.enableContinuousZoom();
*/
         map.setUIToDefault();

         initMap(lat,lng,zml);

/*
         map.addControl(new google.maps.LargeMapControl());
         map.addControl(new google.maps.OverviewMapControl(new google.maps.Size(250,135)));

*/

         map.addControl(new ExtMapTypeControl({showTraffic: true, showTrafficKey: true}));
         map.enableGoogleBar(); 

         if (mrk)
         {
          var point = new google.maps.LatLng(lat, lng);
          lastMarker = new google.maps.Marker(point);
          map.addOverlay(lastMarker);
          google.maps.Event.addListener(lastMarker, "click", function() {
            var link = "http://bigmap.linkstore.ru?lat="+lat+"&lng="+lng+"&zml="+zml+"&mrk=1";
            var myHtml = "<b>Lat:</b> " + lat +" <br><b>Lng:</b> "+lng
                       + "<br/><b>Local:</b> "
                       + "<a title='Local news' target='_blank' href='http://tgazeta.linkstore.ru?lat="+lat+"&lng="+lng+"'>news</a>"
                       + " &nbsp; <a title='Local people' target='_blank' href='http://lt.linkstore.ru?lat="+lat+"&lng="+lng+"'>people</a>"
                       + " &nbsp; <a title='Local photo' target='_blank' href='http://photomap.linkstore.ru?lat="+lat+"&lng="+lng+"'>photo</a>"
                       + "<br/><b>Misc:</b> "
                       + "<a title='Local search' target='_blank' href='http://geo.linkstore.ru?lat="+lat+"&lng="+lng+"'>search</a>"
                       + " &nbsp; <a title='link to this' target='_blank' href='http://bigmap.linkstore.ru?lat="+lat+"&lng="+lng+"&zml="+zml+"&mrk=1'>link</a>"
                       + " &nbsp; <a title='create a forum' target='_blank' href='http://geotalk.linkstore.ru?lat="+lat+"&lng="+lng+"&zml="+zml+"'>forum</a>"
                       + " &nbsp; <a title='Google Buzz' target='_blank' href='http://www.google.com/reader/link?url="+encodeURIComponent(link)+"&title=Shared+location"+"&srcURL=http://www.servletsuite.com'>buzz</a>";
            map.openInfoWindowHtml(point, myHtml);
          });

         }

         google.maps.Event.addListener(map,"moveend",function()
         {
          var lat = map.getCenter().lat();
          var lng = map.getCenter().lng();
          var zml = map.getZoom();

          setCookie('gllat',lat,365);
          setCookie('glltd',lng,365);
          setCookie('glzml',zml,365);
          if (mrk)
          {
           if (lastMarker) map.removeOverlay(lastMarker);
           var point = new google.maps.LatLng(lat, lng);
           var t = "Lat:"+lat + " Lng:"+lng;
           lastMarker = new google.maps.Marker(point,{title:t});
           map.addOverlay(lastMarker);
           google.maps.Event.addListener(lastMarker, "click", function() {
            var link = "http://bigmap.linkstore.ru?lat="+lat+"&lng="+lng+"&zml="+zml+"&mrk=1";
            var myHtml = "<b>Lat:</b> " + lat +" <br><b>Lng:</b> "+lng
                       + "<br/><b>Local:</b> "
                       + "<a title='Local news' target='_blank' href='http://tgazeta.linkstore.ru?lat="+lat+"&lng="+lng+"'>news</a>"
                       + " &nbsp; <a title='Local people' target='_blank' href='http://lt.linkstore.ru?lat="+lat+"&lng="+lng+"'>people</a>"
                       + " &nbsp; <a title='Local photo' target='_blank' href='http://photomap.linkstore.ru?lat="+lat+"&lng="+lng+"'>photo</a>"
                       + "<br/><b>Misc:</b> "
                       + "<a title='Local search' target='_blank' href='http://geo.linkstore.ru?lat="+lat+"&lng="+lng+"'>search</a>"
                       + " &nbsp; <a title='link to this' target='_blank' href='http://bigmap.linkstore.ru?lat="+lat+"&lng="+lng+"&zml="+zml+"&mrk=1'>link</a>"
                       + " &nbsp; <a title='create a forum' target='_blank' href='http://geotalk.linkstore.ru?lat="+lat+"&lng="+lng+"&zml="+zml+"'>forum</a>"
                       + " &nbsp; <a title='Google Buzz' target='_blank' href='http://www.google.com/reader/link?url="+encodeURIComponent(link)+"&title=Shared+location"+"&srcURL=http://www.servletsuite.com'>buzz</a>";
  
            map.openInfoWindowHtml(point, myHtml);
          });

          }
         });

        }

        google.maps.Event.addListener(map, "click", clickFunction);

        var publisher_id = "pub-9490590989861158"; 

        adsManagerOptions = {
        maxAdsOnMap : 2,
        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();
    }

     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 
          { address = addresses.Placemark[0];
            var myHtml = address.address;
            map.openInfoWindow(latlng, myHtml); }
        });
      }
    }
         
     function SetMarker(map)
     {
        if (mrk) 
        {
          mrk = false;
          if (lastMarker)
          {
             map.removeOverlay(lastMarker);
             lastMarker = null;
          }
        }
        else
        {
          mrk = true; 
          var lat = map.getCenter().lat();
          var lng = map.getCenter().lng();
          var zml = map.getZoom();
          var point = new google.maps.LatLng(lat, lng);
          var t = "Lat:"+lat + " Lng:"+lng;

          lastMarker = new google.maps.Marker(point,{title:t});
          map.addOverlay(lastMarker);
          google.maps.Event.addListener(lastMarker, "click", function() {
            var link = "http://bigmap.linkstore.ru?lat="+lat+"&lng="+lng+"&zml="+zml+"&mrk=1";
            var myHtml = "<b>Lat:</b> " + lat +" <br><b>Lng:</b> "+lng
                       + "<br/><b>Local:</b> "
                       + "<a title='Local news' target='_blank' href='http://tgazeta.linkstore.ru?lat="+lat+"&lng="+lng+"'>news</a>"
                       + " &nbsp; <a title='Local people' target='_blank' href='http://lt.linkstore.ru?lat="+lat+"&lng="+lng+"'>people</a>"
                       + " &nbsp; <a title='Local photo' target='_blank' href='http://photomap.linkstore.ru?lat="+lat+"&lng="+lng+"'>photo</a>"
                       + "<br/><b>Misc:</b> "
                       + "<a title='Local search' target='_blank' href='http://geo.linkstore.ru?lat="+lat+"&lng="+lng+"'>search</a>"
                       + " &nbsp; <a title='link to this' target='_blank' href='http://bigmap.linkstore.ru?lat="+lat+"&lng="+lng+"&zml="+zml+"&mrk=1'>link</a>"
                       + " &nbsp; <a title='create a forum' target='_blank' href='http://geotalk.linkstore.ru?lat="+lat+"&lng="+lng+"&zml="+zml+"'>forum</a>"
                       + " &nbsp; <a title='Google Buzz' target='_blank' href='http://www.google.com/reader/link?url="+encodeURIComponent(link)+"&title=Shared+location"+"&srcURL=http://www.servletsuite.com'>buzz</a>";
  
            map.openInfoWindowHtml(point, myHtml);
          });

        } 
         
     }


     function initMap(_lat,_lng,_zml)
     {
      var lat,lng,zml;

      if (_lat) lat = _lat;
      else 
       lat = getCookie('gllat');

      if (google.loader) 
       if (google.loader.ClientLocation)
	 if (lat.length==0) lat = google.loader.ClientLocation.latitude; 

      if (lat.length==0) lat = 55.68455275165637;

      if (_lng) lng = _lng;
      else 
       lng = getCookie('glltd');

      if (google.loader) 
       if (google.loader.ClientLocation)
	      if (lng.length==0) lng = google.loader.ClientLocation.longitude;

      if (lng.length==0) lng = 37.733917236328125;

      if (_zml) zml = _zml;
      else 
       zml = getCookie('glzml');

      if (zml.length==0) zml=4;

      map.setCenter(new google.maps.LatLng(lat,lng),parseInt(zml));
     }

      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 beforeAction()
   {
     document.body.style.cursor = 'wait';
   }

   function afterAction()
   {
     document.body.style.cursor = 'default';
   }

   function handlerFunction(txt, xmlDoc)
   {
     sendMail(txt);
   } 

   function handlerFunction1(txt, xmlDoc)
   {
     sendFacebook(txt);
   } 

   function handlerFunction2(txt, xmlDoc)
   {
     sendTwitter(txt);
   } 

   function errorFunction()
   {
     alert("Could not create URL for this map");
   }


   function sendMail(sUrl)
   {

     var subjectLine='Take a look at this map from http://bigmap.linkstore.ru'; 
     var bodyText='You can see this map at: '+sUrl;

     var message='mailto:?subject='+escape(subjectLine)+'&body='+escape(bodyText);
     var messageIE='mailto:?subject='+(subjectLine)+'&body='+escape(bodyText);     

     if(document.all) location.href=messageIE; 
     else  location.href=message; 
   }

   function sendTwitter(sUrl)
   { 
     var bodyText='look at this map: '+sUrl;

     var message='http://twitter.com/home?status='+escape(bodyText);

     location.href=message; 
   }

  function sendFacebook(sUrl)
  {
    var u=sUrl; t='Big map';
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
  }

   function getUrl(map)
   {
    var center = map.getCenter();
    var sUrl="http://bigmap.linkstore.ru/index.jsp?"
                 +"lng="+center.lng()
                 +"&lat="+center.lat()
                 +"&zml="+map.getZoom();
    if (mrk) sUrl+="&mrk=1";

    return sUrl;
   }


   function MailTo(map)
   {    
     var sUrl=getUrl(map);

     cjAjaxEngine("tinyurl.jsp?"+sUrl,handlerFunction,errorFunction,beforeAction,afterAction);
   }

   function sendFace(map)
   {
     var sUrl=getUrl(map);

     cjAjaxEngine("tinyurl.jsp?"+sUrl,handlerFunction1,errorFunction,beforeAction,afterAction);
   }

   function sendTwit(map)
   {
     var sUrl=getUrl(map);

     cjAjaxEngine("tinyurl.jsp?"+sUrl,handlerFunction2,errorFunction,beforeAction,afterAction);
   }

   function AddressDialog(map)
   {
      var o = document.getElementById("addressbar");
      if (o.style.display=='none') 
      {
        o.style.display="block";
        document.getElementById("idaddress").focus();
      }
      else                         o.style.display="none";
   }

   function lookupAddress(map)
   {
     var s = document.getElementById("idaddress").value;
     if (s!='')
       geocoder.getLocations(s,findCallback);
   }

  function findCallback(response)
  {
   if (!response) alert("Sorry, unable to find this");
   else
     if (response.Status.code!=200) 
       alert("Sorry, unable to find this"); 
     else
     {
       var place = response.Placemark[0];
       var lat = place.Point.coordinates[1];
       var lng = place.Point.coordinates[0];
      
       moveMap(lat,lng,15); 
       AddressDialog(map); 
     } 
  }

    function moveMap(lat,lng,zoom,mt)
    {
       var z;
       if (zoom) z = eval(zoom);
       else      z = map.getZoom();

       var m;

       if (mt) m = getGoogleMapType(mt);
       else    m = map.getCurrentMapType();

       map.setCenter(new google.maps.LatLng(eval(lat),eval(lng)),z,m);
    }
    
   function getGoogleMapType(mapType)
   {
     if (mapType=='0') return google.maps.G_NORMAL_MAP;
     else
      if (mapType=='1') return google.maps.G_SATELLITE_MAP;
      else
       if (mapType=='2') return google.maps.G_HYBRID_MAP;

     return google.maps.G_NORMAL_MAP;
   }












