document.observe("dom:loaded", function() {
  var element = $("preview");

	if (element) {
		var currentIndex = 0, maxIndex = $$("#carousel .entry").size();
 
		 $("preview_next").observe("click", function(event) {
		   currentIndex = (currentIndex + 1) % maxIndex;
		   $("carousel").morph("left: " + (currentIndex * -940) + "px", { duration: 1, transition: 'webkitEaseInOut' });
		 });
 
		 $("preview_previous").observe("click", function(event) {
		   currentIndex = (currentIndex - 1) < 0 ? maxIndex - 1 : currentIndex - 1;
		   $("carousel").morph("left: " + (currentIndex * -940) + "px", { duration: 1, transition: 'webkitEaseInOut' });
		 });
	}
});
