GoogleMap = function(container)
{
	container.style.display='';
	this._map = new google.maps.Map2(container);
	this._bounds = new GLatLngBounds();
}

GoogleMap.searchPoint = function (city, address, func_success, func_fail)
{
	var search;
	if (city && address)
		search=city+', '+address;
	else if (city)
		search=city;
	else if (address) {
		func_fail('Niekompletny adres, proszę wpisać miejscowość');
		return;
		search=address;
	} else
		search='Polska';
	var geocoder = new GClientGeocoder();	
	geocoder.getLatLng(search,function(point){
		if (point && (typeof(point) == 'object'))
		{
			func_success(point);
		}
		else
		{
			if (address && city)
				GoogleMap.searchPoint(city, false, func_success, func_fail);
			else
				func_fail(false);
		}
	});
    
}

GoogleMap.prototype.SetControll = function()
{
	this._map.addControl(new GSmallMapControl());
}

GoogleMap.prototype.GetLatLng = function(funcsuccess)
{
	GEvent.addListener(this._map,"click", function(overlay,latlng)
	{
		if (latlng)
			funcsuccess(latlng);
	});
}

GoogleMap.prototype.center = function(zoom)
{
	var zoomLevel = this._map.getBoundsZoomLevel(this._bounds);
	if (zoomLevel < 6) zoomLevel = 6;
	else if (zoomLevel > 13) zoomLevel = 13;
	var pointCenter = this._bounds.getCenter()
	if (zoom)
		zoomLevel=zoom;
	this._map.setCenter(pointCenter, zoomLevel);
}

GoogleMap.prototype.addPoint = function(point)
{
	var pointGeo = new GLatLng(point.latitude, point.longitude);
	var marker = this.createMarker(pointGeo, point.name, (point.cont)?point.cont:false);
	this._bounds.extend(pointGeo);
	return marker;
}

GoogleMap.prototype.addPoints = function(points)
{
	for (var i in points)
		this.addPoint(points[i]);
}

GoogleMap.prototype.createMarker = function(pointGeo, name, html, icon)
{
	var marker = new GMarker(pointGeo);
	if (name || html)
	{
		var contentBox='';
		if (name)
		{
			contentBox+='<b>'+name+'</b>';
			if (html)
				contentBox+='<br /><br />';
		}
		if (html)
			contentBox+=html;
		GEvent.addListener(marker, "click", function(){
			marker.openInfoWindowHtml(contentBox);
		});
	}
	this._map.addOverlay(marker);
	return marker;
}
