// requires id or obj
// remember that a global variable cannot have the same name as an element id
// it is recommended that _ be added to the beginning of the variable name
// requires the Cover object
// NOTE: if you want to use a table as an object to be displayed, you must wrap it in a div or it will not work in Firefox
// 		perhaps I should make this automatically generate a div around any table if it's an incoming object
function Modal( params )
{
	this.z = params.z ? params.z : 10000; // z-index
	this.cover_color = params.cover_color ? params.cover_color : null;
	this.cover_transparency = params.cover_transparency ? params.cover_transparency : null;
	this.target = !params.target ? document.body : params.target;
	
	if ( params.id )
		this.obj = document.getElementById( params.id );
	else if ( params.obj )
		this.obj = params.obj;
	else // params.url
	{
		this.obj = document.createElement("iframe");
		this.obj.src = params.url;
		this.obj.border = "0px";
		this.obj.margin = "0px";
		this.obj.padding = "0px";
		this.target.appendChild( this.obj );
	}
	
	// fixing the target if necessary
	if ( this.obj.parentElement != this.target )
		this.target.appendChild( this.obj );
	
	var style = this.obj.style;
	style.display = "none"; // hiding the object
	style.overflow = "hidden";
	style.position = "absolute";
	style.zIndex = this.z + 1;
	style.height = params.height ? params.height : "90%";
	style.width = params.width ? params.width : "90%";
	if ( params.border )
		style.border = params.border;
	if ( !this.obj.style.backgroundColor )
		style.backgroundColor = "#ffffff";
	
	this.cover = new Cover({ z: this.z, color: this.cover_color, transparency: this.cover_transparency, target: this.target });
	
	if ( params.show )
		this.show();
}
Modal.prototype.show = function( callback )
{
	var style = this.obj.style;
	style.visibility = "hidden"; // hiding the obj so that it cannot be seen, but keeping the display so that it can be measured
	style.display = "block";
	style.left = (( this.target.clientWidth - this.obj.offsetWidth ) / 2) + "px";
	style.top = ((( this.target.clientHeight - this.obj.offsetHeight ) / 2) + this.target.scrollTop) + "px";
	style.display = "none"; // hiding the object
	style.visibility = "visible";
	
	this.cover.show();
	style.display = "block";
	
	if ( callback )
		callback();
}
Modal.prototype.hide = function( callback )
{
	this.obj.style.display = "none";
	this.cover.hide();
	
	if ( callback )
		callback();
}
