/* Adapted from jbar js script at http://tympanus.net/codrops/2009/10/29/jbar-a-jquery-notification-plugin/ */

(function($) {
	$.fn.notify = function(options) {
		var opts = $.extend({}, $.fn.notify.defaults, options);

		var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
		clearTimeout(timeout);
		$(".jbar-top").remove();

		timeout = setTimeout('$.fn.notify.removebar()',o.time);
		// var _message_span = $(document.createElement('span')).addClass('jbar-content').html(o.message);

		// _message_span.css({"color" : o.color});
		var _wrap_bar = $(document.createElement('div')).addClass('jbar jbar-top').css({"display":"none"}).html(o.message) ;
		
		if (o.type) {
			_wrap_bar.addClass(o.type);
		}
		// else {
			// _wrap_bar.css({"background-color":o.background_color, "opacity":"0.3"});
		// }
		
		if (o.removebutton){
			var _remove_cross = $(document.createElement('a')).addClass('jbar-cross');
			_remove_cross.click(function(e){$.fn.notify.removebar();})
		}
		else {				
			_wrap_bar.css({"cursor"	: "pointer"});
			_wrap_bar.click(function(e){$.fn.notify.removebar();})
		}

//			_wrap_bar.append(_message_span).append(_remove_cross).hide().insertBefore($('.container')).fadeIn('slow');
		_wrap_bar.prependTo($('body')).fadeIn(500);
	};
	
	var timeout;
	$.fn.notify.removebar 	= function(txt) {
		if($('.jbar').length){
			clearTimeout(timeout);
			$('.jbar').fadeOut(250,function(){
				$(this).remove();
			});
		}	
	};
	
	$.fn.notify.defaults = {
		removebutton     	: false,
		time			 	: 5000
	};
	
	$.fn.notifyInfo = function(txt) {
		return $.fn.notify({
			message : txt,
			type : 'information'
		})
	};
	$.fn.notifySuccess= function(txt) {
	    return $.fn.notify({
	        message: txt,
	        type: 'success',
	        time: 3000
	    })
	};
	$.fn.notifyWarning = function(txt) {
	    return $.fn.notify({
	        message: txt,
	        type: 'warning'
	    })
	};
	$.fn.notifyError = function(txt) {
	    return $.fn.notify({
	        message: txt,
	        type: 'error'
	    })
	};
})(jQuery);
