﻿if ($(document).ready) {
    $(document).ready(function() {
        var selected = false;
        //Left side of the navigation bar 
        $(".navLeft").children().each(function(i) {
            var linkName = $.trim($(this).text()).replace(" ", "-");
            if ((location.href.indexOf("/" + linkName + "/") > 0) || (location.href.indexOf("/" + linkName + ".aspx") > 0)) {
                var selectItem = $($(this).children()[0]);
                selectItem.removeAttr("onmouseout");
                selectItem.removeAttr("onmouseover");
                selectItem.removeClass("navBarItem");
                selectItem.removeClass("navBarItemFirst");
                selectItem.addClass('selectedLeft');
                selected = true;
            }
        });

        //Right side of the navigation bar 
        $(".navRight").children().each(function(i) {
            var linkName = $.trim($(this).text()).replace(" ", "-");
            if ((location.href.indexOf("/" + linkName + "/") > 0) || (location.href.indexOf("/" + linkName + ".aspx") > 0)) {
                var selectItem = $($(this).children()[0]);
                selectItem.removeAttr("onmouseout");
                selectItem.removeAttr("onmouseover");
                if (selectItem.hasClass('RightSideNavBarItemFirst')) {
                    selectItem.removeClass("RightSideNavBarItemFirst");
                    selectItem.addClass('selectedContactRight');
                } else {
                    selectItem.removeClass("RightSideNavBarItem");
                    selectItem.addClass('selectedRight');
                }
                selected = true;
            }
        });

        if (selected == false) {
            var firstItem = $($($(".navLeft").children()[2]).children()[0]);
            firstItem.removeAttr("onmouseout");
            firstItem.removeAttr("onmouseover");
            firstItem.removeClass("navBarItem");
            firstItem.removeClass("navBarItemFirst");
            firstItem.addClass('selectedLeft');
        }

        $(".selected").removeClass("rmLink");
    });
} 
    