//Copyright (C) Ben Parbury - All Rights Reserved. Unauthorized copying of this file, via any medium is strictly prohibited. Written by Ben Parbury <ben@gridlockinteractive.com> 2014
var gNextBlockOverlay = new NextBlockOverlay;

function NextBlockOverlay()
{
	this.drawClear = false;
	
	this.GetSpacing = function()
	{
		return this.GetRadius() + kTileSize * 0.1;
	}
	
	this.GetDrawX = function()
	{
		return this.GetSpacing();
	}
	
	this.GetDrawY = function()
	{
		return gDraw.canvas.height - this.GetSpacing();
	}
	
	this.GetRadius = function()
	{
		return kTileSize* 0.7;
	}
	
	this.DrawClear = function()
	{
		if(this.drawClear)
		{
			var x = this.GetDrawX();
			var y = this.GetDrawY();
			var spacing = this.GetSpacing();
			gDraw.overlay.clearRect(x - spacing, y - spacing, spacing * 2, spacing * 2);
			//gDraw.overlay.rect(x - spacing, y - spacing, spacing * 2, spacing * 2);
			//gDraw.overlay.fillStyle = "rgb(255, 0, 0)";
			//gDraw.overlay.fill();
			
			gCompleteOverlay.redraw = true;
		}
	}
	
	this.Draw = function()
	{
		this.drawClear = false;
		if(gSpawnerManager.spawners.length > 0 && !gPause.IsPaused())
		{
			var spawner = gSpawnerManager.spawners[0];
			if(spawner.timer)
			{
				var fraction = spawner.time / spawner.timer;
				
				var drawX = this.GetDrawX();
				var drawY = this.GetDrawY();
				var radius = this.GetRadius();

				gDraw.overlay.shadowOffsetX = 0;
				gDraw.overlay.shadowOffsetY = 0;
				gDraw.overlay.shadowBlur = 0;

				gDraw.overlay.beginPath();
				gDraw.overlay.fillStyle = gStyles.tileFill.GetColor();
				gDraw.overlay.arc(drawX, drawY, radius, 0, Math.PI * 2, false);
				gDraw.overlay.fill();
				
				gDraw.overlay.beginPath();
				gDraw.overlay.fillStyle = gStyles.tileFill.GetAdjusted(32).GetColor();
				gDraw.overlay.arc(drawX, drawY, radius, -Math.PI * 0.5, (-Math.PI * 0.5) + (fraction * Math.PI * 2), false);
				gDraw.overlay.lineTo(drawX, drawY);
				gDraw.overlay.closePath();
				gDraw.overlay.fill();

				spawner.nextBlock.x = 0.3;
				spawner.nextBlock.y = 10.7;
				spawner.nextBlock.redraw = true;
				var previousContext = gBlockRenderer.context;
				gBlockRenderer.context = gDraw.overlay;
				gBlockRenderer.Draw(spawner.nextBlock);

				gDraw.overlay.font	 = GetFont(GetFontScale(32));
				gDraw.overlay.textAlign	 = 'center';
				gDraw.overlay.textBaseline	 = 'middle';
	
				gDraw.overlay.shadowOffsetX = 1;
				gDraw.overlay.shadowOffsetY = 1;
				gDraw.overlay.shadowBlur = 2;

				gBlockRenderer.DrawOverlay(spawner.nextBlock);
				gBlockRenderer.context = previousContext;
				
				this.drawClear = true;
			}
		}
	}
}
