$(document).ready(function() {
	var speed = 5000;
    var run = setInterval('rotate()', speed);   
     
    //grab the width and calculate left value
    var item_width = $('#gallery a').outerWidth(); 
    var left_value = item_width * (-1); 
         
    //move the last item before first item, just in case user click prev button
    $('#gallery a:first').before($('#gallery a:last'));
     
    //set the default item to the correct position 
    $('#gallery p').css({'left' : left_value});
         
});
 
//a simple function to click next link
//a timer will call this function, and the rotation will begin :)  
function rotate() {
  
    //get the right position
    var left_indent = parseInt($('#gallery p').css('left')) - 180;
	
     //slide the item
     $('#gallery p').animate({'left' : left_indent}, 200, function () {
             
     //move the first item and put it as last item
	 $('#gallery img:last').after($('#gallery img:first'));                           
            //set the default item to correct position
            $('#gallery p').css({'left' : 0});
         
        });
}
