Close Dropdown on click

I’m using isotope to filter bunch of images with a dropdown in the same page.

the jsfiddle here , im trying to close the dropdown when the Product 2 list is clicked open or any of the child of Product 2 or Product 3 is clicked closing all the other Product list but keeping the current parent dropdown open and attaching hasarrowndown class to it when its open.

currently the situation is when i open Product 1 and click on Product 1 child it closes all main dropdown and opens up Product 1 dropdown again you can see the behavior in the jsfiddle its not just product 1 same thing with product 2 also.

$('.topnav li a').click(function () {
    if ($(this).parent().children().is('ul')) {
        $(this).parent().find('ul').slideToggle();
    } else {
        if ($(this).parent().parent().is('ul.topnav')) {
            $('.topnav').find('ul').slideUp();
        } else {
            $('.topnav').find('ul').slideUp();
            $(this).parent().parent().slideDown('slow');
        }
    }
});