                 }
         })
     }
-    
+
     // MARK: AVCaptureFileOutputRecordingDelegate Delegate Conformance
     func captureOutput(captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAtURL outputFileURL: NSURL!, fromConnections connections: [AnyObject]!, error: NSError!) {
     }
-    
+
     //MARK: Utility Functions
     func deviceWithMediaType(mediaType: NSString, preferringPosition: AVCaptureDevicePosition) -> AVCaptureDevice{
         let devices: NSArray = AVCaptureDevice.devicesWithMediaType(mediaType as String)
         var captureDevice: AVCaptureDevice = devices.firstObject as! AVCaptureDevice
-        
+
         for device in devices{
             if(device.position == preferringPosition){
                 captureDevice = device as! AVCaptureDevice

    @IBOutlet weak var LRuii: UIImageView!
    @IBOutlet weak var badgeBg: UIImageView!
    @IBOutlet weak var badgeCount: UILabel!
    
    @IBAction func flashToggle(sender: UIButton) {
        toggleFlashMode(backCameraDevice!)
    }
    
    @IBAction func cancelSession(sender: AnyObject) {
        resetThumbImages()
        let pathJSON = jsonGen.getFinalJSON(dest: "cancel", save: false)
        setFlashModeToAuto(backCameraDevice!)
        delegate.cameraFinished(self, JSON: pathJSON)
    }
    
    @IBAction func cameraFinishToQueue(sender: UIButton) {
        resetThumbImages()
        let pathJSON = jsonGen.getFinalJSON(dest: "queue", save: true)
        setFlashModeToAuto(backCameraDevice!)
        delegate.cameraFinished(self, JSON: pathJSON)
    }
    
    func resetThumbImages(){
        ULuii.image = UIImage(named:"gray.png")
        URuii.image = UIImage(named:"gray.png")
        LLuii.image = UIImage(named:"gray.png")
        LRuii.image = UIImage(named:"gray.png")
    }
    
    @IBAction func captureImage(sender: UIButton){
        let connection = stillImageOutput?.connectionWithMediaType(AVMediaTypeVideo)
        stillImageOutput?.captureStillImageAsynchronouslyFromConnection(connection, completionHandler:

                    if(backCameraDevice!.isTorchModeSupported(AVCaptureTorchMode.Off)){
                        device.torchMode = AVCaptureTorchMode.Off;
                    }
                    flashState = 2
                }
                else if(flashState == 2){
                    if(backCameraDevice!.isFlashModeSupported(AVCaptureFlashMode.Off)){
                        device.flashMode = AVCaptureFlashMode.Off;
                        let image = UIImage(named: "camera_flash_on.png") as UIImage!
                        flashUIButton.setImage(image, forState: .Normal)
                    }
                    if(backCameraDevice!.isTorchModeSupported(AVCaptureTorchMode.On)){
                        device.torchMode = AVCaptureTorchMode.On;
                    }

                    flashState = 0;
                }
                device.unlockForConfiguration()
            }

        }catch{
            //TODO write error handling code at some point
        }
    }
    
    func generateFileName() -> String {
        let date = NSDate()
