jQuery(document).ready(function(){
	//getMap("","","div_content");
});


var map = null;
var geocoder = null;
var mapLoaded = false;

function load(id, address, html)
{
    

    if (GBrowserIsCompatible())
        {
		var map = new GMap2(document.getElementById(id));
                var geocoder = new GClientGeocoder();

                var markerHtml = html;
                var encodeAddress = encodeURI(address);

                geocoder.getLatLng( address,function(point)
		{
			if (!point) {
				alert("Вы ввели неправильный адрес.");
			} else if (GBrowserIsCompatible())
			{
				map.addControl(new GLargeMapControl());
				//map.addControl(new GMapTypeControl());
				//map.addControl(new GOverviewMapControl());
				map.enableDoubleClickZoom();
				map.setCenter(point, 15);
				var marker = new GMarker(point);
				map.addOverlay(marker);

				GEvent.addListener(marker, "click", function()
							{marker.openInfoWindowHtml(markerHtml);});
				marker.openInfoWindowHtml(markerHtml);		
				
			}
		});
                mapLoaded = true;		
        }
}

function loadWithLL(id, lat,lng, html)
{


    if (GBrowserIsCompatible())
        {
		var map = new GMap2(document.getElementById(id));               

                var markerHtml = html;

		var point = new GLatLng(lat,lng);

		if (!point) {
				alert("Вы ввели неправильный адрес.");
			} else if (GBrowserIsCompatible())
		{
			map.addControl(new GLargeMapControl());
			//map.addControl(new GMapTypeControl());
			//map.addControl(new GOverviewMapControl());
			map.enableDoubleClickZoom();
			map.setCenter(point, 15);
			var marker = new GMarker(point);
			map.addOverlay(marker);

			GEvent.addListener(marker, "click", function()
						{marker.openInfoWindowHtml(markerHtml);});
			marker.openInfoWindowHtml(markerHtml);

		}
                
                mapLoaded = true;
        }
	return map;
}

function createMap(id)
{
	if (GBrowserIsCompatible())
        {
		var map = new GMap2(document.getElementById(id));
		map.addControl(new GLargeMapControl());
		map.enableDoubleClickZoom();
	}

	return map;
}

function setMarker(map,address, html)
{
	if (GBrowserIsCompatible())
        {		
                var geocoder = new GClientGeocoder();

                var markerHtml = html;
                var encodeAddress = encodeURI(address);

                geocoder.getLatLng( address,function(point)
		{
			if (!point) {
				alert("Вы ввели неправильный адрес.");
			} else if (GBrowserIsCompatible())
			{				
				var marker = new GMarker(point);
				map.addOverlay(marker);

				

				GEvent.addListener(marker, "click", function()
							{marker.openInfoWindowHtml(markerHtml);});
				marker.openInfoWindowHtml(markerHtml);

			}
		});
                mapLoaded = true;
        }
}

function setMarkerLL(map,lat, lng, html)
{
	if (GBrowserIsCompatible())
        {

                var markerHtml = html;

		var point = new GLatLng(lat,lng,true);

		if (!point) {
			alert("Вы ввели неправильный адрес.");
		} else if (GBrowserIsCompatible())
		{
			var marker = new GMarker(point);
			map.addOverlay(marker);			

			GEvent.addListener(marker, "click", function()
						{marker.openInfoWindowHtml(markerHtml);});

			marker.openInfoWindowHtml(markerHtml);

		}
               
		
                mapLoaded = true;
        }
}


function getMap(address,html_bubble,div_content_id)
{
    jQuery.ajax({
	    url:"actions/getMap.php",
	    data:{address:address,html_bubble:html_bubble},
	    beforeSend:function(){jQuery("#"+div_content_id).html("Загрузка...")},
	    success:function(data){
		    jQuery("#"+div_content_id).html(data);
	    }
    });
}
