$(function() {
    $(".major_nav").children("li").each(function() {
        var current = "active";
        var parentClass = $(this).attr('id');
        var thisClass = $(this).attr('class');
        $(this).children("a").css({ backgroundImage: "none" });

        if (parentClass == current) {
            $(this).before('<div class="nav_' + thisClass + '_active"></div>');
        }

    });

    $.each(['home', 'my_mncpa', 'cpe', 'pub_news', 'tech_resources', 'involvement', 'careers', 'about_us'], function(i, val) {
        attachNavEvents(".major_nav", val);
    });

    function hoverOver() {
        myClass = $(this).attr('class');
        $('.hovering, .sub_nav').hide();
        $("#sub_nav_" + myClass).css({ visibility: "visible", zIndex: "100" }).fadeIn(100);
        $(this).before('<div class="nav_' + myClass + ' hovering"></div>');
        $("div.nav_" + myClass).css({ display: "none" }).fadeIn(100);
    }

    function hoverOut() {
        myClass = $(this).attr('class');

        $("div.nav_" + myClass).fadeOut(100, function() {
            $(this).remove();
        });

        // THIS IS FOR THE SUB NAV FUNCTIONALITY
        $("#sub_nav_" + myClass).css({ visibility: "visible" }).fadeOut(100);

    }

    function attachNavEvents(parent, myClass) {

        // THIS IS FOR THE SUB NAV FUNCTIONALITY
        $("#sub_nav_" + myClass);

        var config = {
            sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)    
            interval: 50, // number = milliseconds for onMouseOver polling interval    
            over: hoverOver, // function = onMouseOver callback (REQUIRED)    
            timeout: 600, // number = milliseconds delay before onMouseOut    
            out: hoverOut // function = onMouseOut callback (REQUIRED)    
        };

        $(parent + " ." + myClass).hoverIntent(config);

    }

});
