 pendingFiles = []
 updateQueue = ->
     files = pendingFiles.splice(0, 5)
+    urls = pendingUrls.splice(0, 5)
     fileList = document.getElementById('files')
     scrollingContainer = document.getElementById('droparea')
     for file in files

            toUpload.push(file)
    for file in toUpload
        ((file) ->
            reader = new FileReader()
            reader.onloadend = (e) ->
                try
                    data = e.target.result
                    file.updateStatus('preparing')
                    worker.postMessage({ action: 'compute-hash', data: data, callback: 'hashCompleted', id: file.hash })
                catch e # Too large
                    uploadFile(file)
            reader.readAsBinaryString(file.file)
        )(file)

hashCompleted = (id, result) ->

                        setTimeout(check, 100)
                check()

pendingUrls = []
uploadUrls = (urls) ->
    if albumAttached
        albumUI.querySelector('.button').classList.add('hidden')
        albumUI.querySelector('.status').classList.remove('hidden')
        albumUI.querySelector('.status').textContent = 'Processing, please wait...'
        albumUI.querySelector('.result').classList.add('hidden')
    if Object.keys(uploadedFiles).length == 0
        document.getElementById('files').innerHTML = ''
        dropArea = document.getElementById('droparea')
        dropArea.style.overflowY = 'scroll'
        dropArea.classList.add('files')
        fileList = document.getElementById('files')
    pendingUrls.push(url) for url in urls
    updateQueue()

uploadUrlFile = (file) ->
    oldHash = file.hash
    API.uploadUrl(file, (result) ->
        uploadedFiles[file.hash] = file
        if result.error?
            file.setError(result.error)
            return
        file = result.file
        delete uploadedFiles[oldHash]
        uploadedFiles[file.hash] = file
        if file.status == 'done'
            finish(file)
        else
            file.isUserOwned = true
            worker.postMessage({ action: 'monitor-status', hash: file.hash })
    )

