         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) .....")
-        
+      
         let attrs = super.layoutAttributesForElementsInRect(rect)
-        
         let ret = attrs?.map() {
             
             (attribute) -> UICollectionViewLayoutAttributes in

            
            if let elementKind = attr.representedElementKind {
                if (elementKind == UICollectionElementKindSectionHeader){
                    return self.sectionHeadersAttributes[attr.indexPath.section]
                }
            }
            
            return attr
        }
        
        println("layoutAttributesForElementsInRect \(rect) ... OK")
        return ret
    }
    
    override func layoutAttributesForSupplementaryViewOfKind(elementKind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes! {
        
        println("2contentInset.top = \(self.collectionView!.contentInset.top)")

        if (elementKind == UICollectionElementKindSectionHeader){
            setOffsetOfFloatingHeader()
            return self.sectionHeadersAttributes[indexPath.section]
        }
        return super.layoutAttributesForSupplementaryViewOfKind(elementKind,atIndexPath:indexPath)
    }
    
    func indexForOffset(offset: CGFloat) -> Int {
        
        let range = NSRange(location:0, length:self.offsets.count)
        return self.offsets.indexOfObject(offset,


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