using UnityEngine;
using System.Collections;

public class GUIScript : MonoBehaviour 
{

	public string text;
	private Vector2 scrollPosition;
	public float GUIx, GUIy;
	public int sanity = 100;
	public string outputMsg;
	public bool tempChapter1 = false;
	public bool tempChapter2 = false;
	public bool tempChapter3 = false;

	void OnGUI()
	{

		// Begin a scroll view. All rects are calculated automatically - 
		// it will use up any available screen space and make sure contents flow correctly.
		// This is kept small with the last two parameters to force scrollbars to appear.

		if (GameObject.Find ("Chapter1").GetComponent<EventController>().chapterFinished == true && tempChapter1==false)
			{
				// Make a background box
				GUI.Box(new Rect(10,10,450,125), "What would you like to ask the restless?");
				
				// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
				if(GUI.Button(new Rect(20,40,400,20), "Ask about Brian"))
				{
				text = "I asked The Restless about Brian.\r\nAnd Laura answered me. Brian was a great father figure for the whole family.\r\nShe thought maybe sometimes he put a little too much pressure on Jacob, but none more than what you might expect from a father to a son.\r\n";
				tempChapter1 = true;
				}
				
				// Make the second button.
				if(GUI.Button(new Rect(20,70,400,20), "Confront about the hiding.")) 
				{
				sanity = sanity - 50;
				text = "I confronted Jacob about hiding his problems, not sharing them with Laura.\r\nHe reacted extremely aggressively.\r\n He criticized me, claiming I didn’t know what I was talking about.\r\nThat Laura wasn’t the great and brilliant woman she made out to be.\r\nHe was sure of it, he was sure she was responsible for them drifting apart.\r\n";
				tempChapter1 = true;
				}
				//Third button
				if(GUI.Button(new Rect(20,100,400,20), "Ask Carl about the arguments.")) 
				{
				text="Carl didn’t have much to say about the arguments.\r\nHe didn’t like them, but when pressed he said it always seemed like his Dad was the aggressor.\r\nAs if he pushed the argument.\r\nAlways blaming Mum, sometimes his dad would say his mum might prefer he wasn’t here at all.\r\nThat was the scary thing for Carl. He really didn’t want them to separate.\r\n";				
				tempChapter1 = true;
				}
			}

			else
				if (GameObject.Find ("Chapter2").GetComponent<EventController>().chapterFinished == true && tempChapter2==false)
			{
					// Make a background box
					GUI.Box(new Rect(10,10,450,125), "What would you like to ask the restless?");
			
			// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
					if(GUI.Button(new Rect(20,40,400,20), "Confront about the Lamp"))
					{
						sanity = sanity -50;
						text = "Jacob blasted his return. Refusing to elaborate.\r\n I wasn’t sure if he was holding something back, or if he simply couldn’t remember.\r\nThe memory, or lack of memory, was hard for him to take.\r\nHis emotions ran incredibly high at the mere mention of the Lamp.\r\n";
						tempChapter2 = true;
					}
				
					// Make the second button.
					if(GUI.Button(new Rect(20,70,400,20), "Confront about Matt, and Regrets")) 
					{
						sanity = sanity - 50;
						text = "Laura started to cry. Not just tears, but mournful sobs.\r\nIt started low, but turned into a wailing sound that shook my very core.\r\nIt lasted so long, the crying. When she finally whimpered into a state of seclusion, I could get nothing more out of her.\r\nNo explanation, no new information.\r\n";
						tempChapter2 = true;
					}
					//Third button
					if(GUI.Button(new Rect(20,100,400,20), "I Asked about the Birthday Card")) 
					{
						text="Laura answered about the Birthday Card. She had seen Carl pull it out from time to time.\r\nShe knew it was some form of inspiration for her son.\r\nShe expressed a concern that Brian’s words perhaps pushed for the wrong things for his son, and she explained that although Brian supported her husband, sometimes she felt Brian asked for too much.\r\nPushed him too far.";				
						tempChapter2 = true;
					}
				}
			else
			if (GameObject.Find ("Chapter3").GetComponent<EventController>().chapterFinished == true && tempChapter3==false)
			{
				// Make a background box
				GUI.Box(new Rect(10,10,450,125), "After much investigation the murderer was clearly....");
			
				// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
				if(GUI.Button(new Rect(20,40,400,20), "Jacob"))
				{
					text = "The ghosts wrestled wildly, fighting the very core of my sanity.\r\nMy soul.\r\nAngered by my inability to see the truth, they attacked.\r\nNow, instead of 3 Restless, there are four\r\n";
					tempChapter3 = true;
					Application.LoadLevel(2);
				}
			
				// Make the second button.
				if(GUI.Button(new Rect(20,70,400,20), "Matt")) 
				{
					text = "Laura started to cry. Loud, chest heaving sobs.\r\nI could hear Carl start to comfort her, to try and understand what made her cry.\r\nThere a long silence from Jacob.\r\nAs if letting the information sink in, to help him understand it. Finally, he sighed.\r\nA long, mournful sigh.Soon after, I could hear the sobbing dim down, and Carl’s voice was fading too.\r\n";
					tempChapter3 = true;
					Application.LoadLevel (3);
				}
				//Third button
				if(GUI.Button(new Rect(20,100,400,20), "Chris")) 
				{
					text="The ghosts wrestled wildly, fighting the very core of my sanity.\r\nMy soul.\r\nAngered by my inability to see the truth, they attacked.\r\nNow,instead of 3 Restless, there are four";				
					tempChapter3 = true;
					Application.LoadLevel(2);
				}
			}		
			else
			{
				scrollPosition = GUILayout.BeginScrollView (
				scrollPosition, GUILayout.Width (Screen.width), GUILayout.Height (100));
				GUILayout.Label (text);
				GUILayout.EndScrollView ();
			}
		}
	void Update()
	{
		if(Input.GetAxis ("Mouse ScrollWheel") > 0)
			scrollPosition.y -= 10;
		if(Input.GetAxis ("Mouse ScrollWheel") < 0)
			scrollPosition.y += 10;
	}
}
