function preloadImage(src) {
	img = new Image();
	img.src = src;
}

var rotations = {};

function rotateAmong(name, img_ids) {
	var n = 0;
	function nextN() {
		return (n + 1) % img_ids.length;
	}
	
	function sync() {
		$(name).src = img_ids[n];
	}
	
	n = nextN();
	sync();
	
	if (!rotations[name]) {
 		rotations[name] = new PeriodicalExecuter(function (pe) {
				n = nextN();
				sync();
				preloadImage(img_ids[nextN()]);
			},
			1
		);
	}
	
	$(name).observe('mouseout', function (evt) {
		rotations[name].stop();
		rotations[name] = false;
		$(name).stopObserving('mouseout');
		n = 0;
		sync();
	});
}
