using UnityEngine;
using System.Collections;

public class UIController : MonoBehaviour {

	bool showPicture = false;
	bool showjournal = false;
	public bool hasPicture = false;
	GameObject guiarea;
	GameObject book;
	GameObject pic;
	public string journal;
	public bool camOpen = false;

	// Update is called once per frame
	void Update ()
	{
		if(Input.GetKeyDown (KeyCode.J))
		{
			if (showPicture == false)
			{
				if (showjournal == false)
				{
					Camera.main.transform.rotation = Quaternion.identity;
					showjournal = true;
					guiarea = GameObject.FindGameObjectWithTag ("Journal"); 
					guiarea.transform.guiText.text = journal;
					book = GameObject.FindGameObjectWithTag ("Book");
					book.renderer.enabled = enabled;
					camOpen = false;
					CameraLock ();
				}
				else
				{
					guiarea = GameObject.FindGameObjectWithTag ("Journal");
					guiarea.transform.guiText.text = "";
					showjournal = false;
					book.renderer.enabled = false;
					camOpen = true;
					CameraLock ();
				}
			}
			
		}
		if (Input.GetKeyDown (KeyCode.P))
		{
			if (hasPicture == true)
			{
				if (showPicture == false)
				{
					camOpen = false;
					CameraLock ();
					book = GameObject.FindGameObjectWithTag ("Book");
					book.renderer.enabled = false;
					pic = GameObject.FindGameObjectWithTag ("Picture");
					pic.renderer.enabled = true;
					showPicture = true;
				}
				else
				{
					camOpen = true;
					pic = GameObject.FindGameObjectWithTag ("Picture");
					pic.renderer.enabled = false;
					showPicture = false;
				}
			}
		}
	}
	void CameraLock()
	{
		CharacterController cc = GetComponent<CharacterController>();
		cc.enabled = camOpen; 
		GameObject.Find ("Player").GetComponent<MouseLook>().enabled = camOpen;
		GameObject.Find ("Main Camera").GetComponent<MouseLook>().enabled = camOpen;
		GetComponent<FPSInputController>().enabled = camOpen;
		GetComponent<CharacterMotor>().enabled = camOpen;
	}
	
}
