YAHOO.namespace("Youniverse");

YAHOO.Youniverse.dialogBox = function()
{
	var dialogHeader;
	var dialogBody;
	var pageDialog;
	
	/*
	* Initialise class when window dom loaded
	*/
	this.initClass = function ()
	{		
	}
	
	/**
	 * Opens the panel
	 * @ dialogDiv is the div to put the dialog into
	 * 
	 */
	this.openDialog = function(dialogDiv)
	{
		scroll(0, 0);
		eff =  new YAHOO.widget.Effects.BlindDown(pageDialog, {ghost: true});
		eff.onEffectComplete.subscribe(function()
		{
			YAHOO.util.Dom.setStyle(pageDialog, 'height', '');
		});
	}
	/**
	 * Closes the panel
	 * 
	 */
	this.closeDialog = function()
	{
		//eff =  new YAHOO.widget.Effects.BlindUp(pageDialog, {ghost: true});
		//eff.onEffectComplete.subscribe(function()
		//{
			YAHOO.util.Dom.setStyle(pageDialog, 'height', '');
			dialogBox.clearDialog();
		//});
	}
	
	/**
	 * Clear contents
	 * 
	 */
	this.clearDialog = function()
	{
		if ( pageDialog )
		{
			pageDialog.innerHTML="";
			pageDialog.setAttribute('style','display="none"');
		}		
	}
	
	/*
	* set the div height
	*/
	this.setHeight = function(height)
	{
		if (!height)
		{
			height = pageDialog.clientHeight;
		}
		
		YAHOO.util.Dom.setStyle(pageDialog, 'height', height);
	}
	
	/*
	* Set the dialog body
	* @ body The body contents
	*/
	this.setBody = function(body)
	{
		pageDialog = document.getElementById('pageDialogDiv');
		pageDialog.innerHTML = "";
		pageDialog.innerHTML = body;
	}
	
	/*
	* Set the dialog body
	* @ background is the css inline style text
	*/
	this.setBackground = function(background)
	{
		YAHOO.util.Dom.setStyle(pageDialog, 'background', background);
	}
	
	/*
	* Displays error
	* @ errorText
	* @ offsetX optional
	* @ offsetY optional
	*/
	this.displayError = function (errorText, posX, posY, displayElementName)
	{
	    if (displayElementName)
	    {
	       pageDialog = document.getElementById(displayElementName);
	    }
	    else
	    {
	       pageDialog = document.getElementById('pageDialogDiv');
	    }
		
		var dialogError = document.createElement('div');
		dialogError.setAttribute('id', 'dialogError');
		dialogError.innerHTML = errorText;
		
		if (posX) { 
			dialogError.style.left = posX+'px';
		}
		if (posY) {
			dialogError.style.top = posY+'px';
		}
			
		pageDialog.appendChild(dialogError);		
		
		eff = new YAHOO.widget.Effects.Appear(dialogError);
		eff.onEffectComplete.subscribe(function()
		{
			setTimeout('dialogBox.clearError()', 2500);
		});
	}
	
	
	/*
	* Clears error
	*/
	this.clearError = function ()
	{
		var dialogError = document.getElementById('dialogError');
		
		eff = new YAHOO.widget.Effects.Fade(dialogError);
		eff.onEffectComplete.subscribe(function()
		{
			dialogError = document.getElementById('dialogError');
			
			dialogError.parentNode.removeChild(dialogError);
		});	
	}
}