
$(document).ready(function() {

    var active;

    $('#products').mouseenter(function() {
        active = this.id;
        $('#products-subnav').slideDown(400);
        closeOther();
    });

    $('#greenway').mouseenter(function() {
        active = this.id;
        $('#greenway-subnav').slideDown(400);
        closeOther();
    });
    $('#newsroom').mouseenter(function() {
        active = this.id;
        $('#newsroom-subnav').slideDown(400);
        closeOther();
    });
    $('#lubealert').mouseenter(function() {
        active = this.id;
        $('#lubealert-subnav').slideDown(400);
        closeOther();
    });

    var closeOther = function() {
        if (active != "products" && $('#products-subnav').is(':visible') == true) $('#products-subnav').slideUp(400);
        if (active != "greenway" && $('#greenway-subnav').is(':visible') == true) $('#greenway-subnav').slideUp(400);
        if (active != "newsroom" && $('#newsroom-subnav').is(':visible') == true) $('#newsroom-subnav').slideUp(400);
        if (active != "lubealert" && $('#lubealert-subnav').is(':visible') == true) $('#lubealert-subnav').slideUp(400);
    }

    //Open on load of page
    if (window.NavItem === undefined) {
        // do nothing 
    }
    else {
        if (NavItem == "products" || NavItem == "onroad" || NavItem == "offroad") $('#products-subnav').slideDown(400);
        if (NavItem == "newsroom" || NavItem == "newsroom-blog") $('#newsroom-subnav').slideDown(400);
        if (NavItem == "greenway" || NavItem == "fact-sheet" || NavItem == "greenway-products" || NavItem == "greenway-testimonials") $('#greenway-subnav').slideDown(400);
        if (NavItem == "lubealert" || NavItem == "lubealert-program" || NavItem == "lubealert-confidence-program" || NavItem == "lubealert-registration") $('#lubealert-subnav').slideDown(400);
    }


    /*On and Off Road JS*/
    //On MouseOver Red Point
    $('.red-point').mouseover(function() {
        $(this).toggleClass('green-point');
    });

    //On MouseOut Red Poing
    $('.red-point').mouseout(function() {
        $(this).removeClass('green-point');
    });

    $('.red-point').click(function() {

        if ($("#" + $(this).attr('container')).is(':visible') == false) {
            $('.detail-container').fadeOut();
            $("#" + $(this).attr('container')).fadeIn();
        }
        else {
            $("#" + $(this).attr('container')).fadeOut();
        }

    });

    $('.close-detail').click(function() {

        $('#' + $(this).attr('container')).fadeOut();

    });

});
