$.fn.hasParent = function(objs)
{
	objs = $(objs);
	var found = false;

	$(this[0]).parents().andSelf().each(function()
	{
		if($.inArray(this, objs) != -1)
		{
			found = true;

			return false;
		}
	});

	return found;
}

$(document).ready(function()
{
	var call = "";
	var called = "";
	var data = "";
	var id = "";
	var length = "";
	var loop = "";
	var reference = "";
	var template = "";
	var type = "";
	var z = "";

	$("#references").hide();

	$("sup").hover(function()
	{
		call = $(this).html();
		z = $(this).css("z-index");

		$(this).css(
		{
			"z-index" : "99"
		});

		if(call.match(/(^\d{1}$)|(^(\d,?\s?)+$)|(^\d-\d$)/))
		{
			if(call.match(/^\d{1}$/))
			{
				data = $("#references #reference-" + call).html();
			}

			else if(call.match(/(^(\d,?\s?)+$)/))
			{
				call = call.replace(" ", "").split(",");

				for(var loop in call)
				{
					data += $("#references #reference-" + call[loop]).html() + " ";
				}
			}

			else if(call.match(/(^\d-\d$)/))
			{
				call = call.split("-");
				loop = call[0];
				length = call.length - 1;

				while(loop<=call[1])
				{
					data += $("#references #reference-" + loop).html() + " ";

					loop++;
				}
			}

			$(".reference-template").clone().appendTo($(this));

			if($.browser.msie && $.browser.version.substr(0,3)<="7.0")
			{
				if($(this).hasParent("#cta1"))
				{
					$(this).parents("#cta1").css(
					{
						"z-index" : "10"
					});

					$(this).parents("#cta1").children(".br").css(
					{
						"display" : "none"
					});
				}
			}

			$(".reference-template", this).show();

			if($(this).parents(".faq").length)
			{
				if($(this).position().left > 300)
				{
					$(".reference-template", this).addClass("reference-template-reverse");
				}
			}

			else
			{
				if($(this).position().left > 660)
				{
					$(".reference-template", this).addClass("reference-template-reverse");
				}
			}

			$(".reference-data", this).html(data);
		}
	}, function()
	{
		$(this).css({"z-index" : z});

		if($.browser.msie && $.browser.version.substr(0,3)<="7.0")
		{
			if($(this).hasParent(".cta"))
			{
				$(this).css(
				{
					"top" : "0"
				});

				$(this).parents("#cta1").children(".br").css(
				{
					"display" : "block"
				});
			}
		}

		data = "";

		$(".reference-template", this).hide().remove();
	});
});