/*
* activeClass.js
* @author Jason Ware
* 
* This looks for elements matching the body id + "Nav":
* for instance, if there is a body id of #products and 
* a navigation element with an id of #productsNav, 
* a class of .active will be added to the element.
*
* 9/22/10 - I have added a second selection for tabs that 
* are actually separate sub-pages and use a subpage derived body class
*
* Requires jQuery.
* 
*/

$(document).ready(function() {

	//get the body id
	var bodyId = $('body').attr('id');
	
	//get the first element of the body class string for the tabs
	var bodyClass = $('body').attr('class').split(' ').slice(0,1);
	
	//get the second element of the body class string for the tabs
	var bodyClassTwo = $('body').attr('class').split(' ').slice(1,2);
	
	//find any element with an id using the convention of the body id plus "Nav"
	var activeNavItem = $('body').find('#' + bodyClass+'Nav');
	
	//find any element with an id using the convention of the second body class element plus "Tab"
	var activeSecondaryNavItem = $('body').find('#' + bodyClassTwo+'Nav');
	
	//find any element with an id using the convention of the second body class element plus "Tab"
	var activeTertiaryNavItem = $('body').find('#' + bodyId+'Nav');
	
	
	//if either of these exists we'll add a class of "active" to those elements
	$(activeNavItem).addClass('active');
	$(activeSecondaryNavItem).addClass('active');
	$(activeTertiaryNavItem).addClass('active');
	//if there is something active in the tertiary nav indicate in the second that it has children
	if($('ul#mainNav ul.secondary li.active ul.tertiaryNav li.active').length>0){
		$(activeSecondaryNavItem).addClass('hasChildren');
	}

});


