// Configuration of the hoverIntent
var menuConfig = {
    interval: 100,
    sensitivity: 3,
    over: addMenu,
    timeout: 500,
    out: removeMenu
};

// Function for displaying the menu when called for
function addMenu() {
    if (!($(this).hasClass("hover"))) {
        // Add class hover
        $(this).addClass("hover");
        // Hide drop down
        $('ul', this).hide();
        // Fade in drop down
        $('ul', this).fadeIn(75);
    }
}

// Function for removing the menu when called for
function removeMenu() {
    // If this li element has a submenu item
    if (!($('ul', this).length == 0)) {
        // Fade it out
        $('ul', this).fadeOut(75, function() {
            // Remove hover class
            $(this).parent().removeClass("hover");
        });
    }
    // If not just remove hover class
    else {
        $(this).removeClass("hover");
    }
}

// On document ready, attach hoverIntent to navigation menuitems
$(document).ready(function(){
    $("#header .nav li.main").hoverIntent(menuConfig)
});
