var counter = 1;
var items = new Array();
var irotate = null;
var interval = 5000;

function Rotate(container, imgprefix, thumbprefix, speed) {
	interval = speed;
	jQuery("a", "." + container).each(function() {
		items.push(imgprefix + (items.length + 1));
		jQuery("." + thumbprefix + items.length).mouseover(function() {
			clearTimeout(irotate);
			counter = parseInt(this.className.replace(thumbprefix, ""));
			ResetRotation();
			jQuery("#" + items[counter - 1]).css("display", "block");
		});
		jQuery("." + thumbprefix + items.length).mouseout(function() {
			clearTimeout(irotate);
			irotate = setTimeout("StartRotate()", interval);
		});
	});
	StartRotate();
}

function StartRotate() {
	clearTimeout(irotate);
	if (counter >= items.length)
		counter = 0;
	jQuery("#" + items[(counter == 0 ? items.length - 1 : counter - 1)]).fadeOut(500);
	jQuery("#" + items[counter]).fadeIn(500);
	counter++;
	irotate = setTimeout("StartRotate()", interval);
}

function ResetRotation() {
	jQuery(items).each(function() {
		jQuery("#" + this).css("display", "none");
	});
}
