jQuery(document).ready(function(){
   $().mousemove(function(e){
      //$('#status').html(e.pageX +', '+ e.pageY);
      pos_x = e.pageX;
      pos_y = e.pageY;
   }); 
})

function onPageLoad()
{
	if(typeof GoogleMapsInit == 'function')
	{
		GoogleMapsInit();
	}
	else
	{
		//alert('function NOT exists');
	}
}

var map = null;
var geocoder = null;

function initialize() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map_canvas"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
    
	//map.setCenter(new GLatLng(37.4419, -122.1419), 13);
	
	//center_point = new Gpont(37.28109, 55.671741);
	//map.setCenter(new GLatLng(37.28109, 55.671741), 13);
	
	
    geocoder = new GClientGeocoder();
	
	// Поселок станции хлопино
	// Звенигород
	
    geocoder.getLatLng(
      'Звенигород',
      function(point) {
        if (point) {
          map.setCenter(point, 10);
        }
        else
        {
			geocoder.getLatLng('Москва',
			  function(point) {
				if (point) {
				  map.setCenter(point, 10);
				}
			  }
			)
        }
      }
    );
    
    
  }
}

function showAddress(address, address2) {
//alert('search '+address);
  if (geocoder) {
    geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
          //alert(address + " not found");
          if (address2 != undefined)
          	showAddress(address2);
          else
          	addressNotFound();
        } else {
          addressFound();
          map.setCenter(point, 13);
          var marker = new GMarker(point);
          map.addOverlay(marker);
          marker.openInfoWindowHtml(address);
        }
      }
    );
  }
}

function markLocation(address, name)
{

  if (geocoder) {
    geocoder.getLatLng(
      address,
      function(point) {
        if (point) {
		  //alert(' , '+point.x+' !!! '+point.y);
          //map.setCenter(point, 13);
          var marker = new GMarker(point);
          map.addOverlay(marker);
		  
          GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(name);
          });
		  
          //marker.openInfoWindowHtml(name);
        }
      }
    );
  }
}


function addressNotFound()
{
	//alert('addressNotFound()');
	//document.getElementById('map_canvas').style.display = 'none';
	//document.getElementById('map_canvas_not_found').style.display = '';
}

function addressFound()
{
	//alert('addressFound()');
	//document.getElementById('map_canvas').style.display = '';
	//document.getElementById('map_canvas_not_found').style.display = 'none';
}
