// Dependancies: jQuery Core;
// Author: Big Mike @ dDFCB;
// Version: 0.0;

(function($)
{
	$.fn.pfiAlert = function(type)
	{
		var highestZIndex = Math.max.apply(null,$.map($('body > *'), function(obj)
		{
			if($(obj).css('position')=='relative' || $(obj).css('position')=='absolute' || $(obj).css('position')=='fixed')
			{
				return parseInt($(obj).css('z-index'))||1;
			}
		}));

		if(type=="redirect")
		{
			$(this).click(function()
			{
				var inject = $(this).attr("href");
				var write = '';

				$(".pfiOverlay").css({
					"opacity" : "0",
					"display" : "block",
					"z-index" : highestZIndex + 1
				}).animate({
					"opacity" : "0.85"
				});

				if($.browser.msie && $.browser.version=="6.0")
				{
					var alertLeft = ($(window).width() / 2) + "px";
					var alertTop = ($(window).scrollTop() * 1.75) + ($(".pfiAlert").height() / 2) + "px";

					$(".pfiAlert").css({
						"opacity" : "0",
						"display" : "block",
						"position" : "absolute",
						"top" : alertTop,
	 					"left" : alertLeft,
						"z-index" : highestZIndex + 2
					}).animate({
						"opacity" : "0.85"
					});
				}

				else
				{
					var alertLeft = ($(window).width() / 2) - 170 + "px";
					var alertTop = ($(window).height() / 2.43) - ($(".pfiAlert").height() / 2) + "px";

					$(".pfiAlert").css({
						"opacity" : "0",
						"display" : "block",
						"position" : "fixed",
						"top" : alertTop,
	 					"left" : alertLeft,
						"z-index" : highestZIndex + 2
					}).animate({
						"opacity" : "0.85"
					});
				}

				$(".pfiAlert a[rel=continue]").attr("href", inject);

				return false;
			});
		}

		if(type=="popup")
		{
			$(this).click(function()
			{
				var inject = $(this).attr("href");
				var write = '';

				$(".pfiOverlay").css({
					"opacity" : "0",
					"display" : "block",
					"z-index" : highestZIndex + 1
				}).animate({
					"opacity" : "0.85"
				});

				var alertLeft = ($(window).width() / 2) - 170 + "px";
				var alertTop = ($(window).height() / 2.43) - ($(".pfiAlert").height() / 2) + "px";

				$(".pfiAlert").css({
					"opacity" : "0",
					"display" : "block",
					"position" : "fixed",
					"top" : alertTop,
	 				"left" : alertLeft,
					"z-index" : highestZIndex + 2
				}).animate({
					"opacity" : "0.85"
				});

				$(".pfiAlert a[rel=continue]").attr("href", inject);

				return false;
			});
		}

		$(".pfiAlert a[rel=cancel]").click(function()
		{
			$(this).parents(".pfiAlert").fadeOut("fast", function()
			{
				$(".pfiOverlay").fadeOut("fast");
			});
		});

		$(".pfiAlert a[rel=continue]").click(function()
		{
			$(this).parents(".pfiAlert").fadeOut("fast", function()
			{
				$(".pfiOverlay").fadeOut("fast");
			});

			window.open($(this).attr('href'));

			return false;
		});

		if($.browser.msie && $.browser.version=="6.0") { } else
		{
			$(window).resize(function()
			{
				var totalAlerts = $("body .pfiAlert").length;

				if(totalAlerts > 0)
				{
					var alertLeft = ($(window).width() / 2) - 170 + "px";
					var alertTop = ($(window).height() / 2) - ($(".pfiAlert").height() / 2) + "px";

					$(".pfiAlert").animate({
						"top" : alertTop,
						"left" : alertLeft
					}, {queue: false});
				}
			});
		}

	};
})(jQuery);
