Hi,

I've been working on an AJAX gallery recently, and I have a problem that I can't figure out (I'm quite new at javascript). What I want to happen is when the user clicks on a particular thing (a td cell in this case), it calls a script and recieves data from it (which javascript then processes and displays). The thing that happens with my script is that on the first click, nothing happens, but any click after that and the data seems to come through. Here's my script:
Code:
var ajaxgallerydata;
function ajaxgallery(url) 
{
   http.open('get', url, true);
   http.onreadystatechange = handleResponseGallery;
   http.send(null);
}
function handleResponseGallery() 
{
	if(http.readyState == 4 && http.status == 200)
	{
		var response = http.responseText;
		if(response) 
		{
			ajaxgallerydata = response;
		}
	}
}
function switch_gallery(gallery)
{
	ajaxgallery('gallery.php?act=ajaxgallery&gallery=' + gallery);
	if (ajaxgallerydata)
	{
		str = ajaxgallerydata.split('{<!splitter!>}');
		document.getElementById('maindisplaywindow').innerHTML = str[0];
		document.getElementById('photoscontainer').innerHTML = str[1];
	}
	str = null;
}
The str.split is used to process the data into 2 parts, which I believe is the problem. When I removed the if (ajaxgallerydata), I got an error saying that ajaxgallerydata had no properties, so then I made it output the data and it showed as null. Is there any fix to this?
Also, is it possible to select all images in all td's on a page that have the same class?
Thanks