 //
 
 import UIKit
+import QuartzCore
 
 var KVOContext = ""
 

    
    func startAnimating() {
        
        label.alpha = 0
        var scrollView = superview as UIScrollView
        var insets = scrollView.contentInset
        

                var scrollView = object as? UIScrollView
                if (scrollView != nil) {
                    println(scrollView?.contentOffset.y)
                    
                    // this should be done with tuples
                    /*
                    let state = (previousOffset, scrollView?.dragging, loading)
                    switch state {
                    
                    case (let offset, false, false) where offset < -pullToRefreshDefaultHeight:
                        println()
                    }
                    */
                    if (previousOffset < -pullToRefreshDefaultHeight) {
                        if (scrollView?.dragging == false && loading == false) {
                            loading = true
                        } else if (loading == true) {
                            label.text = "loading ..."
                        } else {
                            label.text = "release to refresh"
                            self.shapeLayer.strokeEnd = -previousOffset / pullToRefreshDefaultHeight
                        }
                    } else if (loading == true) {
                        label.text = "loading ..."
                    } else if (previousOffset < 0) {
                        label.text = "pull to refresh"
                        self.shapeLayer.strokeEnd = -previousOffset / pullToRefreshDefaultHeight
                    }
                    previousOffset = scrollView!.contentOffset.y
                }
