Just an example, not tested at all (I just wrote it straight into here) but should give some clues.
Code:
function showAndGo(show, go) {
var elem = document.getElementById("list" + show);
// If listn actually exist, play with it.
if (elem) {
elem.className = "visible";
}
// Now, go to that anchor!
window.location.hash = go;
}
// Example use:
// This would so list with is "list1" and go to anchor "#1"
showAndGo('1', '1');