         // Dispose of any resources that can be recreated.
     }
     
-    func viewControllerAtIndex(index: Int) -> PictureContentViewController? {
+    func viewControllerAtIndex(index: Int) -> UIViewController? {
         
-        let storyboard = UIStoryboard(name: "Main", bundle: nil)
-        let stopContentVC = storyboard.instantiateViewControllerWithIdentifier("stopContentVC") as! PictureContentViewController
+        guard allStopContent.count > 0 else {
+            let stopContentVC = storyboard?.instantiateViewControllerWithIdentifier("stopContentVC") as! PictureContentViewController
+            stopContentVC.picText = "No Stop Selected"
+            
+            return stopContentVC
+        }
         
-        if let stop = stop {
+        if let _ = (allStopContent[index])["picImage"]  {
+            let stopContentVC = storyboard?.instantiateViewControllerWithIdentifier("stopContentVC") as! PictureContentViewController
+            if let _ = stop {
+                
+                stopContentVC.delegate = self
+                stopContentVC.picImageFileName = (allStopContent[index])["picImage"]!
+                stopContentVC.picText = (allStopContent[index])["picText"]!
+                stopContentVC.maxPages = allStopContent.count
+                
+                
+            } else {
+                stopContentVC.picText = "No Stop Selected"
+            }
+            stopContentVC.pageIndex = index
+            return stopContentVC
+        }else {
+            let youTubeContentVC = storyboard?.instantiateViewControllerWithIdentifier("YouTubeVC") as! YouTubeContentViewController
             
+            youTubeContentVC.delegate = self
+            youTubeContentVC.maxPages = allStopContent.count
+            youTubeContentVC.pageIndex = index
             
-            stopContentVC.picImageFileName = (stop.stopPictures[index])["picImage"]!
-            stopContentVC.picText = (stop.stopPictures[index])["picText"]!
-            stopContentVC.maxPages = stop.stopPictures.count
-            
-            
-        } else {
-            stopContentVC.picText = "No Stop Selected  abc"
+            youTubeContentVC.youTubeID = (allStopContent[index])["YouTubeID"]!
+            youTubeContentVC.youTubeText = (allStopContent[index])["YouTubeText"]!
+            return youTubeContentVC
         }
-        stopContentVC.pageIndex = self.pageIndex
-        
-                
-        return stopContentVC
         
     }
     

    
    func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
        
        guard let stop = stop else {return nil}
        
        let stopContentVC = viewController as! PictureContentViewController
        pageIndex = stopContentVC.pageIndex + 1
       
        if pageIndex > (stop.stopPictures.count) - 1 {
            pageIndex = (stop.stopPictures.count) - 1
            return nil
        } else {
            return viewControllerAtIndex(pageIndex)
            
        }
    }
    


    
}

        super.viewDidLoad()
        
        self.dataSource = self
        
        if let stop = stop {
            allStopContent = stop.stopPictures + (stop.youTubes ?? [])  // ?? is nil coalescing
            // operator - If stop.youTubes is not nil it is unwrapped, otherwise the empty array is
            // returned
        }
        
        let firstVC = viewControllerAtIndex(0)
        setViewControllers([firstVC!], direction: .Forward, animated: true, completion: nil)
        
