/**
 *
 * KDS Navify! v0.3 
 * Last rev. 2011-07-01
 *
 * Purpose:
 * The script will find all links in the nav, and apply the "active" class to both the link ("A") and its closest parent list item ("LI").
 * You can then use these hooks for some nice CSS styling or whatever.
 *
 * Sample usage:
 * $('ul#navigation').navify();
 *
 * Or for multiple navs:
 * $('#main-nav, #side-nav, ul.nav-list').navify();
 *
 * Optionally you can pass in your own className to use instead if you don't like the default, e.g.,
 * $('ul.nav').navify('myOwnActiveClassName');
 *
**/

(function($) {

	$.fn.navify = function($navLists, activeClassNameToApply) {
		
		if (!activeClassNameToApply) {
			activeClassNameToApply = 'active';
		}
		
		var windowHref = window.location.href;
		var windowPath = window.location.pathname + window.location.search;
		
		return this.each(function() {
		
			var $list = $(this);
			$('a', $list).each(function() {
				var $a = $(this);
				var href = $a.attr('href');
				var path = this.pathname + this.search;
				if (windowHref == href || windowPath == href || windowPath == path) {
					// add the active className to both the link and the list item. (and the containing list? is that too much? allow to be configurable? (in v0.3 perhaps.))
					$a.addClass(activeClassNameToApply);
					$a.closest('li').addClass(activeClassNameToApply);
				}
			});
				   
		});
		
	};
  
})(jQuery);
