         
         /* Attached to the top most window (make sure we are using the right orientation) */
         let interfaceOrientation = UIApplication.sharedApplication().statusBarOrientation
+        
+        switch(interfaceOrientation) {
+        case UIInterfaceOrientation.LandscapeLeft:
+            let t: Double = M_PI * 270 / 180
+            self.transform = CGAffineTransformMakeRotation(CGFloat(t))
+            break
             
-        switch(interfaceOrientation) {
-            case UIInterfaceOrientation.LandscapeLeft:
-                let t: Double = M_PI * 270 / 180
-                self.transform = CGAffineTransformMakeRotation(CGFloat(t))
-                break
+        case UIInterfaceOrientation.LandscapeRight:
+            let t: Double = M_PI * 90 / 180
+            self.transform = CGAffineTransformMakeRotation(CGFloat(t))
+            break
             
-            case UIInterfaceOrientation.LandscapeRight:
-                let t: Double = M_PI * 90 / 180
-                self.transform = CGAffineTransformMakeRotation(CGFloat(t))
-                break
-                
-            case UIInterfaceOrientation.PortraitUpsideDown:
-                let t: Double = M_PI * 180 / 180
-                self.transform = CGAffineTransformMakeRotation(CGFloat(t))
-                break
-                
-            default:
-                break
-        }
+        case UIInterfaceOrientation.PortraitUpsideDown:
+            let t: Double = M_PI * 180 / 180
+            self.transform = CGAffineTransformMakeRotation(CGFloat(t))
+            break
             
+        default:
+            break
+        }
+        
         self.frame = CGRectMake(0, 0, self.frame.width, self.frame.size.height)
         UIApplication.sharedApplication().windows.first!.addSubview(self)
         

    private func close() {
        let currentTransform = self.dialogView.layer.transform
        
        let startRotation = (self.valueForKeyPath("layer.transform.rotation.z") as? NSNumber)? as? Double ?? 0.0
        let rotation = CATransform3DMakeRotation((CGFloat)(-startRotation + M_PI * 270 / 180), 0, 0, 0)
        
        self.dialogView.layer.transform = CATransform3DConcat(rotation, CATransform3DMakeScale(1, 1, 1))

        self.cancelButton.addTarget(self, action: "buttonTapped:", forControlEvents: UIControlEvents.TouchUpInside)
        container.addSubview(self.cancelButton)
        
        self.doneButton = UIButton(type: UIButtonType.Custom) as UIButton
        self.doneButton.frame = CGRectMake(
            buttonWidth,
            container.bounds.size.height - kDatePickerDialogDefaultButtonHeight,
