I am using jQuery 1.4.2 and I am trying to carry over the global variable totaltabs into my JSON callback function. The code seems to work properly, however, in my loadJSON function after the callback function loads the data, my totaltabs variable will not increment.

Here is a peak at my code. Any ideas?

totalItems is loaded from another function, not relevant to my example.

Code JavaScript:
var totaltabs = 0;
 
$(document).ready(function(){
 
	resize();
 
 
	for(i = 0; i < totalItems.length; i++){
		loadJSON(totalItems[i]);
	}
 
});
 
function loadJSON(params) {
 
	$.getJSON("/path/to/json",function(data){
 
		totaltabs++;
 
		alert(totaltabs);
 
		if (data.TotalItems == 0) {
			$("#tab-"+totaltabs+" ul").append('<li><div class="wrap"><p>No items found.</p></div></li>');
		}
		else {
			$.each(data.Item, function(i,item){
 
				var title = item.Title;
 
				if (null != title)
				{
					$("#tab-"+totaltabs+" ul").append('<li><div class="wrap"><div class="desc">' + title + '</div></div></li>');
				}
			});
		}
 
 
		$("#tab-"+totaltabs+" .title a").attr("href", data.ItemURL);
		$("#tab-"+totaltabs+" .title a").append(" (" + data.TotalItems + ")");
 
	});
 
}