/**
 * @author C809907
 */
/**
 * @author C809907
 */
/***
* LD - configures side navigation styles and controls
* attaches an accordion event to a list item
* listID = The ID of the UL list
* firstLevelClass = the class name of the first level anchor tag
* secondLevelClass = the class name of the second level anchor tag
* subMenuClass = class name of sub menu UL list
* isNavMenu = Boolean value indicating whether this is a navigation menu that will need to be expanded based on location
***/
function configSideNav(listID, secondListClass, firstLevelClass, secondLevelClass, subMenuClass, isNavMenu)
{
	//check to make sure list exists first
	if($('#' + listID).length == 0)
		return false;
		
	var arrowExpanded = '-7px -46px'; 
	var arrowCollapsed = '-7px -6px';
	
	var selectedBlack = {'color':'#000', 'font-weight':'bold'};
	var selectedOrange = {'color':'#F85D13', 'font-weight':'bold'};
	
	$('#' + listID + ' ul').hide();
	
	if(isNavMenu)
	{
		var matchingFound = false;
		var pathname = window.location.pathname + window.location.search;
		$('#' + listID + ' a').each(function() {
			var thishref = $(this).attr('href');	//get page i'm on
			if(thishref.length > 0 && thishref.charAt(thishref.length - 1) != '/' && !thishref.match(/.html$/) && thishref.indexOf('?') < 0)	//if the url i'm on doesn't end with a '/', we'll append it
				thishref += '/';
				//7.15.10 - for Jennifer Howes history subtabs

                                    //strip out any query strings from the sidenav anchors

                                    if (thishref.indexOf('section') > 0 ) {
											thishref = thishref.substring(0, thishref.lastIndexOf('/') + 1);
											
										}

			if(thishref == pathname) //found matching link
			{
				matchingFound = true;
				return false;
			}
		});
		if(!matchingFound)	//no matching Anchor tags to page's href
		{
			//search for based on just path
			if(pathname.lastIndexOf('/') > 0)	//if contains html file
			{
				//strip it out
				pathname = pathname.substring(0, pathname.lastIndexOf('/')+1);
			}
		}
											 
		$('#' + listID + ' a').each(function() {	//iterate through each anchor tag
			//***** Find current location and expand menu
			var thishref = $(this).attr('href');	//get page i'm on
			if(thishref.length > 0 && thishref.charAt(thishref.length - 1) != '/' && !thishref.match(/.html$/) && thishref.indexOf('?') < 0)	//if the url i'm on doesn't end with a '/', we'll append it
				thishref += '/';
				//7.15.10 - for Jennifer Howes history subtabs

                                    //strip out any query strings from the sidenav anchors
										if (thishref.indexOf('section') > 0 ) {
											thishref = thishref.substring(0, thishref.lastIndexOf('/') + 1);
										
										}


			if(thishref == pathname) //found matching link
			{
				matchingFound = true;
				//$(this) == the matching anchor tag
				
	
				if($(this).parent("li").length > 0)
					$(this).css(selectedOrange);
			
				if($(this).parent("li").hasClass('hoverplain'))
					$(this).parent('li.hoverplain').addClass('oneplain').addClass('activeLI');
				else 
					$(this).css(selectedBlack)	//make it bold and black
				
				$(this).bind('mouseover', function(){$(this).css({'cursor':'default', 'text-decoration':'none'});})
					.attr('href', '#')	//remove the link from it
					.click(function(){return false;})	//on click, disable any action
					.parents("ul.subMenu").parent("li").addClass('onedown');
				
				if ($(this).hasClass('firstNav')) 
						$(this).css(selectedOrange);

				if	($(this).parent("li.hoverplain"))
						$(this).parent("li.hoverplain").addClass("oneplain");
						
				$(this).parents("ul").show()	//slide out UL
					.prev("a").css(selectedOrange).css("background-position", arrowExpanded);
					
				if($(this).hasClass(firstLevelClass) && $(this).next().is('ul'))
					$(this).css("background-position", arrowExpanded).next().show();
					
				//05-16-10: LD - changes to allow for subnav to be clickable
				if($(this).hasClass(secondLevelClass)) {
						$(this).css(selectedOrange);
						$(this).css("background-position", arrowExpanded).next().show();
						$(this).parent("li").removeClass('oneright').addClass("onedown");
				}
				
			}
		});	
	
		
	}
	//***************
	
	
	//***** Controls for second level navigation or simple accordion
	$('#' + listID + ' li a.' + secondLevelClass).click(
		function() {
			if($(this).attr('href') != '#')
				return true;
			
			var listBelow = $(this).next();
			if((listBelow.is('ul')) && (listBelow.is(':visible'))) {
				listBelow.slideUp('fast');
				$(this).parent("li").removeClass("onedown");
			} else //expanding a hidden menu
			{
				//hide other submenu
				$('#' + listID + ' ul.' + subMenuClass + ':visible').slideUp('fast').parent("li").removeClass("onedown");
				listBelow.slideDown('normal');
				$(this).parent("li").removeClass('oneright').addClass("onedown");
			
				
			}
			
			return false;
		}
	);
	//***** 
	
	
	/**** Hover Controls *****/
	$('.' + secondListClass + ' li.hover ').hover(function () {
		
		if($(this).children("UL.subMenu:hidden").length > 0)
			$(this).addClass('oneright');
	  },
	 function () {	
	 	//only remove onedown class if child UL is hidden
		if($(this).children("UL.subMenu:hidden").length > 0)
			
			$(this).removeClass('oneright');
	});
	
	
	$('.' + secondListClass + ' li.hoverplain ').hover(function () {
		$(this).addClass('oneplain');
	  },
	 function () {
		if(!$(this).hasClass('activeLI'))
			$(this).removeClass('oneplain');
	});
}
	 $("input:not(:checked) + span").css("background-color", "yellow");

$(document).ready(function() {
	configSideNav('leftNavMenu', 'sidenavSecond', 'firstNav', 'subNav', 'subMenu', true);

});