                 snd.play()
             else
                 snd.play volume: 0, loop: false
-                setTimeout (-> snd.stop()), 50
+                setTimeout (-> snd.stop()), 50 #FIX: closure issue?
         return
     @_pauseAll = ->
         snd.pause() for snd in _list

                if @_isEnded
                    #set isEnded to false
                    @_isEnded = false

                    #create audio nodes
                    gainNode = audioContext.createGain()
                    @_source = audioContext.createBufferSource()

                    #set values on source node
                    @_source.buffer = @_buffer
                    @_source.loop = opt.loop ? @_config.loop
                    @_source.onended = =>
                        @_isEnded = true
                        @_elapsedTime += audioContext.currentTime - @_startTime
                        if @_elapsedTime >= @_buffer.duration
                            @_elapsedTime = 0

                    #set value on gain node
                    gainNode.gain.value = opt.volume ? @_config.volume

                    #connect nodes
                    @_source.connect gainNode
                    gainNode.connect audioContext.destination

                    #record start time
                    @_startTime = audioContext.currentTime

                    #start playing
                    @_source.start @_startTime, @_elapsedTime
    restart: (opt = {}) ->
        if Greenhorn.isRunning()
            if @_audio?
                @_audio.currentTime = 0
                @_audio.loop = opt.loop ? @_config.loop
                @_audio.volume = opt.volume ? @_config.volume

###

class Sound
    #closures
    _list = []
    _play = (opt) ->
        #create audio nodes
        gainNode = audioContext.createGain()
        @_source = audioContext.createBufferSource()

        #set values on source node
        @_source.buffer = @_buffer
        @_source.loop = opt.loop ? @_config.loop
        @_source.onended = =>
            @_isEnded = true
            @_elapsedTime += audioContext.currentTime - @_startTime
            if @_elapsedTime >= @_buffer.duration
                @_elapsedTime = 0

        #set value on gain node
        gainNode.gain.value = opt.volume ? @_config.volume

        #connect nodes
        @_source.connect gainNode
        gainNode.connect audioContext.destination

        #record start time
        @_startTime = audioContext.currentTime

        #start playing
        @_source.start @_startTime, @_elapsedTime

    #class level objects
    @config:
