Alternative, even more easy-way solution for the task is to use SAP CRM's standard JavaScript method thtmlb_NavBarToggle(), which changes navigation bar mode from expanded to collapsed and vice versa.
This function may be called inside of BSP of view where we want to hide or expand the navigation bar. You can also to wrap this call by checking of navigation bar current mode in order to supply only one action — collapsing or expanding.