(function($) {
	var 
	config = {
		type : 'error', // default|error|highlight
		theme : 'dq-message',
		icon : true,
		life : 10000,
		sticky : false,
		closerTemplate: '<div>[ закрыть ]</div>'
	},
	_init = function(conf)
	{
		_destroy();

		if(typeof conf !== 'object') conf = {};
		config = $.extend(config, conf);


		if(config.type){
			config.theme = 'dq-message ui-state-'+config.type;
		}
	},
	_show = function(data)
	{
		if($.isArray(data)){
			$.each(data, function(index, value){
				_setItem(value);
			});
		} else {
			_setItem(data);
		}
	},
	_destroy = function()
	{
		$('.jGrowl-notification.dq-message', '.jGrowl').trigger('jGrowl.close');
	},
	_setItem = function(value)
	{
		if(!value) return;

		var html = _getIcon();
		html += value;
		$.jGrowl(html, config);
	},
	_getIcon = function()
	{
		if(config.icon){
			var icon = '';
			switch (config.type){
				case 'error' : icon = 'alert'; break;
				default : icon = 'info'; break;
			}
			return '<span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-'+icon+'"></span>';
		}
		
		return '';
	};

	$.dqMessage = function(data, conf){
		_init(conf);

		_show(data);
	};
})(jQuery);
