using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;


public class StartScreen : MonoBehaviour {
	public GameObject slot0;
	public GameObject slot1;


	StartItem item0;
	StartItem item1;


	int current = 0;
	public float delay;
	float moveTime;
	// Use this for initialization
	void Start () {
		moveTime = 0;
		item0 = slot0.GetComponent<StartItem> ();
		item1 = slot1.GetComponent<StartItem> ();

	}

	// Update is called once per frame
	void Update () {
		if (Time.time > moveTime + delay) {
			moveTime = Time.time;
			float vertical_movement = Input.GetAxis ("Vertical");
			if (vertical_movement > 0.5 || Input.GetButtonDown ("Down")) {
				moveDown ();
			} else if (vertical_movement < -0.5 || Input.GetButtonDown ("Up")) {
				moveUp ();
			}
		}

		if (Input.GetButtonDown ("Select") || Input.GetButtonDown ("Select Keys")) {
			Debug.Log ("bang");
			loadLevel ();
		}
		selectLevel (current);
	}

	public void moveUp(){
		switch (current) {
		case 0:
			break;
		case 1:
			item1.Deselect ();
			current--;
			break;
		}
	}

	public void moveDown(){
		switch (current) {
		case 0:
			item0.Deselect ();
			current++;
			break;
		case 1:
			break;
		}
	}

	public void selectLevel(int levelnum)
	{
		switch (current) {
		case 0:
			item0.Select ();
			break;
		case 1:
			item1.Select ();
			break;
		}
	}

	public void loadLevel()
	{
		Debug.Log (current);
		switch (current) 
		{
		case 0:
			SceneManager.LoadScene("ReadyMenu");
			//Debug.Log("start");
			break;
		case 1:
			Application.Quit ();
			//Debug.Log("quit");
			break;

		}
	}
}
