 enum BRNImagePickerSheetItemSize {
     case Normal, Enlarged
     
-    static func itemSizeForType(type: BRNImagePickerSheetItemSize, image: UIImage?) -> CGSize {
+    static var itemsRatioCache = [Int : CGFloat]()
+
+    static func itemSizeForType(type: BRNImagePickerSheetItemSize, asset: ALAsset?, indexPath: NSIndexPath?) -> CGSize {
         var ratio: CGFloat = 1.0
 
-        if let _image = image {
-            ratio = _image.size.width/_image.size.height
+        if let _indexPath = indexPath {
+            ratio = ratioForAsset(asset, indexPath: _indexPath)
         }
 
         switch type {

                    
                    let orientation = UIImageOrientation(defaultRepresentation.orientation())
                    
                    if let photo = UIImage(CGImage: defaultRepresentation.fullScreenImage().takeUnretainedValue(), scale: CGFloat(defaultRepresentation.scale()), orientation: orientation) {
                        
                        if let url : NSURL = self.saveImageOnDisk(photo) {
                            urls.append(url);

    // MARK: - UICollectionViewDelegateFlowLayout
    
    public func collectionView(collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        let asset = assets[indexPath.section]
        
        if enlargedPreviews {
            return BRNImagePickerSheetItemSize.itemSizeForType(.Enlarged, asset:asset, indexPath: indexPath)
        }
    
        return BRNImagePickerSheetItemSize.itemSizeForType(.Normal, asset:asset, indexPath: indexPath)
    }
    
    public func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        let inset = 2.0 * BRNImagePickerSheet.collectionViewCheckmarkInset

        let size = enlargedPreviews ? BRNImagePickerSheetItemSize.itemSizeForType(.Enlarged, asset:nil, indexPath:nil) : BRNImagePickerSheetItemSize.itemSizeForType(.Normal, asset: nil, indexPath: nil)
        return CGSizeMake(BRNImageSupplementaryView.checkmarkImage.size.width, size.height)
    }
    
