timer = 0;
freq = 3000; //change this var to change frequency of rotation
imgs = new Array();
last_which = 1;
next_img = 0;

function preload() {
	srcs = preload.arguments;
	for (i=0; i < srcs.length; i++)
	{
		imgs[i] = new Image(90,100);
		imgs[i].src = srcs[i];
	}
	timer = setTimeout("rotate()",freq);
}


function rotate() {
	timer = null;
	x = randnum();
	last_which = x;
	which = document.getElementById('rand'+x);
	if (which) which.src = get_src();//imgs[next_img].src;
	next_img = (next_img + 1) > (imgs.length - 1) ? 1 : (next_img + 1);
	timer = setTimeout("rotate()",freq);
}

function randnum() {
	got = false;
	while (got != true)
	{
		num = Math.round(Math.random() * 2) + 1;
		if (num != last_which) got = true;
	}
	return num;
}

function get_src() {
	new_src = false;
	while (new_src==false)
	{
		used = false;
		for (i=1; i <= 3; i++)
		{
			which = document.getElementById('rand'+i)
			if (which && which.src==imgs[next_img].src)
			{
				used = true;
				next_img = next_img + 1;
			}
		}
		if (!used) new_src = imgs[next_img].src;
	}
	return new_src;
}