Change JavaScript navigation ordering to a function