     
     // MARK: - Reordering
     
+    func reorderTab(tab: TabButton, withEvent event: NSEvent) {
+        var orderedTabs = self.tabButtons()
+        let tabX = NSMinX(tab.frame)
+        let dragPoint = self.tabsView!.convertPoint(event.locationInWindow, fromView: nil)
+
+        var prevPoint = dragPoint
+        var reordered = false
+        
+        let draggingTab = tab.copy() as! TabButton
+        self.addSubview(draggingTab as NSView)
+        tab.hidden = true
+        
+        while(true) {
+            let mask: Int = Int(NSEventMask.LeftMouseUpMask.union(.LeftMouseDraggedMask).rawValue)
+            let event: NSEvent! = self.window?.nextEventMatchingMask(mask , untilDate: NSDate.distantFuture(), inMode: NSEventTrackingRunLoopMode, dequeue: false)!
+            
+            if event.type == NSEventType.LeftMouseUp {
+                NSAnimationContext.currentContext().completionHandler = {
+                    draggingTab.removeFromSuperview()
+                    tab.hidden = false
+                    let items = orderedTabs.map({ return $0.tabButtonCell!.representedObject! })
+                    if reordered == true && self.delegate?.tabsControl?(self, didReorderItems: items) != nil {
+                        
+                    }
+                    self.reloadTabs()
+                }
+                draggingTab.animator().frame = tab.frame
+                break
+            }
+            
+            let nextPoint = self.tabsView!.convertPoint(event.locationInWindow, fromView: nil)
+            let nextX = tabX + (nextPoint.x - dragPoint.x)
+            
+            var r = draggingTab.frame
+            r.origin.x = nextX
+            draggingTab.frame = r
+            
+            let movingLeft = (nextPoint.x < prevPoint.x)
+            prevPoint = nextPoint
+            let index = orderedTabs.indexOf(tab)!
+            
+            if movingLeft == true && NSMidX(draggingTab.frame) < NSMinX(tab.frame) && tab !== orderedTabs.first! {
+                // shift left
+                swap(&orderedTabs[index], &orderedTabs[index-1])
+                reordered = true
+            }
+            else if movingLeft == false && NSMidX(draggingTab.frame) > NSMaxX(tab.frame) && tab != orderedTabs.last! {
+                swap(&orderedTabs[index+1], &orderedTabs[index])
+                reordered = true
+            }
+            
+            if reordered == true {
+                self.layoutTabButtons(orderedTabs, animated: true)
+            }
+        }
+    }
+    
     // MARK: - Selection
     
     func selectTab(sender: AnyObject?) {
         guard let button = sender else {
             return
         }
-        self.selectedButton = button as? NSButton
+        self.selectedButton = button as? TabButton
+        let item: AnyObject! = self.selectedButton?.tabButtonCell?.representedObject
         
         for button in self.tabButtons() {
             button.state = (button === self.selectedButton!) ? NSOnState : NSOffState

    private var addButton: NSButton? = nil
    private var scrollLeftButton: NSButton? = nil
    private var scrollRightButton: NSButton? = nil
    private weak var selectedButton: NSButton? = nil

    private var hideScrollButtons: Bool = true
    private var isHighlighted: Bool = false

    @IBOutlet public weak var dataSource: TabsControlDataSource? {
        didSet { self.reloadTabs() }
    }
    @IBOutlet public weak var delegate: TabsControlDelegate? {
        get { return self.delegateInterceptor.receiver as? TabsControlDelegate }
        set { self.delegateInterceptor.receiver = newValue as? NSObject }
    }
    
    public weak var selectedItem: AnyObject? = nil
    
    public var preferFullWidthTabs: Bool = false
    
    public var minTabWidth: CGFloat =  50.0
    public var maxTabWidth: CGFloat = 150.0
    
//    public override var highlighted: Bool {
//        get { return true }
//    }
    
    public var tabsStyle: TabsControlTabsStyle = .NumbersApp
    public var bordersMask: TabsControlBorderMask = .Top
    public var automaticSideBorderMasks: Bool = true
    
    public var controlBorderColor: NSColor? = NSColor.KPC_defaultControlBorderColor()
    public var controlBackgroundColor: NSColor? = NSColor.KPC_defaultControlBackgroundColor()
    public var controlHighlightedBackgroundColor: NSColor? = NSColor.KPC_defaultControlHighlightedBackgroundColor()
    
    public var tabBorderColor: NSColor? = NSColor.KPC_defaultTabBorderColor() {
        didSet {
//            self.tabButtons.valueForKey("cell") setValue
//            [[[self tabButtons] valueForKey:@"cell"] setValue:tabBorderColor forKey:@"tabBorderColor"];

        }
    }
    public var tabTitleColor: NSColor? = NSColor.KPC_defaultTabBorderColor()
    public var tabBackgroundColor: NSColor? = NSColor.KPC_defaultTabTitleColor()
    public var tabHighlightedBackgroundColor: NSColor? = NSColor.KPC_defaultTabBackgroundColor()
    public var tabSelectedBorderColor: NSColor? = NSColor.KPC_defaultTabHighlightedBackgroundColor()
    public var tabSelectedTitleColor: NSColor? = NSColor.KPC_defaultTabSelectedTitleColor()
    public var tabSelectedBackgroundColor: NSColor? = NSColor.KPC_defaultTabSelectedBackgroundColor()
    
    public required init?(coder: NSCoder) {
        super.init(coder: coder)

        self.stopObservingScrollView()
    }
    
    // MARK: - Public Overrides

    public override func menuForEvent(event: NSEvent) -> NSMenu? {
        return nil
    }
    
    // MARK: - Data Source
    
    public func reloadTabs() {
        guard let dataSource = self.dataSource else {
