// (SOME) PAGE INDICATORS SET
function postProcessSlider() {
	// Get hash
	var thePanel = location.hash;
	var theHref;
	// No hash present - set first navigation item as current (selected)
	if (thePanel == "") {
		$("#nav-main li:first-child a").addClass("current");		
	}
	// Hash is present
	else {		
		// Loop through main navigation and look for a match
		$.each($("#nav-main a"), function() {		
			theHref = $(this).attr("href");
			// Hyperlink matches current hash
			if (theHref == thePanel) {
				$(this).addClass("current");
				// Some links are hidden since there are two links for each person - check these				
				if ($(this).css("display") == "none") {
					// Hack to get hidden link to display on non-hidden links - move current to previous link
					$(this).parent().prev().children("a").addClass("current");
				}
			}
			// Hyperlink does not match current hash
			else {
				// Remove selected class
				$(this).removeClass("current");
			}
		});		
	}	
}

// MAIN NAVIGATION PRE-PROCESSING INDICATORS
function initMainNav() {
	// CLICK - Main Navigation
	$("#nav-main a").click(function() {
		$("#nav-main a").removeClass("current");
		$(this).addClass("current");	
	});
}

function initTabs() {
	// Hide tabs by default via CSS
	$("div.details").removeClass("no-js");
	var theTabHref;
	var theTabClass;
	var theTabHeight;
	var theTabHeightPx;
	// CLICK - Close All Tabs
	$("div.close a").click(function() {
		closeTabs();
		// Kill hyperlink action
		return false;
	});
	// CLICK - Open/Close Tabs
	$("div.details ul.nav a").click(function() {
		// Close all tabs
		closeTabs();
		$(this).addClass("current");		
		// Get current tab
		theTabHref = $(this).attr("href");
		theTabClass = "." + theTabHref.slice(1,3);
		// Get current tab height
		theTabHeight = $(theTabClass).children(".tab-content").height();		
		theTabHeightPx = theTabHeight + 60 + "px"; // Manually add in padding - easier than converting a pixel calculation
		// Open current tab
		$(theTabClass).animate({
        	height: theTabHeightPx		
      	}, 500);
		// Show close button
		$("div.close a").css("display","block");
		// Kill hyperlink action		
		return false;		
	});
}

// CLOSE ALL OPEN TABS
function closeTabs() {
	// Loop through all tabs and see which ones are open - then close them
	$.each($(".tab"), function() {
		if ($(this).height() != 0) {
			$(this).animate({
       			height: "0px"				
     		}, 500);	
		}
	});
	// Hide close button
	$("div.close a").css("display","none");
	// Reset tab indicators
	$("div.details ul.nav a").removeClass("current");
}

/* ON-LOAD EVENTS */
$().ready(function() {
	$('#coda-slider-1').codaSlider();
	postProcessSlider();
	initMainNav();
	initTabs();
});
		