
var gmarkers = [];
var m_cat = [];
var m_name = [];
var gicons = [];
var gshadow = [];
var map;
var text = "";
var cmap;
var zoomla;
var zoomlb;

var infowindow;
(function () {

  google.maps.Map.prototype.markers = new Array();
    
  google.maps.Map.prototype.addMarker = function(marker) {
    this.markers[this.markers.length] = marker;
    return marker;
  };
    
  google.maps.Map.prototype.getMarkers = function() {
    return this.markers
  };
    
  google.maps.Map.prototype.clearMarkers = function() {
    if(infowindow) {
      infowindow.close();
    }
    
    for(var i=0; i<this.markers.length; i++){
      this.markers[i].set_map(null);
    }
  };
})();

gicons["church"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon11.png", 
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["church"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon11s.png", 
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["gas"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon29.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["gas"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon29s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["hotel"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon28.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["hotel"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon28s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["bank"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon58.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["bank"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon58s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["adm"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon10.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["adm"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon10s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["other"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon13.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["other"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon13s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["shop"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal3/icon26.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["shop"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal3/icon26s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["hospital"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal3/icon46.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["hospital"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal3/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["hospital_vet"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/vet.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["hospital_vet"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal3/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sight"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sight"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sight_mon"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/modernmonument.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sight_mon"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sight_statue"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/statue.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sight_statue"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sight_villa"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/villa-tourism.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["destroyed"] = new google.maps.MarkerImage("http://terijoki.spb.ru/images/destroyed.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sight_villa"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sight_ruins"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/ancienttempleruin.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sight_ruins"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sight_cemetary"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/cemetary.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sight_cemetary"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sight_beach"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/beach.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sight_beach"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sight_fountain"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/fountain.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sight_fountain"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sight_museum"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/museum-archeological.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sight_museum"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sight_wheel"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/ferriswheel.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sight_wheel"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sight_lake"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/lake.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sight_lake"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sight_train"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/steamtrain.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sight_train"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sport_skicross"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/crosscountryskiing.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sport_skicross"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sport_skimount"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/skiing.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sport_skimount"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sport_sail"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/sailboat-sport.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sport_sail"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sport_skateice"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/iceskating.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sport_skateice"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sport_skateboard"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/skateboarding.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sport_skateboard"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["sport_tennis"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/tennis2.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["sport_tennis"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["photo"] = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/photo.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["photo"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon46s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["camp"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon53.png", 
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["camp"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal4/icon53s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["place"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal3/icon56.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["place"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal3/icon56s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["service"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon29.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["service"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon29s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gicons["eat"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon27.png",
                   new google.maps.Size(32, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));
gshadow["eat"] = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal2/icon27s.png",
                   new google.maps.Size(56, 32),
                   new google.maps.Point(0,0),
                   new google.maps.Point(16, 32));

//
function gup( name )
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

//
var zl = gup('zl');
var lol = gup('lo');
var lal = gup('la');
var cat = gup('cat');
var xdf = gup('xd');

var ob = -1;
ob = gup('ob');

if ( xdf.length < 2 ) { xdf = '01'; }
var xmlf = 'trk_gmap_data-' + xdf + '.xml';
if ( cat.length < 2 ) { cat = 'sight'; }

//
function createStreet(pts, colour, width, html) {

// old: var street = new GPolyline(pts,colour,width);

 var street = new google.maps.Polyline({
    path: pts,
    strokeColor: colour,
    strokeOpacity: 0.5,
    strokeWeight: width
 });

 street.setMap(map);               

  infowindow = new google.maps.InfoWindow({
    content: html
  });

  google.maps.event.addListener(street, "click", function(event) {
// old:    map.openInfoWindow(pts[0],html);
//    infowindow.open(map,pts[0]);
     infowindow.content = html; 
     infowindow.position = event.latLng;
     infowindow.open(map); 
  });

  return street;
}

// == shows all markers of a particular category, and ensures the checkbox is checked ==
function show(category) {
  for (var i=0; i<gmarkers.length; i++) {
     if (m_cat[i] == category) {
        gmarkers[i].setVisible(true);
     }
 }
 // == check the checkbox ==
 document.getElementById(category+"box").checked = true;
}

// == hides all markers of a particular category, and ensures the checkbox is cleared ==
function hide(category) {
  for (var i=0; i<gmarkers.length; i++) {
    if (m_cat[i] == category) {
      gmarkers[i].setVisible(false);
    }
  }
  // == clear the checkbox ==
  document.getElementById(category+"box").checked = false;
  // == close the info window, in case its open on a marker that we just hid
// old:  map.closeInfoWindow();
// temporary:  infowindow.close();
}

//
function myclick(i) {
  google.maps.event.trigger(gmarkers[i],"click");
}

// == rebuilds the sidebar to match the markers currently displayed ==
function makeSidebar() {
  text = "";
  for (var i=0; i<gmarkers.length; i++) {
    if (gmarkers[i].getVisible()) {
      text += '- <a href="javascript:myclick(' + i + ')">' + m_name[i] + '</a><br>';
    }
  }
  text = '<p>' + text + '</p>';
  document.getElementById("side_bar").innerHTML = text;
}

// == a checkbox has been clicked ==
function boxclick(box,category) {
  if (box.checked) {
    show(category);
  } else {
    hide(category);
  }
  // == rebuild the side bar
  makeSidebar();
}

// former createMap function
function initialize() {

 var myOptions = {
    zoom: 13,
    center: new google.maps.LatLng(60.2, 29.698),
    mapTypeControl: true,
    scrollwheel: false,
    mapTypeId: google.maps.MapTypeId.ROADMAP
 };

// var map = new google.maps.Map(document.getElementById("map"), myOptions);
 map = new google.maps.Map(document.getElementById("map"), myOptions);

// Traffic layer 12.08.2010
// var trafficLayer = new google.maps.TrafficLayer();
// trafficLayer.setMap(map);
                                     
 google.maps.event.addListener(map, 'dragend', function() {
   cmap = map.getCenter();
   zoomla = map.getZoom();
   var latLngStr = '(' + cmap.lat() + ', ' + cmap.lng() + ') zoom=' + zoomla;
   document.getElementById("message").innerHTML = latLngStr;
   var clink = '<a href="?xd=' + xdf + '&lo=' + cmap.lat() + '&la=' + cmap.lng() + '&zl=' + zoomla + '">Ссылка на текущую карту</a>';
   document.getElementById("clink").innerHTML = clink;
 });
 
 google.maps.event.addListener(map, 'zoom_changed', function() {
//   zoomlb = map.getZoom();
   cmap = map.getCenter();
   zoomla = map.getZoom();
   var latLngStr = '(' + cmap.lat() + ', ' + cmap.lng() + ') zoom=' + zoomla;
   document.getElementById("message").innerHTML = latLngStr;
   var clink = '<a href="?xd=' + xdf + '&lo=' + cmap.lat() + '&la=' + cmap.lng() + '&zl=' + zoomla + '">Ссылка на текущую карту</a>';
   document.getElementById("clink").innerHTML = clink;
//   var zoomlStr = '(' + zoomlb + ')';
//   document.getElementById("zoom").innerHTML = zoomlStr;
 });

// Geocode right-click listener
google.maps.event.addListener(map, 'rightclick', function(eve){
geocode({latLng: eve.latLng});
});

 downloadUrl(xmlf, function(data) {
//
  var area = data.documentElement.getElementsByTagName("area");
  if ( zl == "" ) { zl = area[0].getAttribute("zl"); }
  if ( lol == "" ) { lol = area[0].getAttribute("lol"); }
  if ( lal == "" ) { lal = area[0].getAttribute("lal"); }
  map.setCenter(new google.maps.LatLng(lol, lal));
  map.setZoom(parseInt(zl));
//  
  var markers = data.documentElement.getElementsByTagName("info");
  for (var i = 0; i < markers.length; i++) {
       var category = markers[i].getAttribute("topic");
       var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")),
                            parseFloat(markers[i].getAttribute("lng")));
       var icontype = markers[i].getAttribute("icon");
       var info = markers[i].getAttribute("html");
       var name = markers[i].getAttribute("name");
/*      
       var marker = new google.maps.Marker({
          position: point,
          map: map,
          shadow: gshadow[icontype],
          icon: gicons[icontype],
          title: markers[i].getAttribute("name")
      });
*/
      var marker = map.addMarker(createMarker(point, name, icontype, info));

//      attachMessage(marker, info);

      m_cat.push(category);
      m_name.push(name);
      gmarkers.push(marker);
  }

//  console.log(map.getMarkers());    
//  console.log(map.getMarkers());
  
// ========= Now process the polylines ===========
 var streets = data.documentElement.getElementsByTagName("street");
 if (streets.length > 0) {
// read each line
  for (var a = 0; a < streets.length; a++) {
// get any line attributes
     var colour = streets[a].getAttribute("colour");
     var width  = parseFloat(streets[a].getAttribute("width"));
     var html = streets[a].getAttribute("html");
// read each point on that line
     var nodes = streets[a].getElementsByTagName("point");
     var pts = [];
     for (var b = 0; b < nodes.length; b++) {
        pts[b] = new google.maps.LatLng(parseFloat(nodes[b].getAttribute("lat")), 
                             parseFloat(nodes[b].getAttribute("lng")));
     }
     var street = createStreet(pts, colour, width, html);
// old:     map.addOverlay(street);
  }
 }
// ================================================

  // == show or hide the categories initially ==
  if ( cat == 'camp' ) { show("camp"); } else { hide("camp"); }
  if ( cat == 'place' ) { show("place"); } else { hide("place"); }
  if ( cat == 'sight' ) { show("sight"); } else { hide("sight"); }
  if ( cat == 'service' ) { show("service"); } else { hide("service"); } 
  if ( cat == 'state' ) { show("state"); } else { hide("state"); } 
  if ( cat == 'pano' ) { show("pano");  } else { hide("pano"); } 
  if ( cat == 'sport' ) { show("sport"); } else { hide("sport"); }
  if ( cat == 'eat' ) { show("eat"); } else { hide("eat"); }
  // == create the initial sidebar ==
  makeSidebar();  

  if (ob > 0) myclick(ob);

  
 });

}

  function createMarker(point, name, icontype, info) {
    var marker = new google.maps.Marker({
         position: point,
         map: map,
         shadow: gshadow[icontype],
         icon: gicons[icontype],
         title: name
    });
    google.maps.event.addListener(marker, "click", function() {
      if (infowindow) infowindow.close();
      infowindow = new google.maps.InfoWindow({content: info});
      infowindow.open(map, marker);
    });
    return marker;
  }

/**
 * circle
 */
var thePoint = new google.maps.LatLng(60.2, 29.698);
var circle = new google.maps.Circle({radius: 10, center: thePoint}); 
//map.fitBounds(circle.getBounds());

// selector function
function play(){
//  var selector = document.getElementById("radius");
//  var radius = selector.options[selector.selectedIndex].innerHTML;
  var radius = 200;
  circle.setRadius(radius);
  circle.setCenter(map.getCenter());
  map.fitBounds(circle.getBounds());
  map.circleRadius = radius;
}

//play();

/**
* geocoder
*/
var geocoder = new google.maps.Geocoder();
//document.getElementById("search").value = "search";
function geocode(opts) {
  function geocodeResult(response, status) {
    if (status == google.maps.GeocoderStatus.OK && response[0]) {
      document.getElementById("search").value = response[0].formatted_address;
      //map.fitBounds(response[0].geometry.viewport);
      map.setCenter(response[0].geometry.location); 
      play();
    } else {
      alert("D'oh! " + status);
    }
  } // trim leading and trailing space with capable browsers
  if(opts.address && opts.address.trim)opts.address = opts.address.trim(); 
  if(opts.address || opts.latLng)geocoder.geocode(opts, geocodeResult); // no empty request
}

//function initialize() {
// createMap();
//}
