var blackBoxes = new Array();
var blackBoxId = 0;

function BlackBox(frame)
{
	var div = document.createElement("div");
	div.style.position = "fixed";
	div.style.left = "0px";
	div.style.top = "0px";
	div.style.zIndex = 1000 + BlackBox.prototype.autoIndex;
	div.id = "blackbox" + BlackBox.prototype.autoIndex++;
	
	if(window.innerWidth)
		div.style.width = window.innerWidth + "px";
	else
		div.style.width = (document.body.offsetWidth - 21) + "px";
		
	if(window.innerHeight)
		div.style.height = window.innerHeight + "px";
	else
		div.style.height = (document.body.offsetHeight - 4) + "px";
	div.style.backgroundColor = "#000000";
	div.style.opacity = "0.75";
	div.style.filter = "alpha(opacity=75)";
	
	this.contents = frame;
	
	this.box = div;
	BlackBox.prototype.boxList.push(this);
}

BlackBox.prototype.boxList = new Array();
BlackBox.prototype.autoIndex = 0;

BlackBox.prototype.Show = function ()
{	
	if(document.getElementById(this.box.id) == null)
	{
		document.body.appendChild(this.box);
		if(this.contents)
		{
			document.body.appendChild(this.contents);
		}
	}
	this.Refresh();
}

BlackBox.prototype.Hide = function ()
{
	if(document.getElementById(this.box.id) != null)
	{
		if(this.contents)
			document.body.removeChild(this.contents);
		document.body.removeChild(this.box);
	}
}

BlackBox.prototype.Refresh = function ()
{
	this.box.style.width = "100%";
	this.box.style.height = "100%";
	
	if(this.contents)
	{
		this.contents.style.position = "fixed";
		this.contents.style.zIndex = parseInt(this.box.style.zIndex) + 1;
		this.contents.style.left = (this.box.offsetWidth / 2 - this.contents.offsetWidth / 2) + "px";
		this.contents.style.top = (this.box.offsetHeight / 2 - this.contents.offsetHeight / 2) + "px";
	}
}

BlackBox.RefreshAll = function ()
{
	for(var i = 0; i < BlackBox.prototype.boxList.length; i++)
	{
		BlackBox.prototype.boxList[i].Refresh();
	}
}

BlackBox.GetBoxById = function (id)
{
	for(var i = 0; i < BlackBox.prototype.boxList.length; i++)
	{
		if(BlackBox.prototype.boxList[i].box.id == id)
			return BlackBox.prototype.boxList[i];
	}
	return null;
}

BlackBox.Remove = function (box)
{
	for(var i = 0; i < BlackBox.prototype.boxList.length; i++)
	{
		if(BlackBox.prototype.boxList[i] == box)
		{
			box.Hide();
			BlackBox.prototype.boxList.splice(i, 1);
			return true;
		}
	}
	return false;
}