///<summary>
///	A manager class to manage placemarks and categories
///</summary>
function MapPlacemarkManager()
{
	//#region private variables
	
	var _placemarkDictionary = new Object();
	var _centreLocation = null;
	
	//#endregion private variables


	//#region public methods
	
	///<summary>
	///	Add a new Placemark to the internal collection
	///</summary>
	this.addPlacemark = 
		function(mapPlacemark)
		{
			_placemarkDictionary[mapPlacemark.ID] = mapPlacemark;
			
			// Fire onAdd Event
			this.onAdd(mapPlacemark);
		};
		
	///<summary>
	///	Sets the Centre point for the Map for this Manager
	///</summary>
	this.setCentre = 
		function(location)
		{
			_centreLocation = location;
		};

	///<summary>
	///	Gets the Centre point for the Map for this Manager
	///</summary>		
	this.getCentre =
		function()
		{
			return _centreLocation;
		};
	
	//#endregion public methods
	
	
	//#region public 'events'
	
	///<summary>
	///	Event fired when a new MapPlacemark is added to the Manager
	///</summary>
	this.onAdd = 
		function(mapPlacemark)
		{
			// intentionally empty
		};
		
	//#endregion public 'events'		
}


///<summary>
/// Encapsulates a Placemark on a map
///</summary>
function MapPlacemark()
{
	//#region private variables
	
	var _location = null;
	
	//#endregion private variables
	
	//#region public fields
	
	this.ID = generateUniqueID();
	this.DatabaseID = -1;
	this.Description = "";
	this.Name = "";
	this.GooglePlacemarkReference = null;
	
	//#endregion public fields
	
	//#region private methods
	
	///<summary>
	///	Attempts to create a unique random value for use mainly in
	//	unique IDs. Most likely unique within a client's browser but not across multiple clients.
	///</summary>
	function generateUniqueID()
	{
		var result, i, j;
		result = '';
		for (j = 0; j < 32; j++)
		{
			if( j == 8 || j == 12|| j == 16|| j == 20)
			{
				result = result + '-';
			}
			
			i = Math.floor(Math.random()*16).toString(16).toUpperCase();
			result = result + i;
		}
		
		return result;
	}
	
	//#endregion private methods
	
	//#region public methods
	
	///<summary>
	///	Sets the GLatLng position of the Placemark by setting its GMarker reference's position
	///</summary>
	this.getLocation = 
		function()
		{
			var location = null;
			
			if (this.GooglePlacemarkReference != null)
			{
				location = this.GooglePlacemarkReference.getPoint();
			}
		
			return location;
		};
	
	///<summary>
	///	Gets the GLatLng position of the Placemark from its GMarker reference's position
	///</summary>
	this.setLocation = 
		function(location)
		{
			if (this.GooglePlacemarkReference != null)
			{
				this.GooglePlacemarkReference.setPoint(location);
			}
		};	
		
	//#endregion public methods
}