$(document).ready(function() {
	
	// photo gallery stuff
	$('ul.gallery-list li:nth-child(4n)').addClass('end');
	$("a.pretty").attr('rel', 'prettyPhoto[gallery]');
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'fast'
	});
	
	// configuring the left nav stuff once you're in a program
	$('#location-nav li.current_page_ancestor').addClass('more open');
	$('#location-nav > ul > li > ul > li').addClass('more open');
	$('#location-nav .current_page_item').addClass('here clearfix');
	$('#location-nav > ul > li > ul > li.current_page_ancestor').addClass('here clearfix');
	$('#location-nav > ul > li.page_item:has(ul)').addClass('more closed');
	$('#location-nav > ul > li.page_item:not(.current_page_ancestor) > ul').hide();
	
	$('#location-nav> ul > li.more.page_item:has(ul) > a').click(function (ev) {
		ev.preventDefault();
		// so, I have these weird if blocks because depending on whether we open or close, the class toggling needs to happen in the proper order, either before or after the ul is toggled. Otherwise, it looks janky.
		if ($(this).parent().hasClass('open'))
		{
			$(this).siblings('ul').toggle(150, function() {
				$(this).parent().toggleClass('closed');
				$(this).parent().toggleClass('open');
			});
		}
		else
		{
			$(this).parent().toggleClass('closed');
			$(this).parent().toggleClass('open');
			$(this).siblings('ul').toggle(150);
		}
	});
		
	// this will add the resources submenu to the top nav
	$('#header #navigation li.page_item:has(a[title=Resources])').replaceWith($('div.resources-nav').html());
	$('#header #navigation li.page_item:has(a[title=Resources])').addClass('resources-nav');
	
	// these classes are added to work around IE not honoring the > in CSS selectors
	$('.resources-nav > ul').addClass('resources-dropdown');
	$('.resources-nav > ul > li').addClass('resources-subbox');
	$('li.resources-subbox > a').addClass('resources-subheading');
	
	
	$('.resources-dropdown').wrap('<div></div>');
	
	// add 'here' class to current item in top nav
	$('#header #navigation li.current_page_item').addClass('here');
	
	// manipulate FAQ pages, strip out time/date, etc. and make them expandable
	$('div.faq_approve').remove();
	$('ol.faq div.author').remove();
	$('ol.faq div.answer').hide();
	$('ol.faq h3').click(function () {
		$(this).next().toggle('fast');
	});
	$('ol.faq h3').wrapInner('<span/>');
	$('ol.faq h3 span').bind('mouseover mouseout', function() {
		$(this).toggleClass('hover');
	});
	
	// checking if a top nav li needs to be highlighted; top_nav_here gets set in header.php
	if (top_nav_here)
	{
		$('li.page-item-'+top_nav_here).addClass('here');
	}
	
	// generic expand code that they want to use
	$('div.additional-info').hide();
	$('a.expand-info').click(function (ev) {
		ev.preventDefault();
		if ($(this).nextAll('div.additional-info').toggle('fast'))
		{
			
		}
		else
		{
			$(this).parent().nextAll('div.additional-info').toggle('fast');
		}
	});
	
	// fix KMunn's bug
	$('.page_itemcurrent_page_item').addClass('page_item current_page_item clearfix');
	
	// get heights of all li elements and keep the largest
	// var li_height = 0;
	// $('.resources-subbox').each(function (i, elm) {
	// 	console.log(this.offsetHeight);
	// 
	// 	if ($(elm).height() > li_height)
	// 	{
	// 		li_height = $(elm).height();
	// 	}
	// });
	// $('.resources-subbox').each(function () {
	// 	$(this).height(200);
	// 	
	// });
	
	// $('div.resources-nav').hide();
	
});
