$(document).ready(function() {
						   

	var $nav = $('#nav-container ul.sf-menu');
	var magicClassName = 'current';
	
	// for superfish menus, first put "current" on active item (a.k.a. navify!)
	var windowHref = window.location.href;
	var windowPath = window.location.pathname + window.location.search;
	var $currents = $([]);
	$nav.find('li').each(function() {
		var $li = $(this);
		var href = $li.find('a').attr('href');
		if (href == windowHref || href == windowPath) {
			$li.addClass(magicClassName);
			$currents = $currents.add($li);
		}
	});
	
	// what about any dynamic or non-structured links?
	// determine from body class?
	if (!$currents.length) {
		var bodyClasses = $('body').attr('class');
		var matches = /section-(\w+)/.exec(bodyClasses);
		if (matches && matches.length > 0) {
			var sectionName = matches[1];
			// found a section name, now apply "current" to corresponding branch in the nav
			var $sect = $nav.find('.nav-section-' + sectionName);
			$sect.addClass(magicClassName);
		}
	}
	
	// make sure parents are current, too! (superfish doesn't do this automatically???)
	$currents.each(function() {
		var $li = $(this);
		var $parent = $li.parents('li:first');
		if (!$parent.is('.current')) {
			$parent.addClass(magicClassName);
		}
	});
	
	// finally, apply the superfish!
	jQuery('ul.sf-menu').superfish({ pathClass:magicClassName, pathLevels:9 });
	
});

