window.addEvent('domready', function() { var item_width = 295; var item_height = 90 + 30; var numitems = 5; var carousel_width = 590 + (numitems); var t_stepsize = 590; var stepsize = t_stepsize + (Math.ceil(t_stepsize/item_width)); var currpos = 0; var start = 0; $('carousel_wrap').setStyle('height', item_height); $('carousel_wrap').setStyle('width', carousel_width); $$('.carousel_item').setStyle('width', item_width); $$('.carousel_item').setStyle('height', item_height); var full_width = ((numitems) + (numitems * item_width)); //$('track').set('html', carousel_width); var steps = Math.ceil(full_width/carousel_width); $('carousel_next').addEvent('click', function(){ //$('track').set('html', currpos + ' ' + steps + ' ' + numitems + ' ' + full_width + ' '+ start); if( (currpos) < steps && steps != numitems && ( (stepsize * (currpos+1)) < full_width) ){ currpos++; start = (stepsize * currpos * -1); $('the_carousel').tween('margin-left', start); } }); $('carousel_prev').addEvent('click', function(){ if(currpos > 0){ currpos--; start = (stepsize * currpos * -1); $('the_carousel').tween('margin-left', start); } }); });