Google Maps addListener to draw a polygon

I have a Google Map with over 500 markers on it. For each markers location I have carried out a line of sight calculation and have determined the coordinates of a polygon indicating how far someone could see from that markers location.

I'd like my users to be able to click on a marker and for the polygon representing the coverage at the marker to be drawn as well as an infoWindow containing the name of the marker location.

When each marker is clicked I want to call another function that I have written drawPolyon() which accepts the marker name and which retrieves the coordinates of the polygon for that marker via AJAX. This function exists and works.

What I cannot do is to determine how to pass the name of the marker to the drawPolygon() function. The problem is that no matter what I do, the value of 'name' passed when I click the marker is always the same and is the last name in my list of markers so it appears that I have created one click listener which is applied to all markers.

I guess that I'm trying add a unique click listener to each marker.

I have the following code:

// Loop over markers
for (var i = 0; i < markers.length; i++) {
    // Store code from each marker
    var name = markers[i].getAttribute("name");
    var icon = markers[i].getAttribute("icon");
    // Define new lat-lon pair for this marker
    var point = new google.maps.LatLng(
        // Get values from marker
        parseFloat(markers[i].getAttribute("lat")),
        parseFloat(markers[i].getAttribute("lng"))
    );
    // Build content to display in infowindow
    var html = '<div align="left"><b>Rx</b>: ' + name + '</div>';

    // Construct marker
    var marker = new google.maps.Marker({
        map: coverageMap,
        position: point,
        icon: icon
    });

    // Bind the infowindow to it
    bindInfoWindow(marker, coverageMap, infoWindow, html);

    google.maps.event.addListener(marker, 'click', function() {drawPolygon(name)});
}

I found this article:

http://you.arenot.me/2010/06/29/google-maps-api-v3-0-multiple-markers-multiple-infowindows/

for infowindows which uses 'this' but I cannot see how to apply it in this case, this.name doesn't work for example. Nor did the answer that this was erroneously marked as a duplicate of by a trigger-happy editor !