jQuery.notifyBar = function(settings, cls, ct) {

	(function($) {

		var bar = notifyBarNS = {};
		var spacer;
		notifyBarNS.shown = false;

		if(typeof(cls) === 'string')
			cls = 'nb-' + cls;

		if (typeof(settings) === 'string') {
			settings = { html: settings, cls: cls, delay: ct || -1, close: true };
		} else if (!settings) {
			settings = {};
		}

		// HTML inside bar
		notifyBarNS.html = (settings.html || '').replace(/\n/, "<br />\n");

		//How long bar will be delayed, doesn't count animation time.
		notifyBarNS.delay = settings.delay || 2000;

		//How long notifyBarNS bar will be slided up and down
		notifyBarNS.animationSpeed = settings.animationSpeed || 200;

		//Use own jquery object usually DIV, or use default
		notifyBarNS.jqObject = settings.jqObject;

		//Set up own class
		notifyBarNS.cls = settings.cls || "";

		//close button
		notifyBarNS.close = settings.close || false;

		if (notifyBarNS.jqObject) {
			bar = notifyBarNS.jqObject;
			notifyBarNS.html = bar.html();
		} else {
			bar = jQuery("<div></div>").addClass("jquery-notify-bar").addClass(notifyBarNS.cls).attr("id", "__notifyBar");
			if(settings.spacer)
				spacer = $("<div id='__notifyBarSpacer'></div>").css({ height: bar.height() + 40, display: 'none'});
		}

		bar.html(notifyBarNS.html).hide();
		var id = bar.attr("id");
		switch (notifyBarNS.animationSpeed) {
		case "slow":
			asTime = 600;
			break;
		case "normal":
			asTime = 400;
			break;
		case "fast":
			asTime = 200;
			break;
		default:
			asTime = notifyBarNS.animationSpeed;
		}

		if (bar != 'object'); {
			jQuery("body").prepend(bar);

			if(spacer)
				jQuery("body").prepend(spacer);
		}

		// Style close button in CSS file
		if (notifyBarNS.close) {
			bar.append(jQuery("<a href='#' class='notify-bar-close'>Close [X]</a>"));
			jQuery(".notify-bar-close").click(function() {
				if (bar.attr("id") == "__notifyBar") {
					jQuery("#" + id).slideUp(asTime, function() {
						jQuery("#" + id).remove()
					});

					if(spacer)
						spacer.slideUp(asTime, function () {
							spacer.remove();
						});
				} else {
					jQuery("#" + id).slideUp(asTime);
				}
				return false;
			});
		}

		// Check if we've got any visible bars and if we have, slide them up before showing the new one
		if ($('.jquery-notify-bar:visible').length > 0) {
			$('.jquery-notify-bar:visible').stop().slideUp(asTime, function() {
				bar.stop().slideDown(asTime);
				if(spacer) {
					spacer.stop().slideDown(asTime);
					jQuery("[style*='absolute']").animate({ top: "-= " + bar.height() + 40 });
				}
			});
		} else {
			bar.slideDown(asTime);
			if(spacer) {
				spacer.slideDown(asTime);
				jQuery("[style*='absolute']").animate({ top: "+= " + bar.height() + 40 }, asTime);
			}
		}

		// Allow the user to click on the bar to close it
		bar.click(function() {
			$(this).slideUp(asTime);
		})

		// If taken from DOM dot not remove just hide
		if(notifyBarNS.delay > 0) {
			if (bar.attr("id") == "__notifyBar") {
				setTimeout("jQuery('#" + id + "').stop().slideUp(" + asTime + ", function() {jQuery('#" + id + "').remove()});", notifyBarNS.delay + asTime);
			} else {
				setTimeout("jQuery('#" + id + "').stop().slideUp(" + asTime + ", function() {jQuery('#" + id + "')});", notifyBarNS.delay + asTime);
			}
		}

	})(jQuery)
};
