put this code at first line
lastWindow=null;
then edit your click listener like this
google.maps.event.addListener(marker, 'click', function() {
if (lastWindow) lastWindow.close();
this.infowindow.open(map, this);
lastWindow=infowindow;
});