function Infobox(id)
{
	this.id = id;
	Infobox.instances[ id ] = this;
	
	this.screen = document.createElement( "DIV" );
	this.screen.id = "screen_" + id;
	this.screen.style.position = "fixed";
	this.screen.style.zIndex = 100;
	this.screen.style.display = "none";
	
	this.controls = document.createElement( "DIV" );
	this.controls.id = "controls_" + id;
	this.controls.style.position = "fixed";
	this.controls.style.zIndex = 101;
	this.controls.style.display = "none";
	this.controls.innerHTML = "<A href=\"javascript:Infobox.instances['" + this.id + "'].close()\">&nbsp;</A>";

	this.content = document.createElement( "DIV" );
	this.content.id = "content_" + id;
	this.content.style.position = "fixed";
	this.content.style.zIndex = 101;
	this.content.style.display = "none";
		
	document.body.appendChild( this.screen );
	document.body.appendChild( this.controls );
	document.body.appendChild( this.content );
	
	this.resizeHandler = new Function( "e", "Infobox.instances[\"" + id + "\"].onResize();" );
	this.closeHandler = new Function( "e", "Infobox.instances[\"" + id + "\"].close();" );
	this.isOpen = false;
	this.url = null;
	this.width = 0;
	this.height = 0;
	
	setEventHandler( window, "resize", this.resizeHandler );
	setEventHandler( this.screen, "click", this.closeHandler );
}

Infobox.instances = new Array();

Infobox.prototype.open = function(url, width, height)
{
	this.url = url;
	this.width = width;
	this.height = height;
	
	this.isOpen = true;
	this.onResize();
	
	this.screen.style.display = "block";
	this.content.style.display = "block";
	this.controls.style.display = "block";
	
	this.content.innerHTML = "<IFRAME style=\"border: none; inset: none; overflow: hidden;\" frameborder=\"0\" src=\"" + url + "\" width=\"" + width + "\" height=\"" + height + "\" noscroll></IFRAME>";
}

Infobox.prototype.close = function()
{
	this.isOpen = false;
	
	this.screen.style.display = "none";
	this.content.style.display = "none";
	this.controls.style.display = "none";
}

Infobox.prototype.positionElements = function()
{
	var metrix = getDocMetrics();
	var controlsRule = findCssRule( "#" + this.controls.id );
	
	if( !controlsRule ) {
		this.close();
		return;
	}

	this.content.style.width = this.width + "px";
	this.content.style.height = this.height + "px";
	this.content.style.left = ((metrix.width - this.width) / 2) + "px";
	this.content.style.top = ((metrix.height - (this.height+pixelValue(controlsRule.style.height))) / 2) + "px";

	this.controls.style.width = this.width + "px";
	this.controls.style.left = ((metrix.width - this.width) / 2) + "px";
	this.controls.style.top = (((metrix.height - (this.height+pixelValue(controlsRule.style.height))) / 2) - pixelValue(controlsRule.style.height)) + "px"
}

Infobox.prototype.onResize = function()
{
	if( !this.isOpen ) return;

	var metrix = getDocMetrics();
	
	this.screen.style.left = "0px";
	this.screen.style.width = "100%";
	this.screen.style.top = "0px";
	this.screen.style.height = "100%";
	
	var controlsRule = findCssRule( "#" + this.controls.id );
	var controlsOffset = 0;
	
	if( controlsRule ) {
		controlsOffset += pixelValue( controlsRule.style.height );
		controlsOffset += pixelValue( controlsRule.style.marginTop );
		controlsOffset += pixelValue( controlsRule.style.marginBottom );
		controlsOffset += pixelValue( controlsRule.style.paddingTop );
		controlsOffset += pixelValue( controlsRule.style.paddingBottom );
		controlsOffset += pixelValue( controlsRule.style.borderTopWidth );
		controlsOffset += pixelValue( controlsRule.style.borderBottomWidth );
	}

	var contOffX = 0;
	var contOffY = controlsOffset;
	var contentRule = findCssRule( "#" + this.content.id );
	
	if( contentRule ) {
		contOffX += pixelValue( contentRule.style.marginLeft );
		contOffX += pixelValue( contentRule.style.marginRight );
		contOffX += pixelValue( contentRule.style.paddingLeft );
		contOffX += pixelValue( contentRule.style.paddingRight );
		contOffX += pixelValue( contentRule.style.borderLeftWidth );
		contOffX += pixelValue( contentRule.style.borderRightWidth );

		contOffY += pixelValue( contentRule.style.marginTop );
		contOffY += pixelValue( contentRule.style.marginBottom );
		contOffY += pixelValue( contentRule.style.paddingTop );
		contOffY += pixelValue( contentRule.style.paddingBottom );
		contOffY += pixelValue( contentRule.style.borderTopWidth );
		contOffY += pixelValue( contentRule.style.borderBottomWidth );
	}

	this.controls.style.left = "0px";
	this.controls.style.width = metrix.width + "px";
	this.controls.style.top = (metrix.height - controlsOffset) + "px";

	this.content.style.left = "0px";
	this.content.style.width = (metrix.width - contOffX) + "px";
	this.content.style.top = "0px";
	this.content.style.height = (metrix.height - contOffY) + "px";
		
	this.positionElements();
}

