/**
 * notify.js - fancy notifications
 *
 * @package    core
 * @author     Jon Randy
 * @copyright  (c) 2010 Jon Randy
 */

(function() {
	
notify = {
	
	timeoutID:false,
	
	defaults: {
		background_color 	: '#FFFFCC',
		color 				: '#000',
		time			 	: 8000	
	},
	
	show:function(message) {
		var opts = {};
		$.extend(opts, notify.defaults, (arguments.length>1) ? arguments[1] : {});
		
		// make sure message is a string
		message = ''+message;
		
		// remove existing if there
		if ($('.notifyBar').length) {
			notify.hide(function(){notify.show(message, opts)});
			return;
		}
		
		if (message=='') return;
		
		var msg = $('<div/>').html('<p>'+message.replace(/\n/i, '<br />')+'</p>').css({"color" : opts.color});
		var wrapDiv = $('<div/>').addClass('notifyBar').css({"background-color" : opts.background_color}).attr('title', 'Click to remove notification');
		wrapDiv.click(notify.hide);
		wrapDiv.append(msg).hide().appendTo('body').slideDown('fast');
		
		notify.timeoutID = setTimeout(notify.hide, opts.time);

		
	},
	
	hide:function() {
		var callback = arguments.length ? arguments[0] : false;
		if ($('.notifyBar').length){
			clearTimeout(notify.timeoutID);
			$('.notifyBar').slideUp('fast',function(){
				$('.notifyBar').remove();
				if ($.isFunction(callback)) callback();
			});
		}	
	}
	

};


})();

//window.alert = function() { notify.show.apply(this, arguments) };

