﻿$(document).ready(function(){

	// hide all lower level ul's initially
	$("#deptNav ul")
		.hide();

	// when top level is clicked, expand or collapse the lower level
	$('#deptNav li a').click(
		function() {
			var checkElement = $(this).next();
			
			// clears .deptNavSelected class wherever it may be so it can be reassigned
			$('.deptNavSelected').removeClass('deptNavSelected');

			// if the element that is clicked is already expanded, collapse it and stop
			if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				$('#deptNav ul:visible').slideUp('normal');
				return false;
			}
			
			// if the element that is clicked is not expanded, collapse
			// the one that is open and expand this one
			if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$(this).addClass('deptNavSelected');
				$('#deptNav ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			} 
		}
	); // end click event
	
}); // end of document.ready function 

