/*!
 * jQuery Display Message Plugin
 *
 * Copyright 2010, Andrey Voev
 * http://www.andreyvoev.com
 *
 * Date: Fri Dec 12 16:12 2010 -0800
 */

(function( $ ){

   $.fn.displayMessage = function(options) {

        // Default configuration properties.
         var defaults = {
                  message       : 'Error message',
                  color         : 'silver',
                  speed         : 'fast',
                  position      : 'relative', // relative, absolute, fixed
                  autohide      : false
         }

        var options = $.extend( defaults, options );
        $(this).clearQueue();
        $(this).children().fadeOut(100);
        $(this).removeClass().empty();
        return this.each(function() {

			var sticky = (options.sticky == false) ? 'relative' : 'absolute';
	          $(this).addClass('messagebar-bar').css('position',options.position).addClass('messagebar-'+options.color).click(function(){
		          	$(this).clearQueue().slideUp('fast');
		          });
	          $(this).append('<div class="messagebar-inner"><span class="messagebar-text"></span></div>');
	          $(this).find('span').html(options.message).fadeIn(100);
		
			if($(this).css('display') == 'block' ){
	     	     if(options.autohide == true){ $(this).delay(2400).slideUp('slow'); }
	     	}else{
		          $(this).slideDown(options.speed ,function(){ 
		          	if(options.autohide == true){ $(this).delay(2400).slideUp('slow'); } 
		          });

	     	}
	
	   });

   };
})( jQuery );

