using UnityEngine;
using System.Collections;

#if !UNITY_5_0_0
using UnityEngine.SceneManagement;
#endif

public class Splash : MonoBehaviour {

    // Exposed variables & types
    //--------------------------------

    [SerializeField] string m_nextScene;
    [SerializeField] AudioCue m_soundSeaDads;
	[SerializeField] AudioCue m_soundTitle;
	[SerializeField] AudioCue m_soundTextIn;
	[SerializeField] AudioCue m_soundTextOut;
	[SerializeField] GameObject m_holdEscToQuit;

	bool m_canStart = false;

    // Private variables 
	//--------------------------------
    float m_escHeldTime = 0;
    
    // Public methods 
    //--------------------------------
    
    // Private methods 
    //--------------------------------


    void PlayAudioSeaDads()
	{
		SystemAudio.Play(m_soundSeaDads);
    }
    void PlayAudioTitle()
	{
		SystemAudio.Play(m_soundTitle);
	}
	void PlayTextIn()
	{
		SystemAudio.Play(m_soundTextIn);
	}
	void PlayTextOut()
	{
		SystemAudio.Play(m_soundTextOut);
    }

    void SetCanStart() { m_canStart = true; }
	
    void Update () 
    {
        if (m_canStart && Input.GetButtonDown("Jump"))
        {
            // TODO: Death anim or something!
            #if !UNITY_5_0_0
                SceneManager.LoadScene(m_nextScene);
            #else
                Application.LoadLevel(Application.loadedLevelName);
            #endif
        }


        if ( Input.GetKey(KeyCode.Escape) )
        {
			m_holdEscToQuit.SetActive(true);
			m_escHeldTime += Time.deltaTime;
			if ( m_escHeldTime > 1.5f )
			{
				Application.Quit();
			}

        }
        else 
        {
			m_holdEscToQuit.SetActive(false);
			m_escHeldTime = 0;
        }
    }
}
