Javascript onclick shows last element of array with for loop
<p>I have little problem. I am working with one companys API's. I request for activities and they return me array of activities. Here is part of code.</p>

<pre><code>client.requestActivities(function(activities) {
        if (activities.length &gt; 0) {
            for(i=0; i &lt; activities.length; i++) {
                var activity = activities[i];
                activity.onStart(function() { alert(i+ " started"); });
                activity.onCredit(function() { alert(i+ " credit"); });
                activity.onClose(function() { alert(i+ " close"); });
                activity.onFinish(function() { alert(i+ " finish"); });
                            $('.Game-Screen-Footer').append('&lt;div class="Game-Screen-Footer-Adv" id="foota'+i+'"&gt;&lt;a href="javascript:;" &gt;&lt;img src="'+activity.image_url+'" alt="'+activity.display_text+'" width="190" height="110"&gt;&lt;/a&gt;&lt;/div&gt;');
                document.getElementById('foota'+i+'').onclick = function() {
                ARNO.box.show({html:'&lt;div id="socialVibeFancyBox0"&gt;&lt;/div&gt;', close: false, width:activity.window_width, height:activity.window_height, openjs: 
                            function(){
                                client.loadActivityIntoContainer(activity, 'socialVibeFancyBox0');
                            }
                        });
            }
        }
</code></pre>

<p>}</p>

<p>Mostly, this function give back array with 3 elements. But when I click on first activity, onStart it should alert me (0 start), but it alerts (4 start), this means, that it alerts last element of i. How should I fix this? I tried a lot of stuff, but I haven't find solution, maybe you can help me?</p>
