using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class Spinner : MonoBehaviour {

	float rotationPerMinute;
	GameObject Scoretext;
	Quoter quoteRef;
	bool resultGlobal;
	int tempUp;


	// Use this for initialization
	void Start () {
		tempUp = 0;
		Scoretext = GameObject.Find("ScoreGUIText");
		quoteRef = Scoretext.GetComponent <Quoter>();
		//resultGlobal = quoteRef.Finished();
	
//		print ("count = " + quoteRef.count);

		rotationPerMinute = 60.0F;
	}
	
	// Update is called once per frame
	void Update () {

		if (CheckGameFinished()){
			StartSpinning();
		}
	}

	public void MoveUp(int val){
		if (tempUp < 7){
			gameObject.transform.Translate(Vector3.up);	
			tempUp++;
		}

		/*print ("val: " + val);
		if (val < 9)
		{
			gameObject.transform.Translate(Vector3.up);	
		}*/
	}

	bool CheckGameFinished(){
		bool result = false;

		result = (GameObject.Find("Quote").GetComponent <Quoter> ().finished);
		//result = quoteRef.Finished();
		//result = Quoter.GetComponent <Quoter> ().finished;
		/*try {
			GameObject Quoter = GameObject.Find("ScoreGUIText");
			//result = GameObject.Find("ScoreGUIText").GetComponent <Quoter>().finished;
		} catch (UnityException e){
			result = false;
		} finally {
			print ("Exception");
//			result = GameObject.Find("ScoreGUIText").GetComponent <Quoter>().finished;
		}*/
		return (result);

/*		bool result = GameObject.Find("ScoreGUIText").GetComponent <Quoter>().finished;
		return (result); */
	}

	void StartSpinning() {
		print ("start spinning");
		//gameObject.transform.Rotate(0,0,rotationPerMinute*Time.deltaTime);
	
		gameObject.transform.Rotate(0,0,-10*rotationPerMinute*Time.deltaTime);
	}

	void OnMouseDown() {
/*		if (GameObject.Find("Quote").GetComponent <Quoter> ().finished)
		{
			StartSpinning();
		}*/
	}
}
