var FormMessage = new Class({
	Implements: [Options, Events, Log],
	
	options: {
		allowClose: true,
		heading: null
	},
	
	// Variables
	form: null,
	element: null,
	container: null,
	isShown: false,
	isAnimating: false,

	
	/*
	 * Initialize
	 */
	initialize: function(form, container, options)
	{
		//this.enableLog();
		this.log("FormMessage::initialize(" + form + ", " + container + ", " + options + ")");
		
		// Set options
		this.setOptions(options);
		
		// Set variable
		this.form = form;
		this.container = container;

		//this.container.show();
		this.container.setStyle('opacity', 0);

		// Create animation
		this.container.fx = new Fx.Tween(this.container, {
			duration: 250,
			transition: 'linear',
			property: 'opacity',
			link: 'cancel'
		});
		this.container.fx.addEvent('start', function() {

			if(this.container.getStyle('opacity').toInt() == 0)
			{
				this.container.show();
			}
		}.bind(this));

		this.container.fx.addEvent('complete', function() {

			if(this.container.getStyle('opacity').toInt() == 0)
			{
				this.container.hide();
			}
		}.bind(this));

		//this.container.fx.set(0);

		// Build
		this.build();
	},
	
	/*
	 * Reset
	 */
	reset: function()
	{
		this.log("FormMessage::reset()");

		this.container.show();
		this.container.setStyle('opacity', 0);

		this.clear();

		this.enable();
	},
	
	/*
	 * Build
	 */
	build: function()
	{
		this.log("FormMessage::build()");
	},
	
	/*
	 * Show
	 */
	show: function()
	{
		this.log("FormMessage::show()");
		
		this.log("this.isShown: " + this.isShown);

//		this.container.fade('in');
		this.container.fx.start(1);

		if(!this.isShown || (this.isShown && this.isAnimating))
		{
			this.log("reveal: " + this.element);

			this.element.fx.reveal();
		}
	},
	
	/*
	 * Hide
	 */
	hide: function()
	{
		this.log("FormMessage::hide()");
		
		if(this.isShown) 
		{
//			this.container.fade('out');
			this.container.fx.start(0);
			this.element.fx.dissolve();
		}
	},
	
	/*
	 * Clear
	 */
	clear: function()
	{
		this.log("FormMessage::clear()");
	},
	
	/*
	 * Disable
	 */
	disable: function()
	{
		this.log("FormMessage::disable()");
		
		this.element.addClass('disabled');
	},
	
	/*
	 * Disable
	 */
	enable: function()
	{
		this.log("FormMessage::enable()");
		
		this.element.removeClass('disabled');
	}
		
});

// Static variables
FormMessage.NORMAL = 0;
FormMessage.VALID = 1;
FormMessage.WARNING = 2;
FormMessage.ERROR = 3;

FormMessage.STATUSES = [];
FormMessage.STATUSES[FormMessage.VALID] = 'valid';
FormMessage.STATUSES[FormMessage.WARNING] = 'warning';
FormMessage.STATUSES[FormMessage.ERROR] = 'error';
