Hi

I'm trying to to write some code that loops through a bunch of anchors and on clicking one of these anchors, shows the relevant div. For some reason when clicking on any link in the page, it only shows the last div (in this case 'toggle2') i.e. the i variable in a[i].onclick only ever contains the value of the last number in the loop. Any help much appreciated.

Btw, I've used a function that loads init on onload;

Code:
var Seminars = {
	
	init : function(){
		var a = document.getElementsByTagName("a");
		var b = [];
		for(var i=0, j=a.length; i<j; i++){
			if(a[i].className.indexOf("toggle") != -1){
				b.push(i);
				var idx = b.length - 1;
				a[i].onclick = function(){	
					Seminars.toggle(idx);
					return false;
				};
			};
		};
	},
	
	toggle : function(idx){
		if(document.getElementById("toggle" + idx).style.display == "block"){
			document.getElementById("toggle" + idx).style.display = "none";
		}else{
			document.getElementById("toggle" + idx).style.display = "block";
		};
	}
		
};