I have a list of nodes and I am going to draw each node using a raphael object. I have the following loop:
for(var i=0; i<curNodes.length; i++){
    var node = curNodes[i];
    var obj = paper.rect(node.getX(), node.getY(), node.width, node.getHeight())
   .attr({fill:nodes[i].getColor(), "fill-opacity": 0.6})
   .click(function(e){ onMouseClicked(i,e); });
}
on click, I want to call a function which can view some data associated with 'i' th element of curNodes array. However, all the time the last 'i' is passed to this function. my function is:
var onMouseClicked = function(i, event){
switch (event.which) {
    case 1:
        this.attr({title: curNodes[i].name});
        break;
    }
}
How should I access the correct index when calling a function?
 
     
    