// --------------------------------------------------------
// 
// --------------------------------------------------------
$(function ()
{
	initMainNav();

	initFooterNav();
	
	initSearchBoxes();
	
	initCollegeGuideArticles();
	
	initCommentList();
});

// --------------------------------------------------------
// 
// --------------------------------------------------------
function initMainNav ()
{
	activateDefaultMainNavItem();
	
	$("#nav-main li.main").hover(handleMainNavOver, handleMainNavOut);
};

function handleMainNavOver ()
{
	deactivateMainNavItems();

	activateMainNavItem($(this));
};

function handleMainNavOut ()
{
	deactivateMainNavItems();

	activateDefaultMainNavItem();
};

function activateMainNavItem (item)
{
	item.addClass("over");
	
	item.prev().addClass("sibling-over");
};

function deactivateMainNavItems ()
{
	$("ul#nav-main li").removeClass("over").removeClass("sibling-over");
};

function activateDefaultMainNavItem ()
{
	if ($("ul#nav-main").attr("default"))
	{
		var i = $("ul#nav-main").attr("default");
		
		activateMainNavItem($("ul#nav-main li." + i));
	};
};

// --------------------------------------------------------
// 
// --------------------------------------------------------
function initFooterNav ()
{
	$("#nav-sub li.main li a").hover(handleFooterNavOver, handleFooterNavOut);
};

function handleFooterNavOver ()
{
	$("a.main", $(this).parents("li.main")).addClass("main-hover");
};

function handleFooterNavOut ()
{
	$("a.main", $(this).parents("li.main")).removeClass("main-hover");
};

// --------------------------------------------------------
// 
// --------------------------------------------------------
function initSearchBoxes ()
{
	$("form#search a.submit, dl.item-list-search form a.submit").click(
		function ()
		{
			$(this).parents("form.standard").submit();
			
			return false;
		}
	);
};

// --------------------------------------------------------
// 
// --------------------------------------------------------
function initCollegeGuideArticles ()
{
	$("#college-guide-articles dd select").change(
		function ()
		{
			if ($(this).val())
			{
				var root = $("#college-guide-articles").attr("blogroot");
				
				self.location = root + "toc_" + $(this).val() + ".php";
			};
		}
	);
};

// --------------------------------------------------------
// 
// --------------------------------------------------------
function initCommentList ()
{
	$("dl.item-list-comments dd:last-child").addClass("last");
};

