var Map = {
	Map : null,
	LastPoint : null,
	BeforeMarker : null,
	Markers:new Array(),
	Start : function()
	{
	},
	StartMap : function( divId )
	{
		if ( GBrowserIsCompatible() ) 
		{
			Map.Map = new GMap2( document.getElementById( divId ) );
			Map.Map.setCenter( new GLatLng( 1, 1 ), 14 );
			Map.Map.addControl( new GLargeMapControl() );
			Map.Map.addControl( new GLargeMapControl() );
			Map.Map.addControl( new GMapTypeControl() );
			Map.Map.addControl( new GScaleControl() );
			Map.Map.addControl( new GOverviewMapControl(  ) );
		}
	},
	BuildMap : function( x, y )
	{
		if( !Map.Map )
		{
			Map.BuildMap( x, y );
			return;
		}
		window.setTimeout(function() 
		{
			Map.Map.panTo( new GLatLng( x, y ) );
		}, 1800);
	},
	BuildMapCity : function( city )
	{
		if( !Map.Map )
		{
			Map.BuildCityMap( city );
			return;
		}
		window.setTimeout(function() 
		{
		 	var geo = new GClientGeocoder();
		 	var punkt = '';
		 	geo.getLatLng(city,function(punkt)  
		 	{  
				Map.Map.panTo( punkt ); 
		 	});			
		}, 1800); 
	},	
	CleanPoint : function()
	{
		for( var i = 0; i < Map.Markers.length; i++ )
		{
			Map.Map.removeOverlay( Map.Markers[ i ] );
		}
		Map.Markers = new Array();
	},
	StaticPointMap : function( x, y, text, onClick, city_name )
	{
		window.setTimeout(function() 
		{
			if (city_name)
			{
			 	var geo = new GClientGeocoder();
			 	var pkt = '';
			 	geo.getLatLng(city_name,function(punkt)  
			 	{  
					pkt = punkt;
					return( punkt ); 
			 	});	
				var marker = new GMarker( pkt );
			}
			else
			{
				var marker = new GMarker( new GLatLng( x, y ) );
			}
			
			Map.Markers[ Map.Markers.length ] = marker;
			if( text )
			{
				if( onClick )
				{
					GEvent.addListener( marker, "click", function( ) {
						marker.openInfoWindow( text );
					} );
					Map.Map.addOverlay( marker );
					return;
				}
				else
				{
					Map.Map.addOverlay( marker );
					GEvent.addListener( marker, "click", function( ) {
						marker.openInfoWindow( text );
					} );
					marker.openInfoWindow( text );
					return;
				}
			}
			Map.Map.addOverlay( marker );
		}, 1200);
	},
	CanAddPoint : function()
	{
		window.setTimeout(function() 
		{
			GEvent.addListener( Map.Map, "click", function( marker, point ) {
				if( Map.BeforeMarker )
				{
					Map.Map.removeOverlay( Map.BeforeMarker );
				}
				Map.BeforeMarker = new GMarker( point );
				Map.Markers[ Map.Markers.length ] = Map.BeforeMarker;
				Map.Map.addOverlay( Map.BeforeMarker );
				Map.LastPoint = point;
			});
		}, 1200);
	},
	CanMovedPoint : function( x, y, orAdd )
	{
		if( !orAdd )
		{
			orAdd = 0;
		}
		window.setTimeout(function() 
		{
			Map.LastPoint = new GLatLng( x, y );
			var marker = new GMarker( Map.LastPoint, { draggable: true } );
			Map.BeforeMarker = marker;
			Map.Markers[ Map.Markers.length ] = marker;
			GEvent.addListener( marker, "dragend", function(  ) {
				Map.LastPoint = marker.getPoint();
			});
			GEvent.addListener( Map.Map, "click", function( marker, point ) {
				if( Map.BeforeMarker )
				{
					Map.Map.removeOverlay( Map.BeforeMarker );
				}
				Map.BeforeMarker = new GMarker( point, { draggable: true } );
				Map.Markers[ Map.Markers.length ] = Map.BeforeMarker;
				Map.Map.addOverlay( Map.BeforeMarker );
				Map.LastPoint = point;
				
				GEvent.addListener( Map.BeforeMarker, "dragend", function(  ) {
					Map.LastPoint = Map.BeforeMarker.getPoint();
				});
				
			});
			
			Map.Map.addOverlay( marker );
		}, 1200);
	},
	CanMovedPointCity : function( city_name )
	{
		window.setTimeout(function() 
		{
			 	var geo = new GClientGeocoder();
			 	geo.getLatLng(city_name,function(punkt)  
			 	{  
					var marker = new GMarker( punkt, { draggable: true } );
					Map.BeforeMarker = marker;
					Map.Markers[ Map.Markers.length ] = marker;
					GEvent.addListener( marker, "dragend", function(  ) {
						Map.LastPoint = marker.getPoint();
					});
					GEvent.addListener( Map.Map, "click", function( marker, point ) {
						if( Map.BeforeMarker )
						{
							Map.Map.removeOverlay( Map.BeforeMarker );
						}
						Map.BeforeMarker = new GMarker( point, { draggable: true } );
						Map.Markers[ Map.Markers.length ] = Map.BeforeMarker;
						Map.Map.addOverlay( Map.BeforeMarker );
						Map.LastPoint = point;
						
						GEvent.addListener( Map.BeforeMarker, "dragend", function(  ) {
							Map.LastPoint = Map.BeforeMarker.getPoint();
						});
						
					}); 
					Map.Map.addOverlay( marker );
			 	});	
		}, 1200);
	}	
}