// $Id: nexttile.js,v 1.2 2004/07/10 21:13:57 kai Exp $
// $Log: nexttile.js,v $
// Revision 1.2  2004/07/10 21:13:57  kai
// Refaktorisiert und HTML-Element-Stuktur überarbeitet
//
// Revision 1.1  2004/07/10 15:04:36  kai
// Erste Version von Anzeige des nächsten Tiles
//

function nexttile(brickwidth, brickheight)
{
	// Members
	this.top;
	this.left;
	this.brickwidth;
	this.brickheight;
	this.padding;
	this.borderWidth;

	// Member functions
	this.makeid = nexttile_makeid;
	this.settile = nexttile_settile;

	// Init
	this.brickwidth = brickwidth;
	this.brickheight = brickheight;
	this.padding = 1;
	this.borderWidth = 2;

	div = document.createElement("div");
	div.id = "nexttile";
	div.style.position = "absolute";
	div.style.top = (theplayfield.brickrows * theplayfield.brickheight) - ((this.brickheight * 4) + (2 * this.borderWidth) + (2 * this.padding)) + theplayfield.pborder - 18;
	div.style.left = 0;
	div.style.margin = 0;
	div.style.padding = 0;
	div.style.fontFamily = "Arial, sans-serif";
	div.style.fontSize = "10pt";
	div.innerHTML = "<b>Next:</b><br>";
	document.getElementById("tetris").appendChild(div);

	div = document.createElement("div");
	div.style.width = (this.brickwidth * 4) + (2 * this.borderWidth) + (2 * this.padding);
	div.style.height = (this.brickheight * 4) + (2 * this.borderWidth) + (2 * this.padding);
	div.style.margin = 0;
	div.style.padding = this.padding;
	div.style.position = "absolute";
	div.style.left = 0;
	div.style.top = 18;
	div.style.borderWidth = this.borderWidth;
	div.style.borderStyle = "dashed";
	div.style.borderColor = "#000000";
	document.getElementById("nexttile").appendChild(div);
	for(i = 0; i < 4; i++)
	{
		for(j = 0; j < 4; j++)
		{
			img = document.createElement("img");
			img.id = this.makeid(i, j);
			img.style.position = "absolute";
			img.style.top = (i * this.brickheight) + this.padding;
			img.style.left = (j * this.brickwidth) + this.padding;
			img.style.border = 0;
			img.style.width = this.brickwidth;
			img.style.height = this.brickheight;
			img.style.visibility = "hidden";
			div.appendChild(img);
		}
	}
	return;
}

function nexttile_settile(tile)
{
	brickname = brickgfx[tile.nexttile].src;
	for(i = 0; i < 4; i++)
	{
		for(j = 0; j < 4; j++)
		{
			img = document.getElementById(this.makeid(i, j));
			if(tile.tshape[tile.nexttile][0][i].substring(j, j + 1) == "*")
			{
				img.src = brickname;
				img.style.visibility = "visible";
			}
			else
			{
				img.style.visibility = "hidden";
			}
		}
	}
}

function nexttile_makeid(x, y)
{
	return("ntx" + x + "y" + y);
}