using UnityEngine;
using System.Collections;

public class ExtraControls : MonoBehaviour {

	private string pauseScreen = "Main";

	private bool pauseToggle = false;

	private States states;

	public bool inCutscene = false;
	
	void Start ()
	{
		states = GameObject.Find("Player").GetComponent<States>();
	}

	void Update ()
	{

		if (!inCutscene)
		{
			if (Input.GetKeyDown (KeyCode.Escape) && GameObject.Find("Fader").GetComponent<SceneFader>().state == "Done")
			{
				pauseScreen = "Main";
				pauseToggle = !pauseToggle;
			}
		}

		if (pauseToggle)
			Time.timeScale = 0;
		else
			Time.timeScale = 1;

		if (GameObject.Find("Fader").GetComponent<SceneFader>().state == "Done")
		{
			if (pauseToggle)
			{
				states.pauseFlag = pauseToggle;
			} else {
				states.pauseFlag = pauseToggle;
			}
		}
	}

	void OnGUI ()
	{
		GUI.depth = -10;

		if (pauseToggle){
			switch (pauseScreen)
			{
				case "Main":
					if (GUI.Button(new Rect(Screen.width / 2f - 50, Screen.height / 2f - 55, 100, 50), "Resume")){
						pauseScreen = "Main";
						pauseToggle = false;
					}
					if (GUI.Button(new Rect(Screen.width / 2f - 50, Screen.height / 2f + 5, 100, 50), "Quit")){
						pauseScreen = "Quit";
					}
					break;
				case "Quit":
					GUI.Label(new Rect(Screen.width / 2f - 40, Screen.height / 2f - 20, 100, 50), "Are you sure?");
					if (GUI.Button(new Rect(Screen.width / 2f - 55, Screen.height / 2f + 5, 50, 25), "Yes")){
						Application.Quit();
					}
					if (GUI.Button(new Rect(Screen.width / 2f + 5, Screen.height / 2f + 5, 50, 25), "No")){
						pauseScreen = "Main";
					}
					break;
				default:
					pauseScreen = "Main";
					pauseToggle = false;
					break;
			}
		}
	}
}
