// Tab Navigation
// <![CDATA[
$(function () {
			
	// Initiate variables
    var tabContainers;
	var tabContainersTwo;
    
    $('div.tabs ul.tabNav a').click(function () {
		
		// Assign first-level tab contents
		tabContainers = $('div.tabs > div');
		
		// Hide all tab contents except this one
        tabContainers.hide().filter(this.hash).show();
        
		// Remove "active" from this link
        $('div.tabs ul.tabNav a').removeClass('active');
        $(this).addClass('active');
        
		// Get href of this link
		var href = $(this).attr("href");
		
		// If the section has secondary Tabs
		if ($(href).children().hasClass('tabsTwo')) {
			// Select the first tab by default
			$(href).find('div.tabsTwo ul.tabNavSecondary a').filter(':first').click();
		}

        return false;
    }).filter(':first').click(); // Default to first tab
	
	// If second-level tabs exist
	if ($('div.tabsTwo')); {
	
		$('div.tabsTwo ul.tabNavSecondary a').click(function () {
			
			// Assign second-level tab contents
			tabContainersTwo = $('div.tabsTwo > div');
					
			// Hide all second-level tab contents except this one	
			tabContainersTwo.hide().filter(this.hash).show();
			
			// Remove "active" from this link
			$('div.tabsTwo ul.tabNavSecondary a').removeClass('active');
			
			// Get href of this link
			var href = $(this).attr("href");
			
			// Find matching hrefs of links and add active
			$("a[href=" + href +"]").addClass('active');
			
			return false;
		}).filter(':first').click(); // Default to first tab 
	}
	
	// If user wants to link to a specific tab from an external link within the page
	$('a.tabLink').click(function(){
								   
		// Get href of this link
		var tabs = $(this).attr('href');
		
		// Split the contents
		var tabArray = tabs.split(" ");
		
		// For however many elements with in the href
		for (var i=0; i < tabArray.length; i++) {
			
			if (i == 0) {
				// If one, narrow down query to first level tabs
				$('ul.tabNav a[href="' +tabArray[i]+ '"]').click();
			}
			else if (i == 1) {
				// If two, narrow down query to second-level tabs
				$('ul.tabNavSecondary a[href="' +tabArray[i]+ '"]').click();
			}
		}

		return false;
								   
	});
	
});
// ]]>