$(document).ready (function() {
	//add active class to matched navigation elements
	var path = location.pathname;
	var path2 = location.pathname.replace(/\/index\.html/,"");
	var home = "/";
	$("a[href='" + [ path ] + "'], a[href='" + [ path2 ] + "/'], a[href='" + [ path2 ] + "'], a[href='" + [ path ] + "index.html']").parents("li").each(function() { //match exact urls, index.html, and links to the directory w/ or w/o the trailing slash
		$(this).addClass("active"); //assign class
	}).parents("ul").each(function(){ 
		$(this).css("display", "block"); //show submenu
	});
	
	//activate all anchor links
	function filterPath(string) {
	        return string
	                .replace(/^\//,'')
	                .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
	                .replace(/\/$/,'');
	    }

	    var locationPath = filterPath(location.pathname);

	    var scrollElement = 'html, body';
	    $('html, body').each(function () {
	        var initScrollTop = $(this).attr('scrollTop');
	        $(this).attr('scrollTop', initScrollTop + 1);
	        if ($(this).attr('scrollTop') == initScrollTop + 1) {
	            scrollElement = this.nodeName.toLowerCase();
	            $(this).attr('scrollTop', initScrollTop);
	            return false;
	        }    
	    });

	    $('a[href*=#]').each(function() {
	        var thisPath = filterPath(this.pathname) || locationPath;
	        if  (locationPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/, '')){
				if ($('a[name='+this.hash.replace(/#/, '')+']').length) {
					$(this).click(function(event) {
						var targetOffset = $('a[name='+this.hash.replace(/#/, '')+']').offset().top;
						var target = this.hash;
						event.preventDefault();
						$(scrollElement).animate(
							{scrollTop: targetOffset},
							500,
							function() {
								location.hash = target;
							});
						});
				}	        
			}
	    });

	
		$(".third_third").find(".expander").each(function(){
		//hide extra items
		$(this).children(":gt(1)").each(function(){
			if(!$(this).hasClass("last") && !$(this).hasClass("last_light")){ //exclude last one
				$(this).addClass("hide");
			}
		});
		
		$(this).children(":last").find("a").each(function(){
			//initially hide minus link
			if($(this).hasClass("more_link_remove"))
				$(this).addClass("more_link_remove_off");

			if($(this).hasClass("more_link_add")){
				//set onclick handlers for expanding lists
				$(this).click(function(){
					$(this).parent().parent().parent().find(".hide:first").each(function(){
						$(this).fadeIn().removeClass("hide").addClass("show");
					});

					//when clicked, show minus link
					$(this).parent().parent().parent().children(":last").find("a.more_link_remove_off").removeClass("more_link_remove_off");


					if($(this).parent().parent().parent().find(".hide:first").length < 1){ //there are no more items to show
						if($(this).parent().find(".more_link_add").addClass("more_link_add_off"));
					}

					return false;
				});
			}

			if($(this).hasClass("more_link_remove")){
				//set onclick handlers for removing lists
				$(this).click(function(){
					$(this).parent().parent().parent().find(".show:last").each(function(){
						$(this).fadeOut().removeClass("show").addClass("hide");
					});

					//when clicked, show minus link
					$(this).parent().parent().parent().children(":last").find("a.more_link_add_off").removeClass("more_link_add_off");

					if($(this).parent().parent().parent().find(".show:last").length < 1){ //there are no more items to show
						if($(this).parent().find(".more_link_remove").addClass("more_link_remove_off"));
					}

					return false;
				});
			}
		});
	});

	//if form on page, activate autogrow textarea
	// if($('textarea.expanding').length > 0){
	// 	$('textarea.expanding').autoResize();
	// }
	
});