var menu = document.getElementById("nav").getElementsByTagName("a");
var list = document.getElementById("nav").getElementsByTagName("li");
//creates an array out of each "a" element
for(var i=0; i<menu.length; i++) {
    if(menu[i].href == "http://"+window.location.hostname+window.location.pathname) {
        list[i].className="selected";
    }
}

