//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
function TripleButton(name, buttonLeft, buttonMiddle, buttonRight)
{
	this.name = name;
	this.buttons = new Array();
	
	this.buttons.push(buttonLeft);
	this.buttons.push(buttonMiddle);
	this.buttons.push(buttonRight);
	
	this.selectedItem = 1;
	this.highlightSound = gSounds.Get("menuHighlight");
	
	this.CanSelect = function()
	{
		return true;
	}
	
	this.PlayHighlightSound = function()
	{
		this.highlightSound.Play();
	}

	this.GetX = function()
	{
		return this.buttons[1].GetX();
	}
	
	this.GetY = function()
	{
		return this.buttons[1].GetY();
	}

	this.GetWidth = function()
	{
		return this.buttons[1].GetWidth();
	}
	
	this.GetHeight = function()
	{
		return this.buttons[1].GetHeight();
	}
	
	this.SetPosition = function(x, y)
	{
		var widthd2 = this.buttons[1].width/2;
		var gap = kTileSize;
		this.buttons[0].SetPosition(x - widthd2 - gap, y);
		this.buttons[1].SetPosition(x, y);
		this.buttons[2].SetPosition(x + widthd2 + gap, y);
	}

	this.SetSize = function(width, height)
	{
		this.buttons[0].SetSize(width/4, height);
		this.buttons[1].SetSize(width, height);
		this.buttons[2].SetSize(width/4, height);
	}

	this.SetFontSize = function(size)
	{
		for(var i = 0; i < this.buttons.length; i++)
		{
			this.buttons[i].SetFontSize(size);
		}
	}
	
	this.SelectLeft = function()
	{
		this.buttons[0].Interact();
		this.buttons[0].SetHighlighted();
	}
	
	this.SelectRight = function()
	{
		this.buttons[2].Interact();
		this.buttons[2].SetHighlighted();
	}
	
	this.Interact = function()
	{
		this.buttons[1].Interact();
	}
	
	this.CanInteract = function(x, y)
	{
		for(var i = 0; i < this.buttons.length; i++)
		{
			if(this.buttons[i].CanInteract(x, y))
			{
				return true;
			}
		}
		return false;
	}
	
	this.SelectedItem = function()
	{
		this.selectedItem = 1;
		this.highlightSound.Play();
	}
	
	this.InteractMove = function(x, y)
	{
		for(var i = 0; i < this.buttons.length; i++)
		{
			if(this.buttons[i].CanInteract(x, y))
			{
				if(this.selectedItem != i)
				{
					this.selectedItem = i;
					this.highlightSound.Play();
				}
			}
		}
	}
	
	this.InteractRelease = function (x, y)
	{
		for(var i = 0; i < this.buttons.length; i++)
		{
			if(this.buttons[i].InteractRelease(x, y))
			{
				return true;
			}
		}
		return false;
	}


	this.Redraw = function()
	{
		for(var i = 0; i < this.buttons.length; i++)
		{
			this.buttons[i].Redraw();
		}
	}

	this.DrawClear = function()
	{
		for(var i = 0; i < this.buttons.length; i++)
		{
			this.buttons[i].DrawClear();
		}
	}
	
	this.Draw = function(selected)
	{
		for(var i = 0; i < this.buttons.length; i++)
		{
			this.buttons[i].Draw(selected && i == this.selectedItem);
		}
	}

	this.ForceUpdate = function()
	{
		for(var i = 0; i < this.buttons.length; i++)
		{
			this.buttons[i].ForceUpdate();
		}
	}
	
	this.Update = function(selected)
	{
		for(var i = 0; i < this.buttons.length; i++)
		{
			this.buttons[i].Update(selected && i == this.selectedItem);
		}
	}
	
	this.IsVisible = function()
	{
		return this.buttons[0].IsVisible()
	}
	
	this.SetVisible = function(set)
	{
		this.buttons[0].SetVisible(set);
	}
}

