﻿$(document).ready(function () {
    var options = {
        header: "h3",
        active: false,
        collapsible: true,
        navigation: true,
        navigationFilter: function () {
            $('#accordion li').each(function () {
                var li = $(this);

                if (li.html() != '') {
                    var a = li.find("a");
                    li.removeClass("selected");
                    var pathName = window.location.pathname;
                    link = $(a).attr("href").split("?")[0];

                    if (pathName == link) {
                        li.addClass('selected');

                        return true;
                    }
                }
            });
        }
    };

    $("#accordion").accordion(options);

    var index = $("#accordion li.selected").parent().parent().find("h3").attr("id");
    if (index != undefined) {
        $('#accordion').accordion('option', 'animated', false);
        $('#accordion').accordion('activate', parseInt(index));
        $('#accordion').accordion('option', 'animated', 'slide');
    }

    $("#topMenu #subMenu a").each(function () {
        $(this).removeClass("selected");
        var pathName = window.location.pathname;
        var location = pathName.substring(pathName.lastIndexOf("/") + 1);
        var link = $(this).attr("href").substring(pathName.lastIndexOf("/") + 1);

        if (location == link) {
            $(this).addClass("selected");
        } else {
            var parentPath = window.location.pathname.split("/");
            var parentLink = $(this).attr("href").split("/");
            if (parentPath.length >= 3 && parentLink.length >= 3) {
                if (parentPath[2] == 'about' && parentPath[3] == 'news-releases' && parentLink.length == 3) {
                // Do nothing
                } else if (parentPath[2] == 'about' && parentPath[3] != 'news-releases' && parentLink.length == 4) {
                        // Do nothing
                }
                else if (parentPath[2] == parentLink[2]) {
                    $(this).addClass("selected");

                }
            }
        }
    });

    $(".aboutMenu a").each(function () {
        $(this).removeClass("selected");
        var pathName = window.location.pathname;
        var location = pathName.substring(pathName.lastIndexOf("/") + 1);
        var link = $(this).attr("href").substring(pathName.lastIndexOf("/") + 1);
        if (location == link) {
            $(this).addClass("selected");
        }
    });
});

