     var sectionHeadersAttributes:Array<UICollectionViewLayoutAttributes!> = []
     let offsets = NSMutableOrderedSet()
     var floatingSectionIndex:Int! = nil
+    var previousWidth:CGFloat! = nil
     
     override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool {
         return true
     }
     
+    func calculateHeaders(){
+        self.sectionHeadersAttributes.removeAll(keepCapacity: true)
+        self.offsets.removeAllObjects()
+        
+        let collectionView = self.collectionView!
+        
+        let numberOfSections = collectionView.numberOfSections()
+        for var section = 0; section < numberOfSections; ++section {
+            
+            let attr =  super.layoutAttributesForSupplementaryViewOfKind(UICollectionElementKindSectionHeader,atIndexPath:NSIndexPath(forItem: 0, inSection: section))
+            self.sectionHeadersAttributes.append(attr)
+            
+            if (section > 0){
+                self.offsets.addObject(attr.frame.origin.y)
+            }
+        }
+        
+
+    }
+    
+    func setOffsetOfFloatingHeader(){
+        let collectionView = self.collectionView!
+        let offset:CGFloat = collectionView.contentOffset.y + collectionView.contentInset.top
+        let index = indexForOffset(offset)
+        self.setFloatingHeaderOffset(offset, forIndex: index)
+    }
+    
     override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]? {
+
+        println("layoutAttributesForElementsInRect \(rect) ... ")
+        println("1contentInset.top = \(self.collectionView!.contentInset.top) .....")
+        
+        setOffsetOfFloatingHeader()
 
         let attrs = super.layoutAttributesForElementsInRect(rect)
         
-        return attrs?.map() {
+        let ret = attrs?.map() {
             
             (attribute) -> UICollectionViewLayoutAttributes in
             

            
            return attr
        }
    }
    
    override func layoutAttributesForSupplementaryViewOfKind(elementKind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes! {
        
        if (elementKind == UICollectionElementKindSectionHeader){
            return self.sectionHeadersAttributes[indexPath.section]
        }
        return super.layoutAttributesForSupplementaryViewOfKind(elementKind,atIndexPath:indexPath)


        
        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")
    }
    
}
