$(document).ready(function() { var w=449*; $('#calosc').css("width", w+"px"); timer = setInterval('slide("left")', 3000); $(document).bind('keypress', function(e) { if(e.keyCode==37) { clearInterval(timer); slide('right'); } else if(e.keyCode==39) { clearInterval(timer); slide('left'); } }); }); function slide(where) { var scrollAmount = $('#calosc').width() - $('#calosc').parent().width(); var currentPos = Math.abs(parseInt($('#calosc').css('left'))); var Scroll = Math.floor($('#calosc').parent().width()); if(where == 'left' && (currentPos < scrollAmount-$('#calosc').parent().width())) { $('#calosc:not(:animated)').animate({'left':'-=' + Scroll}, 'slow'); } if(where == 'right' && currentPos != 0) { $('#calosc:not(:animated)').animate({'left':'+=' + Scroll}, 'slow'); } }