In this code I am supposed to bind a rollover effect to each <area> tag in a <map> element.
function initLinks(webrt) {
  var areas = document.querySelectorAll("map#streetmap > area");
  var links = new Array(areas.length);
  for (var i=0; i<links.length; i++) {
    links[i] = new Image(786,272);
    links[i].src = webrt+"templates/default/sketches/links"+(i+1)+".png";
    areas[i].onmouseover=function(){switchLinkImg(webrt+"templates/default/sketches/links"+(i+1)+".png");};
    areas[i].onmouseout=function(){switchLinkImg(webrt+"templates/default/sketches/links.png");};
  }
}
Strangely, each <area> onmouseover event tries to load the non-existing image: /templates/default/sketches/links6.png. Why does it keep this variable i which has incremented to 6 as a global variable rather than take the string I am passing to the function?
How do I fix this?
Note: No jQuery!
 
     
    