// 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
function Modal( params )
{
	this.z = params.z ? params.z : 10000; // z-index
	this.coverColor = params["cover color"] ? params["cover color"] : null;
	this.coverTransparency = 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.position = "absolute";
	style.zIndex = this.z + 1;
	style.height = params.height ? params.height : "90%";
	style.width = params.width ? params.width : "90%";
	if ( !this.obj.style.backgroundColor )
		style.backgroundColor = "#ffffff";
	
	this.cover = new Cover({ z: this.z, color: this.coverColor, transparency: this.coverTransparency, target: this.target });
	
	if ( params.show )
		this.show();
}
Modal.prototype.show = function()
{
	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;
	style.top = (( this.target.clientHeight - this.obj.offsetHeight ) / 2) + this.target.scrollTop;
	style.display = "none"; // hiding the object
	style.visibility = "visible";
	
	this.cover.show();
	style.display = "block";
}
Modal.prototype.hide = function()
{
	this.obj.style.display = "none";
	this.cover.hide();
}
