class PhotoModeToggle extends inkToggleController
{
	private editable var m_SelectedWidget : inkWidgetRef;
	private editable var m_FrameWidget : inkWidgetRef;
	private editable var m_IconWidget : inkImageRef;
	private editable var m_LabelWidget : inkTextRef;
	var m_photoModeGroupController : weak< PhotoModeTopBarController >;
	private var m_fadeAnim : inkAnimProxy;
	private var m_fade2Anim : inkAnimProxy;

	protected event OnInitialize()
	{
		inkWidgetRef.SetVisible( m_SelectedWidget, false );
		inkWidgetRef.SetOpacity( m_FrameWidget, 0.1 );
		inkImageRef.Get( m_IconWidget ).BindProperty( 'tintColor', 'MainColors.Red' );
		inkTextRef.Get( m_LabelWidget ).BindProperty( 'tintColor', 'MainColors.Red' );
		RegisterToCallback( 'OnToggleChanged', this, 'OnToggleChanged' );
		RegisterToCallback( 'OnRelease', this, 'OnToggleClick' );
	}

	protected event OnUninitialize()
	{
		UnregisterFromCallback( 'OnToggleChanged', this, 'OnToggleChanged' );
		UnregisterFromCallback( 'OnRelease', this, 'OnToggleClick' );
	}

	private function PlayFadeAnimation( widget : inkWidgetRef, opacity : Float ) : inkAnimProxy
	{
		var animDef : inkAnimDef;
		var animInterp : inkAnimTransparency;
		if( inkWidgetRef.GetOpacity( widget ) == opacity )
		{
			return NULL;
		}
		animDef = new inkAnimDef;
		animInterp = new inkAnimTransparency;
		animInterp.SetStartTransparency( inkWidgetRef.GetOpacity( widget ) );
		animInterp.SetEndTransparency( opacity );
		animInterp.SetDuration( 0.25 );
		animInterp.SetDirection( inkanimInterpolationDirection.To );
		animInterp.SetUseRelativeDuration( true );
		animDef.AddInterpolator( animInterp );
		return inkWidgetRef.PlayAnimation( widget, animDef );
	}

	protected event OnToggleChanged( controller : weak< inkToggleController >, isToggled : Bool )
	{
		inkWidgetRef.SetVisible( m_SelectedWidget, true );
		if( isToggled )
		{
			if( m_fadeAnim != NULL )
			{
				m_fadeAnim.Stop();
			}
			m_fadeAnim = PlayFadeAnimation( m_SelectedWidget, 0.1 );
			if( m_fade2Anim != NULL )
			{
				m_fade2Anim.Stop();
			}
			inkWidgetRef.StopAllAnimations( m_FrameWidget );
			m_fade2Anim = PlayFadeAnimation( m_FrameWidget, 1.0 );
			inkWidgetRef.Get( m_FrameWidget ).BindProperty( 'tintColor', 'MainColors.Red' );
			inkImageRef.Get( m_IconWidget ).BindProperty( 'tintColor', 'MainColors.Blue' );
			inkTextRef.Get( m_LabelWidget ).BindProperty( 'tintColor', 'MainColors.Blue' );
		}
		else
		{
			if( m_fadeAnim != NULL )
			{
				m_fadeAnim.Stop();
			}
			m_fadeAnim = PlayFadeAnimation( m_SelectedWidget, 0.0 );
			if( m_fade2Anim != NULL )
			{
				m_fade2Anim.Stop();
			}
			inkWidgetRef.StopAllAnimations( m_FrameWidget );
			m_fade2Anim = PlayFadeAnimation( m_FrameWidget, 0.1 );
			inkWidgetRef.Get( m_FrameWidget ).BindProperty( 'tintColor', 'MainColors.Red' );
			inkImageRef.Get( m_IconWidget ).BindProperty( 'tintColor', 'MainColors.Red' );
			inkTextRef.Get( m_LabelWidget ).BindProperty( 'tintColor', 'MainColors.Red' );
		}
	}

	protected event OnToggleClick( e : inkPointerEvent )
	{
		if( e.IsAction( 'click' ) )
		{
			m_photoModeGroupController.SelectToggle( this );
		}
	}

	public function SetEnabledOnTopBar( enabled : Bool )
	{
		GetRootWidget().SetVisible( enabled );
	}

	public function GetEnabledOnTopBar() : Bool
	{
		return GetRootWidget().IsVisible();
	}

}

