; (function($) {
	$.infoBar = function(txt, options) {
		var text = txt || "&nbsp;",
			opties = $.extend({}, $.infoBar.defaults, options),
			random = parseInt(Math.random() * 10000),
			table = $("<table/>").attr("cellspacing", 0).attr("cellpadding", 0);  // menu;

		if (!opties.ID) {
			opties.ID = "infobar_R" + random;
		} else {
			opties.ID = "infobar_" + opties.ID;
			if (opties.cookie && !!$.cookie) {
				if ($.cookie(opties.ID) != null) {
					opties.hide = $.cookie(opties.ID) == "true" ? true : false;
				} else {
					$.cookie(opties.ID, opties.hide);
				}
			}
		}

		// add infobar;
		var root = $('<div/>').addClass("infobar").attr("id", opties.ID).toggle(!opties.hide).appendTo($(document.body));

		// add bar;
		$('<div/>').hide().addClass("infobar-bar").addClass(opties.type).append(
			$('<div/>').html(text).attr("title", "Click for more options...").hover(function() {
				$(this).addClass("hover");
			}, function() {
				$(this).removeClass("hover");
			}).click(function(e) {
				var V = viewport(),
					W = $("#" + opties.ID + " .infobar-menu").width(),
					X = e.pageX - V.x,
					Y = e.pageY - V.y;
				$("#" + opties.ID + " .infobar-menu").css("top", Y).css("left", (X <= V.w - W ? X : Math.min(X - W, X))).show();
				V = W = X = Y = null;  // clean up;
			}).append(
				$("<input/>").attr("type", "button").attr("value", "x").attr("title", "Close This Warning").click(function() {
					hider();
					return false;
				})
			)
		).appendTo(root).slideDown();

		// add menu & items;
		//opties.menu.push(null, { txt: "Close InfoBar" }, { txt: "Info about InfoBar for jQuery...",
		//	fn: "http://www.jeroenvanwarmerdam.nl/content/resources/javascript/jquery/infobar/infobar.aspx"
		//});
		
		opties.menu.push(null, { txt: "Close This Warning" });
		$.each(opties.menu, function(i, val) {
			if (!!val) {
				var txt = !!val.txt ? val.txt.toString() : "",
					fn = !!val.fn ? val.fn : function() { };
				table.append(
					$("<tr/>").append(  // image;
						$("<th/>").html(!!val.icon ? '<img src="' + val.icon.toString() + '" title="' + txt + '" />' : "&nbsp;")
					).append(  // verticale divider;
						$("<td/>").addClass("dividerH").html("&nbsp;")
					).append(  // text;
						$("<td/>").text(txt)
					).click(function() {  // extra function;
						if (typeof (fn) == "string" ? (function() { window.open(fn); return true; })() : (fn() == false ? false : true)) {
							hider();
						}
					})
				);
			} else {  // horizontale divider;
				table.append(
					$("<tr/>").addClass("dividerV").append(
						$("<th/>").html("&nbsp;")
					).append(
						$("<td/>").addClass("dividerH").html("<div><!-- no content fix for Chrome & empty div fix for IE --></div>")
					).append(
						$("<td/>").html("<div><!-- no content fix for Chrome & empty div fix for IE --></div>")
					)
				);
			}
		});

		// add menu;
		$("<div/>").hide().addClass("infobar-menu").append(table).appendTo(root)
		.find("tr:not(.dividerV)").hover(function() {
			$(this).addClass("hover");
		}, function() {
			$(this).removeClass("hover");
		});

		function hider() {
			$("#" + opties.ID + " .infobar-bar").fadeOut("slow");
			$("#" + opties.ID + " .infobar-menu").hide("fast");
			if (opties.cookie && !!$.cookie && !opties.ID.match("infobar_R")) {
				$.cookie(opties.ID, !opties.hide);
			}
		}

		// window helper;
		function viewport() {
			return {
				x: $(window).scrollLeft(),
				y: $(window).scrollTop(),
				w: $(window).width(),
				h: $(window).height()
			};
		};

		// hide menu on blur;
		$().click(function(e) {
			if (!jQuery(e.target).is("#" + opties.ID + " *")) {
				$("#" + opties.ID + " .infobar-menu").hide("fast");
			}
		});

		// clean up;
		text = random = table = null;

		// return this InfoBar;
		return root;
	};

	// public enum;
	$.infoBar.type = {
		exclamation: "exclamation",
		error: "error",
		help: "help",
		ok: "ok",
		warning: "warning"
	};

	// public defaults;
	$.infoBar.defaults = {
		ID: null,
		type: $.infoBar.type.warning,
		menu: [],
		hide: false,
		cookie: true,
		zOrder: 1
	};
})(jQuery);  // plugin code end;