function ap_stopAll()
{
	$.post('ajax-backend.php',{"playedSong":"true"},function(data)
	{
		//$("#musicplayer").html(data);
	});
}
$(document).ready(function()
{
	$.post('ajax-backend.php',{'checkIfAjax':'true'});
	
	
	//Enables Smooth Scrolling to top
	$(".backtotop").click(function()
	{
		$('html, body').animate({scrollTop:0}, 'slow');
	});
	
	//Shows the ajax loading indicator
	$("#loading-indicator").ajaxStart(function(){ $(this).fadeIn(100); });
	$("#loading-indicator").ajaxStop(function(){ $(this).fadeOut(); });
	$.post('ajax-backend.php',{'audioplayer':'2'},function(data)
	{
		$("#musicplayer").html(data);
	});

	$("#musicplayer").dblclick(function()
	{
		$.post('ajax-backend.php',{'audioplayer':'1'},function(data)
		{
			$("#musicplayer").html(data);
		});
	});

	$.post('ajax-backend.php',{'getPageFromHashdata':window.location.hash},function(urlData)
	{
		$.post('ajax-backend.php',{'getPageTitleFromHashdata':window.location.hash},function(titleData)
		{
			document.title = 'Northeastern University Anime Club - ' + titleData;
			$("#main_page_content").load(urlData);
		});
	});

	$("#logolink").click(function()
	{
		$("#main_page_content").fadeOut(function()
		{
			window.location.hash = "news";
			$("#main_page_content").load('news.php').fadeIn();
			fb.anchors.length = 0;
			fb.tagAnchors(document);
		});
	});

	//Flash then remove all alerts
	setTimeout(function()
	{
		$("#alertText").slideUp();
	}, 4000);

	$(document).bind('hashChange', function(e, newHash)
	{
		var hashInfo = newHash;
		$.post('ajax-backend.php',{'getPageFromHashdata':newHash},function(urlData)
		{
			$.post('ajax-backend.php',{'getPageTitleFromHashdata':hashInfo},function(titleData)
			{
				$("#main_page_content").fadeOut(function()
				{
					document.title = 'Northeastern University Anime Club - ' + titleData;
					$("#main_page_content").load(urlData).fadeIn();
					fb.anchors.length = 0;
					fb.tagAnchors(document);
				});
			});
		});

	});

});

//Function that controls the popupBubbles
$(function()
{
	$('.popupBubble').each(function()
	{
		var distance = 10;
		var time = 250;
		var hideDelay = 250;

		var hideDelayTimer = null;

		var beingShown = false;
		var shown = false;
		var trigger = $('.trigger', this);
		var info = $('.popup', this).css('opacity', 0);

		$([trigger.get(0), info.get(0)]).mouseover(function ()
		{
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || shown)
			{
				// don't trigger the animation again
				return;
			}
			else
			{
				// reset position of info box
				beingShown = true;

				info.css({
					bottom: 15,
					left: -5,
					display: 'block'
				}).animate({
					bottom: '+=' + distance + 'px',
					opacity: 0.9
				}, time, 'swing', function()
				{
					beingShown = false;
					shown = true;
				});
			}
			return false;
		}).mouseout(function()
		{
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			hideDelayTimer = setTimeout(function()
			{
				hideDelayTimer = null;
				info.animate({
					bottom: '+=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function()
				{
					shown = false;
					info.css('display', 'none');
				});

			}, hideDelay);
			return false;
		});
	});
});
