I guess I would make the click function a separate function which you can call from the click event as well as the document ready event.
The click event passes the right item by clicking on the item. Document ready passes the right item by searching for your
active-trail class, or just get the first item.
The result would then be something like this: https://codepen.io/jeroenreijs/pen/rwzLwo