//Sets the active state by first looking for a self-referencing link and sets the active state on it.
//Main nav active state runs off which sub-nav is loaded. 

function activeStates() {
    var SNClass, section, slashLoc, currentUrl, poundLoc, subLink, navLink;
    //find and clean URL
    slashLoc = document.URL.lastIndexOf("/");
    currentUrl = document.URL.slice(slashLoc + 1);

    poundLoc = currentUrl.indexOf("#");
    if (poundLoc !== -1) {
        currentUrl = currentUrl.slice(0, poundLoc);
    }

    //setting 'section'
    SNClass = $("#sub-nav").attr("class");
	window.console && console.log("section from subnav: "+SNClass);
    if (SNClass) {
        section = SNClass;
    } else {
        navLink = $("#nav").find("a[href=" + currentUrl + "]");
        if (navLink.length !== 0) {
            section = navLink.attr("id");
        }
    }
	
    //Set main-nav active state
    $("#nav").find("#nav" + section).addClass("active");
    $("body").addClass(section);

    //Set sub-nav active state and expand ul
    subLink = $("#sub-nav").find("a[href='" + currentUrl + "']");
    $(subLink).addClass("active");
}
