/*!*******************************************************************************
|	$Revision$
|	$Date$
|
********************************************************************************/  

/* CP.FlashAlert
----------------------------------------------------------------------------*/

CP.set( 'FlashAlert', {
	initialize: function( uid, options )
	{
		var _this = this,
			defaults = {
				messageIds: [
					'#flashMessage',
					'#authMessage'
				]
				,containerId: 'flash-messages'
				,timeOut: 5000
			};

		// extend the default options with the options specific to our current object
		$.extend( this, defaults, options || {} );
		
		this._timeOutRef = null;
		this.messageCount = 0;
		this.container = $( '<div>' )
			.css({display: 'none'})
			.attr( 'id', this.containerId )
			.click( function(){ _this.hide(); } )
			.appendTo( 'body' );
		
		$.each( this.messageIds, function( id, item ){
			var message = $( item );
			if( message.size() )
			{
				message.appendTo( _this.container );				
				_this.messageCount++;
			}
		});
		
		if( this.messageCount )
			setTimeout( function(){ _this.show(); }, 200 );
	}
	,show: function()
	{
		var _this = this;
		
		if( this._timeOutRef !== null )
			clearTimeout( this._timeOutRef );
		
		this.container
			.css({
				opacity: 0,
				display: 'block'
			})
			.animate({
				opacity: .9
			});
			
		this._timeOutRef = setTimeout( function(){ _this.hide(); }, this.timeOut );			
	}
	,hide: function()
	{
		var _this = this;
		
		if( this._timeOutRef !== null )
			clearTimeout( this._timeOutRef );		
		
		this.container.fadeOut(function(){
			_this.container.empty();
		});
		this.messageCount = 0;
	}	
});
CP.FlashAlert.singleton = true;