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


public class LevelSelect : MonoBehaviour {
	public GameObject slot0;
	public GameObject slot1;
	public GameObject slot2;
	public GameObject slot3;
	public GameObject slot4;


	StartItem item0;
	StartItem item1;
	StartItem item2;
	StartItem item3;
	StartItem item4;


	int current = 0;
	public float delay;
	float moveTime;
	// Use this for initialization
	void Start () {
		moveTime = 0;
		item0 = slot0.GetComponent<StartItem> ();
		item1 = slot1.GetComponent<StartItem> ();
		item2 = slot2.GetComponent<StartItem> ();
		item3 = slot3.GetComponent<StartItem> ();
		item4 = slot4.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")) {
			loadLevel ();
		}
		selectLevel (current);
	}

	public void moveUp(){
		switch (current) {
		case 0:
			break;
		case 1:
			item1.Deselect ();
			current--;
			break;
		case 2:
			item2.Deselect ();
			current--;
			break;
		case 3:
			item3.Deselect ();
			current--;
			break;
		case 4:
			item4.Deselect ();
			current--;
			break;
		}
	}

	public void moveDown(){
		switch (current) {
		case 0:
			item0.Deselect ();
			current++;
			break;
		case 1:
			item1.Deselect ();
			current++;
			break;
		case 2:
			item2.Deselect ();
			current++;
			break;
		case 3:
			item3.Deselect ();
			current++;
			break;
		case 4:
			break;
		}
	}

	public void selectLevel(int levelnum)
	{
		switch (current) {
		case 0:
			item0.Select ();
			break;
		case 1:
			item1.Select ();
			break;
		case 2:
			item2.Select ();
			break;
		case 3:
			item3.Select ();
			break;
		case 4:
			item4.Select ();
			break;
		}
	}

	public void loadLevel()
	{
		Debug.Log (current);
		switch (current) 
		{
		case 0:
			SceneManager.LoadScene("HorrorHalls");
			break;
		case 1:
			SceneManager.LoadScene("mikeScene");
			break;
		case 2:
			SceneManager.LoadScene("TankWarChasing");
			break;
		case 3:
			SceneManager.LoadScene("WickedWarps");
			break;
		case 4:
			SceneManager.LoadScene("Alex_Less");
			break;

		}
	}
}
