$(function()
{  
  $.fn.slide = function(e)
  {
    //Get size of images, how many there are, then determin the size of the image reel.
    var imageWidth = 1000;//$(".top-rotator").width();
    var imageSum = $(".top-rotator-items .top-rotator-items-item").size();
    var imageReelWidth = imageWidth * imageSum;
    
    //Adjust the image reel to its new size
    $(".top-rotator-items").css({'width' : imageReelWidth});
    
    //Slider Function
    rotate = function(){          
      //Slider Animation
      var _trigger = $active.attr("id") - 1; //Get number of times to slide
      var _position = _trigger * imageWidth; //Determines the distance the image reel needs to slide
      
      $('.top-rotator-items .top-rotator-items-item').removeClass('active');
      $active.addClass('active');
      
      $(".top-rotator-items").animate({ 
        left: -_position
      }, 500 );
      
    }; 
    
    //Rotation + Timing Event
    rotateSwitch = function(){    
      $active = $('.top-rotator-items .top-rotator-items-item:first');
      rotate();
      
      play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
        $active = $(".top-rotator-items .top-rotator-items-item.active").next();
        if ($active.length === 0)
        { 
          $active = $('.top-rotator-items .top-rotator-items-item:first'); //go back to first
        }
        rotate(); //Trigger the paging and slider function
      }, 10000); //Timer speed in milliseconds (3 seconds)
    };
    
    rotateSwitch(); //Run function on launch    
  }
  $(".top-rotator-items").slide();
});

