 
 extension DayHeaderView: DaySelectorDelegate {
   func dateSelectorDidSelectDate(date: NSDate, index: Int) {
+    currentDate = date
     currentWeekdayIndex = index
     swipeLabelView.date = date
     delegate?.dateHeaderDateChanged(date)
-  }
-
-  func beginningOfWeek(date: NSDate) -> NSDate {
-    let components = calendar.components([.Year, .Month, .Day, .TimeZone, .Weekday], fromDate: date)
-    let offset = components.weekday - calendar.firstWeekday
-    components.day = components.day - offset
-
-    return calendar.dateFromComponents(components)!
   }
 }
 

    centerDaySelector.selectedDate = selectedDate
  }

  func selectDate(selectedDate: NSDate) {
    let centerDaySelector = pagingScrollView.reusableViews[1] as! DaySelector
    let startDate = centerDaySelector.startDate.dateOnly()

    let currentWeek = DTTimePeriod(size: .Week, startingAt: startDate)

    if currentWeek.containsDate(selectedDate, interval: .Open) {
      centerDaySelector.selectedDate = selectedDate//.daysFrom(startDate)
    } else if selectedDate.isEarlierThan(currentWeek.StartDate) {
      currentWeekdayIndex = 6
      pagingScrollView.scrollBackward()

    } else if selectedDate.isLaterThan(currentWeek.EndDate) {
      currentWeekdayIndex = 0
      pagingScrollView.scrollForward()
    }
    swipeLabelView.date = selectedDate
  }

  override func layoutSubviews() {


  weak var delegate: DayHeaderViewDelegate?

  var daysInWeek = 7

  var calendar = NSCalendar.autoupdatingCurrentCalendar()

  var currentWeekdayIndex = -1
  var currentDate = NSDate().dateOnly()

  var daySymbolsViewHeight: CGFloat = 20
  var pagingScrollViewHeight: CGFloat = 40
  var swipeLabelViewHeight: CGFloat = 20

  lazy var daySymbolsView: DaySymbolsView = DaySymbolsView(daysInWeek: self.daysInWeek)
  let pagingScrollView = PagingScrollView()
  lazy var swipeLabelView: SwipeLabelView = SwipeLabelView(date: NSDate().dateOnly())

  init(selectedDate: NSDate) {
    self.currentDate = selectedDate
    super.init(frame: CGRect.zero)
    configure()
    configurePages(selectedDate)
