var _speed = 1000;
var _timeout = 5000;

function rotateImages() {
	var oCurPhoto = $("#rotator ul li.show");
	var oNxtPhoto = oCurPhoto.next();
	if (oNxtPhoto.length == 0)
	{
		oNxtPhoto = $("#rotator ul li:first");
	}
			
	oCurPhoto.fadeOut(_speed, function() { 
								oNxtPhoto.fadeIn(_speed);
								oNxtPhoto.addClass('show');
								oCurPhoto.removeClass('show');
	});
}

function rotateImagesPrev() {
	var oCurPhoto = $("#rotator ul li.show");
	var oPrevPhoto = oCurPhoto.prev();
	if (oPrevPhoto.length == 0)
	{
		oPrevPhoto = $("#rotator ul li:last");
	}
			
	oCurPhoto.fadeOut(_speed, function() { 
								oPrevPhoto.fadeIn(_speed);
								oPrevPhoto.addClass('show');
								oCurPhoto.removeClass('show');
	});
}

$(document).ready(function() {
		var rotateInterval = setInterval("rotateImages()", _timeout);
		
		$("a.next").click(function() {
			clearInterval(rotateInterval);
			rotateInterval = setInterval("rotateImages()", _timeout);
			rotateImages();
			return false;
		});
		
		$("a.prev").click(function() { 
			clearInterval(rotateInterval);
			rotateInterval = setInterval("rotateImages()", _timeout);
			rotateImagesPrev();		
			return false;
		});
});
