// Constructor
YAHOO.lib.Messager = function(el, config) {
	this.page = null;
	this.parent = null;
	YAHOO.lib.Messager.superclass.constructor.call(this, el, config);
}
// Create
YAHOO.lib.Messager.create = function(el, config) {
	if (YAHOO.lang.isUndefined(config)) config = {};
	return new YAHOO.lib.Messager(el, config);
}
YAHOO.extend(YAHOO.lib.Messager, YAHOO.widget.Panel, {
	// Init
	init: function(el, config) {
		if (YAHOO.lang.isUndefined(config.draggable)) config.draggable = false;
		if (YAHOO.lang.isUndefined(config.fixedcenter)) config.fixedcenter = false;
		if (YAHOO.lang.isUndefined(config.constraintoviewport)) config.constraintoviewport = true;
		if (YAHOO.lang.isUndefined(config.underlay)) config.underlay = 'none';
		if (YAHOO.lang.isUndefined(config.modal)) config.modal = false;
		if (YAHOO.lang.isUndefined(config.visible)) config.visible = false;
		YAHOO.lib.Messager.superclass.init.call(this, el, config);
		this.page = (!YAHOO.lang.isUndefined(config.page)) ? config.page : null;
		this.parent = (!YAHOO.lang.isUndefined(config.parent)) ? config.parent : null;
		this.render();
	}, 
	// Get element
	getElement: function() {
		if (this.element && this.element.firstChild) return this.element.firstChild; else return null;
	}, 
	// Get height
	getHeight: function() {return YAHOO.lib.util.Element.getHeight(this.element);},
	// Render
	render: function() {
		YAHOO.lib.Messager.superclass.render.call(this);
		if (this.body) {
			if (!this.errorElement) 
				this.errorElement = YAHOO.lib.util.Element.getChildByClassName(this.body, 'error');
			if (!this.infoElement) 
				this.infoElement = YAHOO.lib.util.Element.getChildByClassName(this.body, 'info');
		}
	}, 
	// Clear error 
	clearError: function() {if (this.errorElement) this.errorElement.innerHTML = '';}, 
	// Clear info
	clearInfo: function() {if (this.infoElement) this.infoElement.innerHTML = '';}, 
	// Clear 
	clear: function() {this.clearError();this.clearInfo();}, 
	// Show
	show: function() {
		YAHOO.lib.Messager.superclass.show.call(this);
		YAHOO.lib.util.Element.show(this.getElement());
	}, 
	// Hide
	hide: function() {
		YAHOO.lib.Messager.superclass.hide.call(this);
		this.clear();
		this.hideErrorElement(); 
		this.hideInfoElement();
		YAHOO.lib.util.Element.hide(this.getElement());
	}, 
	// Show error element
	showErrorElement: function(message) {YAHOO.lib.util.Element.show(this.errorElement);}, 
	// Hide error element
	hideErrorElement: function(message) {YAHOO.lib.util.Element.hide(this.errorElement);}, 
	// Show info element
	showInfoElement: function(message) {YAHOO.lib.util.Element.show(this.infoElement);}, 
	// Hide info element
	hideInfoElement: function(message) {YAHOO.lib.util.Element.hide(this.infoElement);}, 
	// Render error 
	renderError: function(messages) {
		if (this.errorElement) {
			this.clearError();
			this.hideErrorElement();
			if ((messages instanceof Array) && (messages.length > 0)) {
				var html = '<ul>';
				for (var i = 0; i < messages.length; i++) html += '<li>' + messages[i] + '</li>';
				this.errorElement.innerHTML = html;
				this.show();
				this.showErrorElement();
			}
		}
	}, 
	// Render info
	renderInfo: function(messages) {
		if (this.infoElement) {
			this.clearInfo();
			this.hideInfoElement();
			if ((messages instanceof Array) && (messages.length > 0)) {
				var html = '<ul>';
				for (var i = 0; i < messages.length; i++) html += '<li>' + messages[i] + '</li>';
				html += '</ul>';
				this.infoElement.innerHTML = html;
				this.show();
				this.showInfoElement();
			}
		}
	}, 
	// Render messages 
	renderMessages: function(data) {
		this.renderError(data.error);
		this.renderInfo(data.info);
	}, 
	// Show messages 
	showMessages: function(data) {
		this.clear();
		this.renderMessages(data);
	},  
	// To string
	toString: function() {return 'Messager Object';}
});