/** * Vittorio Ottaviani - Mitecube -2011 */ $(document).ready(function() { //rotation speed and timer //move the last item before first item, just in case user click prev button $('.carouselNews li:first').before($('.carouselNews li:last')); mite_prepareCarousel(); $(document).keydown( function(event) { if ( event.which == 37 ) $('.btnPrevNews').click(); if ( event.which == 39 ) $('.btnNextNews').click(); } ); }); function mite_prepareCarousel() { var speed = 5000; //grab the width and calculate left value var item_width = $('.carouselNews li').outerWidth(); var left_value = item_width * (-1); //set the default item to the correct position $('.carouselNews').css({'left' : left_value}); //if user clicked on prev button $('.btnPrevNews').click(function() { //get the right position var item_width = $('.carouselNews li').outerWidth(); var left_indent = parseInt($('.carouselNews').css('left')) + item_width; var left_value = item_width * (-1); //slide the item $('.carouselNews:not(:animated)').animate({'left' : left_indent}, 600,function(){ //move the last item and put it as first item $('.carouselNews li:first').before($('.carouselNews li:last')); //set the default item to correct position $('.carouselNews').css({'left' : left_value}); }); //cancel the link behavior return false; }); //if user clicked on next button $('.btnNextNews').click(function() { //get the right position var item_width = $('.carouselNews li').outerWidth(); var left_indent = parseInt($('.carouselNews').css('left')) - item_width; var left_value = item_width * (-1); //slide the item $('.carouselNews:not(:animated)').animate({'left' : left_indent}, 600, function () { //move the first item and put it as last item $('.carouselNews li:last').after($('.carouselNews li:first')); //set the default item to correct position $('.carouselNews').css({'left' : left_value}); }); //cancel the link behavior return false; }); }