//##############################################################################
//------------------------------------------------------------------------------
function Document()
{   
    this.items = Array();
}

//------------------------------------------------------------------------------
Document.prototype.addItem = function(item, flyIn)
{
	this.items.push(item); 
	item.addToWorld();
}

//------------------------------------------------------------------------------
Document.prototype.removeItem = function(item)
{
	item.removeFromWorld();

	var a;
	for(a = 0; a < this.items.length; a++)
	{
		if(this.items[a] == item)
		{
			this.items.splice(a, 1);
			break;
		}           
	}
}

//------------------------------------------------------------------------------
Document.prototype.getBounds = function()
{
	var count = this.items.length;
	if(count == 0)
		return new Rect();
		
	var r = this.items[0].getBounds();
	var left = r.left;
	var top = r.top;
	var right = r.left + r.width;
	var bottom = r.top + r.height;
	
	var a;
	for(a = 1; a < count; a++)
	{
		r = this.items[a].getBounds();
		left = Math.min(left, r.left);
		top = Math.min(top, r.top);
		right = Math.max(right, r.left + r.width);
		bottom = Math.max(bottom, r.top + r.height);                        
	}
	
	return new Rect(left, top, right - left, bottom - top);
}


