One way to get the id param from the query string would be to change the first line of your function to this:
var hash = window.location.search.match( /\?id=([0-9a-zA-Z_]+)/ );
Although as you can have multiple parameters in a query string, it might be more useful to have a function that can return the value of any parameter when given the key:
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}