 
 class ASFloatingHeadersFlowLayout: UICollectionViewFlowLayout {
     
-    var sectionHeadersAttributes:Array<UICollectionViewLayoutAttributes!> = []
+    var sectionAttributes:[(header:UICollectionViewLayoutAttributes!,footer:UICollectionViewLayoutAttributes!)] = []
     let offsets = NSMutableOrderedSet()
     var floatingSectionIndex:Int! = nil
     var previousWidth:CGFloat! = nil

        })
    }
    
    func setFloatingHeaderOffset(offset:CGFloat, forIndex:Int){
        let attrs = self.sectionHeadersAttributes[forIndex]
        attrs.frame = CGRectMake(0, offset, attrs.frame.size.width, attrs.frame.size.height)
        attrs.zIndex = 1024
        println("SetOffset: \(offset) forIndex:\(forIndex)")
        
        // должна помнить - самый первый offset до изменения
    }
    
   
    override func invalidationContextForBoundsChange(newBounds: CGRect) -> UICollectionViewLayoutInvalidationContext {
        
        
        var context = super.invalidationContextForBoundsChange(newBounds)
        if let width = self.previousWidth{
            if (width != newBounds.size.width){
                println("FORCE PREPARE LAYOUT width changed \(width) -> \(newBounds.size.width) newBounds = \(newBounds)")
                self.previousWidth = newBounds.size.width
                return context
            }
        }
        
        self.previousWidth = newBounds.size.width

        // здесь инвалидируем конкретный аттрибут - выставляем его новые значения!,
        let collectionView = self.collectionView!
        
        let offset:CGFloat = newBounds.origin.y + collectionView.contentInset.top
        let index = indexForOffset(offset)
  //      self.setFloatingHeaderOffset(offset, forIndex: index)
        

        var invalidatedIndexPaths = [NSIndexPath(forItem: 0, inSection:index)];

        if let floatingSectionIndex = self.floatingSectionIndex {
            if (self.floatingSectionIndex != index){
                
                self.sectionHeadersAttributes[floatingSectionIndex] = super.layoutAttributesForSupplementaryViewOfKind(UICollectionElementKindSectionHeader,atIndexPath: NSIndexPath(forItem: 0, inSection: floatingSectionIndex))
                
                invalidatedIndexPaths.append(NSIndexPath(forItem: 0, inSection:floatingSectionIndex))
            }
        }
        self.floatingSectionIndex = index
        
        context.invalidateSupplementaryElementsOfKind(UICollectionElementKindSectionHeader,atIndexPaths:invalidatedIndexPaths)

        println("invalidationContextForBoundsChange(\(newBounds)) \(invalidatedIndexPaths) contentInset.top = \(collectionView.contentInset.top)")

        
        return context
    }
    
    
    override func prepareLayout() {
        
        let start = CFAbsoluteTimeGetCurrent()

        
        super.prepareLayout()
        println("prepareLayout ...")

        calculateHeaders()

        
//        
//        let offset:CGFloat = collectionView.contentOffset.y + collectionView.contentInset.top
//        let index = indexForOffset(offset)
//        self.setFloatingHeaderOffset(offset, forIndex: index)
//        self.floatingSectionIndex = index
        
        // ПОДУМАТЬ -> тут добавить еще пересчет первого видимого!
        
        
        let stop = CFAbsoluteTimeGetCurrent()
        println("prepareLayout ... done in \(stop - start) sec")
    }
    
}

        return true
    }
    
    
    override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]? {

      
        let attrs = super.layoutAttributesForElementsInRect(rect)
        let ret = attrs?.map() {
            
            (attribute) -> UICollectionViewLayoutAttributes in
