
jQuery(function(){

	// Don't run if ie6
	if(!(jQuery.browser.msie && parseInt(jQuery.browser.version.substr(0,1)) == 6))
	{
		// tag all the non expandable items
		jQuery("#leftNav li a:only-child").parent("li").addClass("notExpandable");
		
		// show the current selection when the page loads
		jQuery('#leftNav ul li.selected').show();
		jQuery('#leftNav li a').click
		( 
			function()
			{
				var checkElement = jQuery(this).next();
				
				// if the item click is already opened, close it and update the classes
				if((checkElement.is('ul')) && (checkElement.is(':visible')))
				{
					contLen = jQuery('#contentContainer2').css('min-height');
					contLen = contLen.substring(0,contLen.length - 2) * 1;
					
					var theLi = jQuery('#leftNav ul li ul:visible');
					theLi.slideUp('normal');
					theLi.parent('li').addClass('closed');
					// this is for closed selected items that need a blue arrow pointing sideways
					jQuery('#leftNav ul.level1 li ul.level2 li.selected').parent('ul').parent('li').addClass('blue');
					
					// remove the active tag and update the page length.
					theLi.parent("li").removeClass('active');
					
					contLen = contLen - 36 * theLi.children("li").length;
					jQuery('#contentContainer2').css('min-height', contLen);
					
					return false;
				}
				// if the item clicked has a ul child that is not visible
				if((checkElement.is('ul')) && (!checkElement.is(':visible')))
				{
					contLen = jQuery('#contentContainer2').css('min-height');
					contLen = contLen.substring(0,contLen.length - 2) * 1;
					
					// close any current open sub levels
					jQuery('#leftNav ul li ul:visible').slideUp('normal');
					jQuery('#leftNav ul li ul:visible').parent('li').addClass('closed');
					jQuery('#leftNav ul.level1 li ul.level2 li.selected').parent('ul').parent('li').addClass('blue');
					prev = jQuery('#leftNav ul li ul:visible').children("li").length;
					jQuery('#leftNav ul li ul:visible').parent("li").removeClass('active');
					
					// slide down the one clicked.
					checkElement.slideDown('normal');
					checkElement.parent("li").removeClass('closed');
					checkElement.parent("li").removeClass('blue');
					checkElement.parent("li").addClass("active");
					
					// change the length of the content container to fit the new nav
					contLen = contLen + 36 * (checkElement.children("li").length - prev);
					jQuery('#contentContainer2').css('min-height', contLen);
					
					return false;
				}
			}
		);
	}
});