function canManipulateImages() {
	if (document.images)
		return true;
	else
		return false;
}

function loadSlide(imageURL) {
	if (gImageCapableBrowser) {
		document['slide' + gCurrentSlide].src = imageURL;
		return false;
	}
	else {
		return true;
	}
}
function nextSlide() {
	gCurrentSlide = ++gCurrentSlide % gNumberOfSlides;
	gCurrentImage[gCurrentSlide] = ++gCurrentImage[gCurrentSlide] % gImages[gCurrentSlide].length;
	loadSlide(gImages[gCurrentSlide][gCurrentImage[gCurrentSlide]]);
}

gImageCapableBrowser = canManipulateImages();

$(document).ready(function(){
	gImages = new Array(4);
	
	$.getJSON('/js/toylist.php?c=1', function(data){gImages[0] = data;startup();});
	$.getJSON('/js/toylist.php?c=2', function(data){gImages[1] = data;startup();});
	$.getJSON('/js/toylist.php?c=3', function(data){gImages[2] = data;startup();});
	$.getJSON('/js/toylist.php?c=4', function(data){gImages[3] = data;startup();});
});

coldRuns = 0;

function startup()	{
	if(++coldRuns != 4)return;
	gSlideName = 'slide';
	gSlideshowInterval = 1; // how often the image is refreshed (time given in seconds)
	gCurrentImage = [0,0,0,0];
	gCurrentSlide = 0;
	gNumberOfSlides = 4;
	setInterval("nextSlide()",gSlideshowInterval * 1000);
}
