Hi all,

I have the following code snippet that i am having some trouble with.

Code:
<script>

var holding = document.getElementById("chooseframe"); // Contains outer div element //

var imageholders = [];
for(var i=0;i<images.length;i++)   // loops through all images in the images array //
{
imageholders[i] = document.createElement("IMG");
imageholders[i].src=images[i];
imageholders[i].className = "tabs";
imageholders[i].onclick = function()  {
	document.slideshow1.src=images[i]; //makes the slideshow image the image of the current IMG being clicked //
	document.slideshow.src=images[i];  //multilayer slideshow so does the same thing as the above code  //
	window.clearInterval(pauseme);      // again, clears variables used in the slideshow //
	window.clearInterval(runfront);
	window.clearInterval(runback);
	};
	
holding.appendChild(imageholders[i]);  //displays the IMG elements created as children of the first variable //
}

var nodes = document.getElementById('chooseframe').children; //this part of the code is irrelevant really as all this is doing is sizing the elements depending on how many elements there are in the imageholders array //
var amount = 100/nodes.length;
for(w=0;w<nodes.length;w++)
{
nodes[w].style.height=amount+"%";
}

</script>
The problem here is the
Code:
imageholders[i].onclick = function()  {
	document.slideshow1.src=images[i]; //makes the slideshow image the image of the current IMG being clicked //
	document.slideshow.src=images[i];  //multilayer slideshow so does the same thing as the above code  //
	window.clearInterval(pauseme);      // again, clears variables used in the slideshow //
	window.clearInterval(runfront);
	window.clearInterval(runback);
	};
I assumed at first that the onclick would get the dynamic value of i as everything else does. However, I started to get that the function was not working like that but was instead seeing i when then function was actually being called (so i = 4). I have tried so many ways to fix this, looked up quite a few old posts aswell but cannot seem to figure out a way to fix this for my code.

Can anyone help to resolve this and if so please explain how the "fixed" code works.

Thanks to anyone and everyone who helps

ps: whole code can be seen on my test site here http://englishseadragon.appspot.com/ (please ignore the pictures, :P)