$(function() {
    var COOKIE_NAME    = "last_facet";
    var COOKIE_OPTIONS = { path: '/browse/' };

    $('.sub_section').find('h5').each(function() {
            if ($(this).parent().hasClass("selected")) {
                var facet_id = $(this).parent().attr("id");
                if (facet_id) {
                    $('> a', this).bind("click", function(e) {
                        $.cookie(COOKIE_NAME, facet_id, COOKIE_OPTIONS);
                    });
        }
            }

        if (!$(this).parent().hasClass('selected')){
        $(this).bind("click", function() {
            $(this).next('ul').toggle(400);
            $(this).toggleClass('plus');
        });
        }
    });

    var last_facet = $.cookie(COOKIE_NAME);

        $('.subnav :not(.non_facet)').find('div:gt(4)').each(function(){
        if (this.id != last_facet) {
            $(this).find('ul').addClass('facet_hide');
            $(this).find('h5').addClass('plus');

        } else {
        $.cookie(COOKIE_NAME, '', COOKIE_OPTIONS);
        }
        /* Manually hide DE Certificate/FSK */
        $('#certificate').find('ul').addClass('facet_hide');
        $('#certificate').find('h5').addClass('plus');

        });
});

