function AjaxDialog()
{
}

AjaxDialog.hide_elements = new Array();

AjaxDialog.content_handler =
{
	onCreate: function() 
	{
	},
	
	onSuccess: function(data) 
	{
	}
}

AjaxDialog.load = function( url )
{	
}

AjaxDialog.createDialog = function( options )
{
	options.height 	= options.height ? options.height : 0;
	options.width 	= options.width ? options.width : 0;
	
	this.dialog = document.createElement( "div" );
	
	this.dialog.style.height = options.height == 0 ? 'auto' : options.height + "px";
	this.dialog.style.width  = options.width == 0 ? 'auto' : options.width + "px";
	this.dialog.style.position = "absolute";
	this.dialog.style.top = "200px";
	this.dialog.style.left = "50%";
	this.dialog.style.marginLeft = "-" + (options.width / 2) + "px";
	this.dialog.className = options.classname ? options.classname : "dialog";
	
	if ( options.title )
	{
		h1 = document.createElement( "h1" );
		h1.innerHTML = options.title;
		this.dialog.appendChild( h1 );
	}
}

AjaxDialog.hideOnDim = function( elements )
{
	this.hide_elements = elements;
}

AjaxDialog.toggleBackground = function( dimmed )
{
	if ( !this.fade_div )
	{
		this.fade_div = document.createElement( "div" );
		this.fade_div.style.width = "100%";
		this.fade_div.style.height = "100%";
		this.fade_div.style.display = "none";
		this.fade_div.style.backgroundColor = "black";
		this.fade_div.style.position = 'absolute';
		this.fade_div.style.top = "0px";
		this.fade_div.style.left = "0px";
		this.fade_div.id = "__fade_div";
		this.fade_div.style.MozOpacity = "0.80";
		this.fade_div.style.opacity = "0.80";
		this.fade_div.style.filter = "alpha(opacity=80)";
		
		document.getElementsByTagName( "body" )[0].appendChild( this.fade_div );
	}
	
	for( i = 0; i < this.hide_elements.length; i++ )
		$(this.hide_elements[i]).style.display = dimmed ? 'none' : '';
	
	// Hide all embeds (flash)
	embeds = document.getElementsByTagName( "embed" );
	for( i = 0; i < embeds.length; i++ )
		embeds[i].style.height = (dimmed ? 0 : embeds[i].getAttribute("height")) + "px";
	
	embeds = document.getElementsByTagName( "object" );
	for( i = 0; i < embeds.length; i++ )
		embeds[i].style.display = dimmed ? 'none' : '';

	this.fade_div.style.display = dimmed ? 'block' : 'none'; 
}

AjaxDialog.attachContent = function( e )
{
	e = $(e);
	
	if ( !this.dialog )
		this.createDialog();
	
	/*
	cloned_e = e.cloneNode(true);
	
	this.dialog.appendChild( cloned_e );
	cloned_e.style.display = 'block';
	*/
	this.dialog.appendChild( e );
	e.style.display = 'block';
}

AjaxDialog.showDialog = function()
{	
	this.toggleBackground( true );
	document.getElementsByTagName( "body" )[0].appendChild( this.dialog );	
}

AjaxDialog.closeDialog = function()
{
	this.dialog.style.display = 'none';
	this.toggleBackground( false );
}


