function Space(row, col)
{
	this.init(row, col);
}

Space.prototype.init = function(row, col)
{
	this.row = row;
	this.col = col;
	this.symbol = null;
	this.left = 0;
	this.top = 0;
	this.fixedSpace = false;

	this.id = 'Space' + row + '_' + col;
}

Space.prototype.isOccupied = function()
{
	return (this.symbol != null);
}

Space.prototype.setSymbol = function(symbol)
{
	this.symbol = symbol;
}

Space.prototype.getSymbol = function()
{
	return this.symbol;
}

Space.prototype.getRow = function()
{
	return this.row;
}

Space.prototype.setRow = function(v)
{
	this.row = v;
}

Space.prototype.getCol = function()
{
	return this.col;
}

Space.prototype.setCol = function(v)
{
	this.col = v;
}

Space.prototype.getId = function()
{
	return this.id;
}


Space.prototype.navigate = function(orientation)
{
	switch (orientation)
	{
		case 0: return this.l;
		case 1: return this.ll;
		case 2: return this.ul;
		case 3: return this.u;
		case 4: return this.ur;
		case 5: return this.lr;
	}

	return this.l;
}


Space.prototype.emphasize = function()
{
	if (this.isOccupied())
	{
		var img = document.getElementById(this.getId());
		if (img != null)
		{
			img.src = this.getSymbol().getEmphasisImage();
		}
	}
}

Space.prototype.deemphasize = function()
{
	if (this.isOccupied())
	{
		var img = document.getElementById(this.getId());
		if (img != null)
		{
			img.src = this.getSymbol().getImage();
		}
	}
}

Space.prototype.hasCloseNeighbors = function()
{
	for (var i=0; i<6; i++)
	{
		var n = this.navigate(i);
		if (n != null)
		{
			if (n.isOccupied() || n.hasNeighbors())
			{
				return true;
			}
		}

	}

	return false;
}

Space.prototype.hasNeighbors = function()
{
	for (var i=0; i<6; i++)
	{
		var n = this.navigate(i);
		if ((n != null) && n.isOccupied() && !n.symbol.isRestricted())
		{
			return true;
		}
	}
	return false;
}

Space.prototype.hasAnOpenNeighbor = function()
{
	for (var i=0; i<6; i++)
	{
		var n = this.navigate(i);
		if ((n != null) && !n.isOccupied())
		{
			return true;
		}
	}
	return false;
}

Space.prototype.findFixedNeighbor = function()
{
	for (var i=0; i<6; i++)
	{
		var n = this.navigate(i);
		if ((n != null) && n.isOccupied() && (n.fixedSpace == true))
		{
			return n;
		}
	}
	return null;
}

Space.prototype.loadEmptyEdges = function(spaces)
{
	var n = this;
	Space.loadEmptyEdge(this.u, spaces, true, false);
	Space.loadEmptyEdge(this, spaces, false, true);
	Space.loadEmptyEdge(this.ul, spaces, true, true);
	Space.loadEmptyEdge(this.ur, spaces, true, true);
}

Space.loadEmptyEdge = function(n, spaces, up, down)
{
	if (!n.isOccupied())
	{
		spaces.push(n);
		if (up)
		{
			if (!n.u.isOccupied()) { spaces.push(n.u); }
		}
	}

	if (down)
	{
		for (var i=0; i<2; i++)
		{
			n = n.l;
			if (!n.isOccupied()) { spaces.push(n); }
		}
	}
}

