     
     
     func animationNext(){
-        NSTimer.scheduledTimerWithTimeInterval(2, target: self, selector: #selector(ViewPager.moveToNextPage), userInfo: nil, repeats: true)
+        Timer.scheduledTimer(timeInterval: 2, target: self, selector: #selector(ViewPager.moveToNextPage), userInfo: nil, repeats: true)
     }
     func moveToNextPage (){
         if(currentPosition <= numberOfItems && currentPosition > 0) {
-            scrollToPage(currentPosition)
+            scrollToPage(index: currentPosition)
             currentPosition = currentPosition + 1
             if currentPosition > numberOfItems {
                 currentPosition = 1


extension ViewPager:UIScrollViewDelegate{
    
    //http://stackoverflow.com/a/1857162
    public func scrollViewDidScroll(scrollView: UIScrollView) {
        NSObject.cancelPreviousPerformRequestsWithTarget(scrollView)
        self.performSelector(#selector(self.scrollViewDidEndScrollingAnimation(_:)), withObject: scrollView, afterDelay: 0.3)
    }
    
    public func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
        NSObject.cancelPreviousPerformRequestsWithTarget(self)
        var pageNumber = round(scrollView.contentOffset.x / scrollView.frame.size.width)
        pageNumber = pageNumber + 1
        pageControl.currentPage = Int(pageNumber)
        currentPosition = pageControl.currentPage
        scrollToPage(Int(pageNumber))
    }
    
    
}


            view.removeFromSuperview()
        }
        
        DispatchQueue.main.async {
            self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width *  CGFloat(self.numberOfItems) , height: self.scrollView.frame.height)
            self.reloadViews(index: 0)
        }
    }
    
    func loadViewAtIndex(index:Int){
        let view:UIView?
        if(dataSource != nil){
            view =  (dataSource?.viewAtIndex(viewPager: self, index: index, view: itemViews[index]))!
        }else{
            view = UIView()
        }
        
        setFrameForView(view: view!, index: index);
        
        
        if(itemViews[index] == nil){
