                 if(imageData == nil){
                     print("missing HQ image data")
                     // loading ended or aborted
-                    DetailController.isLoadingProgress = false
-                    
 
                     self.hidePrefetchHUD()
                     return

                        self.isHQImagePrefetched = true
                        
                        self.hidePrefetchHUD()
                    }
                    
                    

                        if(infoArray!["PHImageResultIsDegradedKey"] as! Bool == true){
                            print("============    DEGRADED: Setting no image     ============")
                            
                            return
                            
                        }
                        
                    }
                }
                
                if(imageData == nil){
                    print("missing HQ image data")
                   
                    return
                }
                
                
                
                // HERE NO FALLBACK IMAGE, since we already loaded the fallback as lowres before usually
                if let image = UIImage(data: imageData!){
                    print("next next image was prefetched")
                    
                    
                    
                    
                } else {
                    // loading ended or aborted

                    
                    print("error creating HQ image from data")
                }
                
            })
            
            
            
            
            
        }
        
        
        
    }
    
    // loads the full HQ image in the background
    // regardless of the current browsing direction
    func prefetchNextImage(){
        

        showPrefetchHUD()
        
        // get the next prefetch image
        var prefetchPosition = indexPosition + 1
        
        
        // do we have images at all?
        // and not only one image? otherwise the prefetching is useless
        if(phAssetResult.count > 1){
            // did we reach the end of the list, then switch to the start
            if(prefetchPosition == phAssetResult.count){
                prefetchPosition = 0
            }
    
            let prefetchAsset: PHAsset = getAsset(atIndex: prefetchPosition)
            

            
            // first load the main image synchronously for a quick result
            // and the load the image again asyncly and abort loading when the user swipes etc.
            imageAsyncRequestID =  self.loadImage(asset: prefetchAsset, isSynchronous: false, resultHandler: { imageData, dataUTI, orientation, infoArray in
                // The cell may have been recycled by the time this handler gets called;
                // set the cell's thumbnail image only if it's still showing the same asset.
                
                
                // general information about the loaded asset
                // print("Load information \(infoArray)")
                // HERE WE GET THE IMAGE
                
                
                
                if(infoArray != nil){
                    
                    // did we really get the requested image and not an old callback?
                    if(infoArray!["PHImageResultRequestIDKey"] != nil){
                        if(infoArray!["PHImageResultRequestIDKey"] as! PHImageRequestID != self.imageAsyncRequestID!){
                            // print("old image request \(infoArray!["PHImageResultRequestIDKey"]) ignoring result")
                            // no HUD update needed here, since this is not the image we want to display
                            return
                        }
                        
                    }
                    
                    
                    
                    if(infoArray!["PHImageResultIsDegradedKey"] != nil){
                        if(infoArray!["PHImageResultIsDegradedKey"] as! Bool == true){
                            print("============    DEGRADED: Setting no image     ============")
                            
                            self.hidePrefetchHUD()
                            return
                            
