
/**
 *  Establish a tile with two Symbols.
 */
function Tile(pivot, floater)
{
    this.init(pivot, floater);
}

Tile.prototype.init = function(pivot, floater)
{
    this.tileId = Utility.createDivId('Tile');
    this.pivotId = Utility.createDivId('Pivot');
    this.floatId = Utility.createDivId('Float');

    this.pivot = pivot;
    this.floater = floater;


    this.orientation = 0;

    this.tileDiv = document.createElement('div');
    this.tileDiv.id = this.tileId;
    this.tileDiv.className = 'positionable';
    hideDiv(this.tileDiv);

    this.pivotDiv = document.createElement('div');
    this.pivotDiv.id = this.pivotId;
    this.pivotDiv.className = 'positionable';
    showDiv(this.pivotDiv);

    this.floatDiv = document.createElement('div');
    this.floatDiv.id = this.floatId;
    this.floatDiv.className = 'positionable';
    showDiv(this.floatDiv);

	this.newSymbols(pivot, floater);

    this.tileDiv.appendChild(this.pivotDiv);
    this.tileDiv.appendChild(this.floatDiv);

    this.floatDiv.style.top = Symbol.HEIGHT + 'px';

    this.placed = false;

}

Tile.prototype.show = function(b)
{
    if ((b == true) || (b == null))
    {
        showDiv(this.tileDiv);
    }
    else
    {
        hideDiv(this.tileDiv);
    }
}


Tile.prototype.getTileDiv = function()
{
    return this.tileDiv;
}

Tile.prototype.getX = function()
{
	return parseInt(this.tileDiv.style.left);
}

Tile.prototype.getY = function()
{
	return parseInt(this.tileDiv.style.top);
}

Tile.prototype.getPivotDiv = function()
{
    return this.pivotDiv;
}

Tile.prototype.getFloatDiv = function()
{
    return this.floatDiv;
}


Tile.prototype.getTileId = function()
{
    return this.tileId;
}

Tile.prototype.getPivotId = function()
{
    return this.pivotId;
}

Tile.prototype.getFloatId = function()
{
    return this.floatId;
}

Tile.prototype.getOrientation = function()
{
    return this.orientation;
}

Tile.prototype.setOrientation = function(orientation)
{
    this.orientation = orientation;
}

Tile.prototype.rotate = function(clockwise)
{
    this.orientation = ((this.orientation + (clockwise ? 1 : -1)) % 6);
}

Tile.prototype.newSymbols = function(pivot, floater)
{
	this.pivot = pivot;
	this.floater = floater;

    var html = '<img src="' + pivot.getImage() + '" width="' + Symbol.WIDTH + '" height="' + Symbol.HEIGHT + '" border="0" />';
    this.pivotDiv.innerHTML = html;

    html = '<img src="' + floater.getImage() + '" width="' + Symbol.WIDTH + '" height="' + Symbol.HEIGHT + '" border="0" />';
    this.floatDiv.innerHTML = html;

}

Tile.prototype.getHtml = function()
{
	return '<div width="' + Symbol.WIDTH + '">' + this.pivotDiv.innerHTML + '<br>' + this.floatDiv.innerHTML + '</div>';
}

Tile.prototype.setPlaced = function(b)
{
	this.placed = b;
}

Tile.prototype.isPlaced = function()
{
	return this.placed;
}

Tile.prototype.isDouble = function()
{
	return (this.pivot.getType() == this.floater.getType());
}