function GoogleMaps(id, fromAddress, toAddress, country, language, toName)
{
	var map;
	var gdir;
	var geocoder;
	var marker;
	
	this.id				= id;
	this.fromAddress 	= fromAddress;
	this.toAddress 		= toAddress;
	this.country		= country;
	this.language		= language;
	this.toName			= toName;
	this.created		= false;
	
	
	this.ShowLocation	= function()
	{
		this.geocoder.getLocations(this.toAddress + " " + this.country, this.AddLocationToMap);
	}
	
	this.New			= function()
	{
		if (GBrowserIsCompatible() && !this.created) 
		{    
			this.map = new GMap2(document.getElementById(this.id+"_canvas"));
			this.map.addControl(new GSmallMapControl());
			this.map.addControl(new GMapTypeControl());
			this.map.setCenter(new GLatLng(34, 0), 16);			

			this.gdir = new GDirections(this.map, document.getElementById(this.id+"_directions"));
			GEvent.addListener(this.gdir, "error", this.HandleErrors);
			this.geocoder = new GClientGeocoder();
			
			this.ShowLocation();
		}
		this.created		= true;
	}	
	
		
	
	
	function AddLocationToMapFunction(response)
	{ 
		this.map.clearOverlays();
		
		if (!response || response.Status.code != 200) 
    	{
			$ES('.error').setStyle('display', 'block');
			this.map.setCenter(new GLatLng(34, 0), 1);	
    	} 
    	else 
		{
			place = response.Placemark[0];
			point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
			this.marker = new GMarker(point, {clickable: true, title: place.address});
			this.map.addOverlay(this.marker);        
			this.marker.openInfoWindowHtml("<strong>" + this.toName + " </strong><br/>" + this.toAddress);
			GEvent.addListener(this.marker, "click", this.ShowInfoWindow);
			
      	}
	}
	this.AddLocationToMap = AddLocationToMapFunction.bind(this);
	
	function ShowInfoWindowFunction()
	{
		this.marker.openInfoWindowHtml(this.marker.getTitle());
	}
	this.ShowInfoWindow = ShowInfoWindowFunction.bind(this);
	
    
	this.SetDirections	= function(fromAddress, toAddress) 
	{
		this.New();
		this.fromAddress		= fromAddress;
		this.toAddress			= toAddress;		
		
		this.gdir.clear();
		this.gdir.load("from: " + this.fromAddress + " to: " + this.toAddress + " " + this.country, { "locale": this.language+"_"+this.country});
				
		$ES('.directions').setStyle('display', 'block');
		$ES('.error').setStyle('display', 'none');
	}
		
	function HandleErrorsFunction()
	{
		// error!
		$ES('.error').setStyle('display', 'block');
	}	
	this.HandleErrors	= HandleErrorsFunction.bind(this)
}
