
//Namespace used to handle the animation effects of the sub-nav

var subNav = (function() {

    //private



    //public
    return {

        //Function which hides children of inactive parent navigation items
        hideInactive: function() {
            //Hide nested lists of item currently inactive
            $('.sub-nav > li').filter(function() {
                if ($(this).find('a:first').hasClass('active')) {
                    return false;
                } else {
                    return true;
                }
            }).find('ul').css('display', 'none');
        },

        //Function which binds click event to parent links
        bindClick: function() {
            $('.sub-nav > li').find('a:first').click(function($e) {
                if ($(this).attr('href') == '#') $e.preventDefault();
                //Hide nested list of item currently selected
                $('.sub-nav > li a.active').removeClass('active').parent().find('ul').slideUp(200);

                //Show nested list of item clicked
                $(this).addClass('active').parent().find('ul:first').slideDown(200);

            });
        },


        //Function which initializes the left nav
        init: function() {
            //Hide nested lists of inactive parent links
            this.hideInactive();

            //Attach click event
            this.bindClick();
        }
    };

})();


$(document).ready(function() {
    subNav.init();

});
