var google_maps_load = 0;

var map;
var geocoder;

var google_maps_latitude_default = "52.227799";
var google_maps_altitude_default = "19.505859";

var google_map;
var user_marker = null;

function google_maps_initialize( latitude, altitude, nameID )
{
	if ( google_maps_load == 0 )
	{	
    	google_maps_load = 1;
    	if (GBrowserIsCompatible()) 
    	{
    		google_map = new GMap2( document.getElementById(nameID) );        
        	if ( latitude == 0 && altitude == 0 )
        	{
        		google_map.setCenter(new GLatLng(google_maps_latitude_default,google_maps_altitude_default), 6);
        	}	
        	else
        	{
        		google_map.setCenter(new GLatLng(latitude, altitude), 6);
        	}        	        	        	  

		google_map.addControl(new GSmallMapControl());
        	google_map.addControl(new GMapTypeControl());
        	google_map.addControl(new GScaleControl());		           
    	}
	}
}

function google_maps_geocoder( nameID )
{	
	if (GBrowserIsCompatible()) {
		geocoder = new GClientGeocoder();
		GEvent.addListener(google_map, "click", function(overlay, latlng){
			if (latlng && user_marker == null) {	
				document.getElementById('lat').value = latlng.lat();
				document.getElementById('lng').value = latlng.lng();
			    createMarker( latlng.lat(), latlng.lng(), true);	
			}
		});
	}	 
}

function createMarker( latitude, altitude, drag)
{
	var marker = new GMarker(new GLatLng(latitude,altitude), {draggable: drag});
	dragProp(marker);
    google_map.addOverlay(marker);	
    user_marker = marker;
    return marker;
}

function dragProp( marker )
{
	GEvent.addListener(marker, "dragend", function(overlay, latlng){	
		var latlng = marker.getLatLng();	
		document.getElementById('lat').value = latlng.lat();
		document.getElementById('lng').value = latlng.lng();	
	});	
}

function deleteMarker()
{
	if (user_marker != null)
	{
		google_map.removeOverlay(user_marker);
		document.getElementById('lat').value = '';
		document.getElementById('lng').value = '';		
		user_marker = null;
	}
}

function focus(latitude, altitude)
{
	google_map.setCenter(new GLatLng(latitude, altitude), 10);
}

function createInfoWindow( marker, uid, uname, photo_id)
{	
	var zdjecie="<img src='http://discostacja.pl/inc/img/user/user.png' height='60' align='left' border='0'>";
	if(photo_id){
		zdjecie=" <img src='http://discostacja.pl/inc/img/user/" + photo_id + "' height='60' align='left' border='0'>";
	}
	var strHtml ="<a href='http://discostacja.pl/profil/" + uid + "' class='mapinfo' style='color:#000;'>"+ zdjecie  + uname + "</a>";
	
	GEvent.addListener(marker, "click", function() { 				  				
		 marker.openInfoWindowHtml( strHtml );
	});	
}

function createInfoWindow2( marker, uid, uname)
{	
	var strHtml = "<a href='http://discostacja.pl/profil/koncert-podglad/id/" + uid + "'>" + uname + "</a>";
	
	GEvent.addListener(marker, "click", function() { 				  				
		 marker.openInfoWindowHtml( strHtml );
	});	
}



