// Complex Step
 function CombinedPresentationStep(pin, steps)
 {
	this.Pin = pin;
	this.Steps = steps;
	
	this.PerformStep = function(presentationId, stepIndex)
	{
		if (stepIndex >= this.Steps.length)
		{
			// TODO: determine what to do at this point.
			return;
		}
		
		// If nothing is passed in, assume that we're starting from the beginning of this sequence of steps
		if (!stepIndex)
		{
			stepIndex = 0;
		}
		
		this.Steps[stepIndex].PerformStep(presentationId);
	}
	
	this.Dispose = function()
	{
		for (var i = 0; i < this.Steps.length; i++)
		{
			this.Steps[i].Dispose();
			this.Steps[i] = null;
		}
		
		this.Steps = null;
		this.Pin = null;
	}
 }
 
 // Simple Steps
 function PresentationWaitStep(pin, waitTime, parent)
 {
	this.Pin = pin;
	this.WaitTime = waitTime;
	
	this.PerformStep = function(presentationId)
	{
		window.setTimeout('PresentationManager.Instance.OnStepComplete("' + presentationId + '");', waitTime);
	}
	
	this.Dispose = function()
	{
		this.WaitTime = null;
	}
 }
 
 // map - instance of VE Map
 // mapStyle - map style
 function PresentationSetMapStyleStep(pin, map, mapStyle)
 {
	// TODO: Validate input
	this.Pin = pin;
	this.Map = map;
	this.MapStyle = mapStyle;
	
	this.PerformStep = function(presentationId)
	{
		map.SetMapStyle(this.MapStyle);
		PresentationManager.Instance.OnStepComplete(presentationId);
	}
	
	this.Dispose = function()
	{
		this.Map = null;
		this.MapStyle = null;
	}			
 }
 
 // map - instance of VE Map
 // zoom - Zoom level, 1-19
 function PresentationSetMapZoomStep(pin, map, zoom)
 {
	this.Pin = pin;
	this.Map = map;
	this.Zoom = zoom;
	
	this.PerformStep = function(presentationId)
	{
		if (map.GetZoomLevel() == this.Zoom)
		{
			PresentationManager.Instance.OnStepComplete(presentationId);
		}
		else
		{
			// The Presentation should be subscribed the map view change
			map.SetZoomLevel(this.Zoom);
		}
	}
	
	this.Dispose = function()
	{
		this.Pin = null;
		this.Map = null;
		this.Zoom = null;
	}
 }
 
 function PresentationTravelStep(pin, map)
 {
	// TODO: Validate input
	this.Pin = pin;
	this.Map = map;
	
	this.PerformStep = function(presentationId)
	{
		// First hide the ERO.
		VEPushpin.Hide(true);
		
		var currentCenterInPixels = this.Map.LatLongToPixel(this.Map.GetCenter());
		var targetInPixels = this.Map.LatLongToPixel(this.Pin.LatLong);

		// TODO: Figure out what to do about the case where the map tries to move some but doesn't actually - we have issues if it doesn't trigger a change view.
		// For now, just recenter the map.
		this.Map.SetCenter(this.Pin.LatLong);
	}
	
	this.Dispose = function()
	{
		this.Pin = null;
		this.Map = null;
	}
 }
 
 function PresentationDisplayPinDetailsStep(pin, view)
 {
	this.Pin = pin;
	this.View = view;

	this.PerformStep = function(presentationId)
	{
		if (this.View)
		{
			this.View.Display(this.Pin);
		}
		else
		{
			var title = (this.Pin.Title != null && this.Pin.Title != "undefined" && this.Pin.Title.length > 0) ? escape(this.Pin.Title) : "";
			var details = (this.Pin.Details != null && this.Pin.Details != "undefined" && this.Pin.Details.length > 0) ? escape(this.Pin.Details) : "";
			
			VEPushpin.Show(this.Pin.m_vemap.GUID, this.Pin.ID, this.Pin.LatLong.Latitude, this.Pin.LatLong.Longitude, title, details, this.Pin.TitleStyle, this.Pin.DetailsStyle);
		}
		PresentationManager.Instance.OnStepComplete(presentationId);
	}
		
	this.Dispose = function()
	{
		this.Pin = null;
		this.View = null;
	}
 }
 
function PresentationHidePinDetailsStep(pin, view)
{
	this.Pin = pin;
	this.View = view;
	
	this.PerformStep = function(presentationId)
	{
		if (this.View)
		{
			this.View.Hide();
		}
		else
		{
			VEPushpin.Hide();
		}
		PresentationManager.Instance.OnStepComplete(presentationId);
	}
	
	this.Dispose = function()
	{
		this.Pin = null;
		this.View = null;
	}
}