var alphaSpeed = 2.0;
var glimpseDuration = 3.0;

var randomAlternatives = 1;
var randomOffset = 1;

private var reveal = false;
private var glimpseTime = 0.0;

private var alpha = 0.0;
private var targetAlpha = 0.0;

function Start() {
	var main : Main = GameObject.Find("Main").GetComponent("Main");
	if (randomAlternatives > 1) {
		Debug.Log(main.GetGlobalRandom());
		var offset = Mathf.Floor(main.GetGlobalRandom() * randomAlternatives) * randomOffset;
		Debug.Log(offset);
		transform.Translate(offset, 0, 0);
	}
}

function Update() {
	if (reveal) {
		targetAlpha = 1.0;
	} else if (glimpseTime > 0.0) {
		targetAlpha = .3;
	} else {
		targetAlpha = 0;
	}
	
	glimpseTime = Mathf.Max(0.0, glimpseTime - Time.deltaTime);
	
	if (alpha != targetAlpha) {
		if (alpha < targetAlpha) {
			alpha = Mathf.Min(targetAlpha, alpha + alphaSpeed * Time.deltaTime);
		} else {
			alpha = Mathf.Max(targetAlpha, alpha - alphaSpeed * Time.deltaTime);
		}
	}
	renderer.material.color.a = alpha * .4; 
	
}

function OnWalk() {
	if (!reveal) {
		reveal = true;
		var main : Main = GameObject.Find("Main").GetComponent("Main");
		main.NewTileFound();
		var playerControl : PlayerControl = GameObject.Find("Player").GetComponent("PlayerControl");
		playerControl.PlayGet();
	}
}

function OnGlimpse() {
	glimpseTime = glimpseDuration;
}