$(function () 
{
	var shown = false;
	
	$('.bubbleInfo').each(
		function () 
		{
		// options
		var time = 300;

		var trigger = $('.trigger', this);
		var popup;
		if($.browser.msie)
		{
			popup = $('.popup', this).css('display', 'none');
		} else
		{
			popup = $('.popup', this).css('opacity', 0);
		}

		$([trigger.get(0), popup.get(0)]).click(function (evt) {
			if($.browser.msie)
			{
				if(popup.is(":visible"))
				{
					popup.css('display', 'none');
				} else {
					popup.css(
						{
						  display: 'block' // brings the popup back in to view
						}
					)
				}
			} else {
				if(popup.is(":visible"))
				{
					popup.animate({
					  opacity: 0
					}, time, 'swing', function () {
					  // hide the popup entirely after the effect (opacity alone doesn't do the job)
					  popup.css('display', 'none');
					  shown = false;
					});
				} else {
					popup.css(
						{
						  display: 'block' // brings the popup back in to view
						}
					)

					// (we're using chaining on the popup) now animate it's opacity and position
					.animate({
					  opacity: 1
					}, time, 'swing', function () {
					  // hide the popup entirely after the effect (opacity alone doesn't do the job)
					  shown = true;
					});
				}
			}
		}).blur(
			function () {
			  if($.browser.msie)
				{
					popup.animate(
						{
						  // This doesn't actually do anything other than delay IE hiding the popup so the links work
						  voiceFamily: 'inherit'
						}, function()
						{
							popup.css('display', 'none'); // callback function then hides popup
						}
					);
				} else {
					popup.animate({
						  opacity: 0
					}, time, 'swing', function () {
					  // hide the popup entirely after the effect (opacity alone doesn't do the job)
					  popup.css('display', 'none');
					  shown = false;
					});
				}
			}
		);
		
	});
	
	if($.browser.safari)
	{
		$("body").click(
			function()
			{
				if(shown)
				{
					if($.browser.msie)
					{
						$(".popup").css(
							{
							  display: 'none' // brings the popup back in to view
							}
						);
					} else {
						$(".popup").animate({
						  opacity: 0
						}, 300, 'swing', function () {
						  // hide the popup entirely after the effect (opacity alone doesn't do the job)
						  $(".popup").css('display', 'none');
						});
					}
					shown = false;
					//alert(shown);
				}
			}
		);
	}
	
});