﻿
$(document).ready(function ()
{
	//this will make any div with a tag of "tabs" into a tab control
	$("#tabs").tabs(
	{
		show: fixToolTips
	});

	$("#getThere").change(function ()
	{
		//grab the value...redirect to [value].html =)
		var choice = $("#getThere option:selected").val();

		if(choice != "0")
		{
			//when to redirect
			window.location.href = choice;
		}
	});

	//these are our "ads"
	$('#slideshow').cycle(
	{
		fx: 'fade',
		delay:  5000,
		timeout: '4800',
		speed: '1000',
		pager: '#slideshow_nav'
	});

	$("#slideshow a").hover(
		function ()
		{
			$(this).append("<img class='bannerOverlay' src='images/slides/moreinfo.png' width='330' height='150' style='margin-left:-330px;' />");
			$('#slideshow').cycle('pause');

			window.setTimeout(function ()
			{
				$('#slideshow').cycle('resume');
			}, 4800);
		},
		function ()
		{
			$(".bannerOverlay").remove();
			$('#slideshow').cycle('resume');

		}
	);

	//this little chunk of code spits out a random background image of the 6 we have...
	var backgroundImageNumber = Math.floor(Math.random() * 6);

	if(backgroundImageNumber == 0)
		backgroundImageNumber = 1;

	$("#homeLeft").css("background", "url(images/home/" + backgroundImageNumber + ".png) no-repeat");

	//home page effects for our message series
	$("#messageSeries").hover(function ()
	{
		$(this).append("<img class='messageSeriesOverlay' src='images/messages/over.png' width='333' height='300' />");
	},
	function ()
	{
		$(".messageSeriesOverlay").remove();
	});

	$("#messageSeries").click(function ()
	{
		window.location.href = "messages";
	});

	$("a[tooltip]").tooltip();

	$(window).resize(fixToolTips);
});

//fixes tooltips
function fixToolTips(event)
{
	//reset any tooltips w/ a good offset; this needs to happen when we resize the page, too
	try
	{
		$("a[tooltip]").filter(function ()
		{
			return $(this).text() != "Amanda Cross";
		}).tooltip({ offset: [-180, -($(this).position().left)] });

		//reset amanda's tooltip at the bottom
		$("a[tooltip]").filter(function ()
		{
			return $(this).text() == "Amanda Cross";
		}).tooltip();
	} 
	catch(e)
	{
		//window is still moving...therefore .offset() doesn't work
	}
}

//fetches the existing centerpoint calendar from http://thecenterpoint.org/index.php?option=com_jcalpro&Itemid=52
//once the html is retrieved, it is parsed out to remove
function fetchCalendar()
{
	$.ajax(
	{
		url: 'http://thecenterpoint.org/index.php?option=com_jcalpro&Itemid=52',
		cache: false,
		type: 'GET',
		dataType: 'html',
		complete: function(html)
		{
			//var calendar = .find("#extcalendar");

			$("#mainContent").html(html.responseText);
		}
	});
}

//checks if the menu item is expanded or collapsed
function toggleMenu(item)
{
	//if we have the 'east' icon, we need to expand
	item = $(item).children("span");

	if($(item).siblings("ul:visible").length == 0)
	{
		$(item).removeClass("ui-icon-triangle-1-e");
		$(item).addClass("ui-icon-triangle-1-s");

		//expand
		$(item).siblings("ul").slideDown();
	}
	else
	{
		$(item).removeClass("ui-icon-triangle-1-s");
		$(item).addClass("ui-icon-triangle-1-e");

		//collapse
		$(item).siblings("ul").slideUp();
	}
}

//called when the arrows for messages are clicked
function fetchSeries(url, name)
{
	$.ajax(
	{
		url: url + '/' + (name == '' ? 'current' : name),
		cache: false,
		type: 'GET',
		dataType: 'html',
		complete: function (html)
		{
			var fadeArea = $("#messageSeriesMiddle").length == 0 ? "mainArea" : "messageSeriesMiddle";

			$("#" + fadeArea).fadeOut(function ()
			{
				$("#mainArea").html(html.responseText);
				$("#mainArea").fadeIn();
			});
		}
	});
}

function onYouTubePlayerReady(playerId)
{
	ytplayer = document.getElementById("video_overlay");
	ytplayer.setVolume(90);
} 
