Why are you creating another marker at the same spot each time a user clicks on the marker? That doesn't make sense.
Anyway, if you want to remove the marker on the marker click event is instead of calling addMarker create a function to deleteMarker which would iterate through your markersArray and delete the Marker such as:
It would look something like this:
var listener = (google.maps.event.addListener(marker, "click", function () {
for ( var i = 0; i < markersArray.Length; i++ )
{
if ( markersArray[i].id ==
marker.id )
{
markersArray[i].setMap(null);
markersArray.splice(i, 1);
}
}
}));
I didn't check to make sure you were keeping track of the listeners for all your markers. If you aren't you need to as you will have a potential memory leak as the listeners would never be getting deleted, you would use a similar method of adding and removing the listeners as you do for handling the markers.
If you have any questions feel free to ask.