function jb_upload_attach(event, progressBar){
    var files = event.target;
    var readPhotos = function(o) {

        var input = event.target;

        var reader = new FileReader();
        reader.onload = function() {
            var dataURL = reader.result;

            var container = $('#bf_upload_' + o);
            var output = container.find('img')[0];//container.find('.img_fak')[0];

            if (container.length == 0) return false;

            output.src = dataURL;
	    ///output.style.backgroundImage = 'url('+dataURL+')';
            container.find('.__uploadingInfo').addClass('__off');
            container.find('.uploading_ovr').addClass('__on');
            setTimeout(function() {
                container.find('.uploading_ovr.__on,.pup_bar_m_upload').remove();
                photoAddTextarea(container, o);
            }, 1500);

        };

        reader.readAsDataURL(files[o]);

    }



    var count = 0;
    var totalFiles = files.length;

    var trigger_upForm = function() {

        if (typeof files[count] === 'undefined' || count > files.length - 1) {

            var progressBarTimeout;
            var progressBarRemove = function() {
                progressBarTimeout = setTimeout(function() {
                    progressBar.remove();
                }, 8000);
            }


            progressBar.hover(function() {
                    clearTimeout(progressBarTimeout)
                },
                function() {
                    progressBarRemove();
                });
            edUpload();
            if (!albID)
                photoTabClick("#pphotosTab");
            progressBarRemove();
            return false;
        }

        var formData = new FormData();
        formData.append('files[]', files[count]);
        formData.append('albid', albID);
        $.ajax({
            url: _st.uploadFile, //Server script to process data
            type: 'POST',
            xhr: function() { // Custom XMLHttpRequest
                var Xhr = $.ajaxSettings.xhr();
                if (Xhr.upload) { // Check if upload property exists
                    Xhr.upload.addEventListener('progress', function(e) {

                        mainUploadProgressHandling(e, count, progressBar, count, totalFiles)
                    }, false); // For handling the progress of the upload
                }
                return Xhr;
            },
            //Ajax events
            beforeSend: function() {  readPhotos(count); },
            success: function(data) {
                var response = validateJson(data);

                if (response['status'] === 'OK') {
		    
                    var container = $('#bf_upload_' + count);
		    container.find('img')[0].src = '/getPhoto?p='+response['photoid']+'&sz=thumb&v'+(new Date()).getTime();

                    container.children(':first').attr('data-photoc', response['photoid']);
                    container.find('#restore_recent_upload').attr('href', '/profile?q=' + (response['userid']) + '&cmd=phreturn&i=' + (response['albumid']) + '&phf=' + (response['filename']) + '&ex=' + (response['extension']) + '&fsz=' + (response['filesize']) + '&pos=0&ad=' + response['added']);
                    container.find('#delete_recent_upload').removeAttr('style').attr('href', '/profile?q=' + (response['userid']) + '&cmd=deletephoto&ph=' + response['photoid']);
                    setTimeout(function() {

                        count++;
                        trigger_upForm();
                    }, 50);
                } else return displayErr(data);

            },
            error: function() {
                return displayErr(lang.somethingWrong)
            },
            // Form data
            data: formData,
            //Options to tell jQuery not to process data or worry about content-type.
            cache: false,
            contentType: false,
            processData: false
        });


    }

    trigger_upForm();



}