Ahoy!

I want to put this code in the head of my main index page so that it redirects to my translated pages only if the browser language is French, Spanish or German. If the browser language is anything else (including English) then I want it to remain on my main index page. I can't get it to work. It seems to want to redirect even if the language isn't "fr", "es" or "de". I'd really appreciate any help.

Code:
<script>
var langcodes=new Array("fr", "es", "de")

var langredirects=new Array("french.html", "spanish.html", "german.html")

var languageinfo=navigator.language? navigator.language : navigator.userLanguage

function redirectpage(dest){
if (window.location.replace)
window.location.replace(dest)
else
window.location=dest
}

for (i=0;i<langcodes.length-1;i++){
if (languageinfo.substr(0,2)==langcodes[i]){
redirectpage(langredirects[i])

break
}
}
</script>
Thanks