setTimeout issue

Hi there,

So I’m writing an image slideshow in jQuery, and I have an array of img srcs which I am sending to a function:


function revolve(array, delay){
	var src = array[0];
	var nextSrc = array[1];
	$('#window img[src="' + nextSrc + '"]').css({"z-index": 50});
	$('#window img[src="' + src +'"]').css({"z-index": 100}).fadeOut(1000, function(){
		$(this).css({"z-index": 0}).show();
	});
	array.shift();
	array.push(src);
	[B]timer = setTimeout("revolve(" + array + ", " + delay + ")", delay + 1000);[/B]
}

now, when the script gets down to the last line, I get this error:
Uncaught SyntaxError: Unexpected token ILLEGAL

But when I call the function like so:


revolve(images, 1000);

It runs fine. I only get the error message when I use a setTimeout();

I’m not sure what’s happening because the error message doesn’t make a lot of sense to me, plus I couldn’t find anything that seemed particularly relevant online about it.

Thanks in advance,
Mike

Does:

var timer = setTimeout(“revolve(” + array + ", " + delay + “)”, delay + 1000);

do the trick?

Hi beebs93, thanks for your reply.

I actually set var timer; before I called the function. I realise it has something to do with the array, because the setTimeout takes a string, so converts the array into a string before it passes it to the function. The function is looking for an array, and so gives the error.

If I change the function like so:


function revolve (delay){
var src = images[0];
var nextSrc = images[1];

// etc etc

images.shift();
images.push(src);
timer = setTimeout("revolve(" + delay + ")", 1000 + delay);

It works fine. That’ll do the trick for the moment, but I’d love to know how to pass an array to a function using setTimeout.

Anyway, thanks for your input,
Mike