Any idea what is causing this?
Yes. By
infowindow.setContent(document.getElementById("info"));
You are moving <div id="info">
into infowindow
. That goes well until you close the infowindow, because when you close the infowindow you are also removing <div id="info">
from the DOM! And after that,
document.getElementById("info").innerHTML=locations[i][0];
will raise an execption because <div id="info">
no longer exists :
Uncaught TypeError: Cannot set property 'innerHTML' of null
You should really find another approach. I would remove <div id="info"></div>
from the HTML and use this code instead :
var content='<div id="info">'+locations[i][0]+'</div>';
infowindow.setContent(content);
infowindow.open(map, marker);
see forked fiddle -> http://jsfiddle.net/E2CxC/