using UnityEngine;
using System.Collections;

public class DifficultyBox : MonoBehaviour {
	public int LevelToShow;
	public Sprite EmptyBox;
	public Sprite FullBox;

	private GameController gc;
	private SpriteRenderer rend;
	private bool juicing=false;

	// Use this for initialization
	void Start () {
		Init ();
	}

	private void Init()
	{
		GameObject go = GameObject.Find ("GameController");
		gc = go.GetComponent<GameController>();
		
		rend = gameObject.GetComponent<SpriteRenderer>();
	}
	
	void FixedUpdate () {
		if(gc == null || rend == null)	
			Init ();
		if(gc == null || rend == null)	
			return;

		if((gc.DifficultyLevel < LevelToShow) && (rend.sprite != EmptyBox))
		{
			rend.sprite = EmptyBox;
			Juice();
		}
		else if(!(gc.DifficultyLevel < LevelToShow) && (rend.sprite != FullBox))
		{
			rend.sprite = FullBox;
			Juice ();
		}
	}

	private void Juice()
	{
		if(!juicing)
		{
			juicing = true;
			iTween.ScaleFrom (gameObject, iTween.Hash("scale", new Vector3(1.5f, 1.5f, 0f), "time", 0.2f, "easetype", iTween.EaseType.easeOutQuad, "oncomplete", "DoneJuicing"));
		}
	}

	void DoneJuicing()
	{
		juicing = false;
	}
}
