         teaSelection.broadcastSelection(currentSelection)
 
     $scope.start = () ->
-        permission = window.webkitNotifications.checkPermission()
-        if permission != 0
-            window.webkitNotifications.requestPermission($scope.onTimerStart)
-        else
-            $scope.onTimerStart()
+        Notification.checkPermission()
+        $scope.onTimerStart()
 
     $scope.onTimerStart = () ->
         console.log("Starting timer for: " + $scope.time)

        $scope.displayName = $scope.tea.title
        $scope.actualTime = $scope.time
        $scope.timer = true
        if (window.webkitNotifications.checkPermission() != 0)
            $("#notification_disabled").show()
            return

        $('#countdownModal').modal()
        $('#countdownModal').on('hidden', ->



    this.setFromSelection(teaSelection.getSelection())
)

angular.module('tea').service('Notification', ($timeout) ->
    snd = new Audio('snd/alarm.mp3')
    popup = null
    service = {}

    service.supported = () ->
        Notification

    service.checkPermission = () ->
        Notification.requestPermission() unless Notification.permission is "granted"

    service.display = (title, message) ->
        popup = new Notification(title, {
            body: message
            icon: "img/icon.png"
        })
        snd.play() if SOUND

        popup.onclick = () ->
            popup.close()

        popup.onclose = () ->
            snd.pause()

        $timeout(() ->
            #hide notification and stop sound
            cancel()
        , CANCEL_TIMEOUT)

    cancel = () ->
        popup.close() if popup
        snd.pause()


    return service
)

angular.module('tea').controller("RootController", ($scope, Notification) ->
    $scope.notificationSupported = Notification.supported
)

#Utils
