﻿function initSwfUpload(paramValue, flashUrl, uploadUrl) 
{
    var settings = {
				flash_url : flashUrl,
				upload_url: uploadUrl,
				post_params: { "AUTHID": paramValue},
	    		file_size_limit : "20 MB",
				file_types : "*.jpg;*.png;*.gif",
				file_types_description : "Файлы изображений",
				file_upload_limit : 50,
				file_queue_limit : 50,
				button_cursor : SWFUpload.CURSOR.HAND,
				button_width: "120",
				button_height: "29",
				button_placeholder_id: "spanButtonPlaceHolder",
				button_text: '<span class="theFont">Загрузить фото</span>',
				button_text_style: ".theFont { font-family: Verdana; font-size: 12; font-weight: bold; text-decoration: underline;}",				
                file_dialog_start_handler : function() {},
	            file_queued_handler: function(file) {},
	            file_queue_error_handler : function(file, error_code, message) {},
	            file_dialog_complete_handler : onFileDialogComplete,
	            upload_start_handler : onUploadStart,
	            upload_progress_handler : onUploadProgress,
	            upload_error_handler : onUploadError,
	            upload_success_handler : onUploadSuccess,
	            upload_complete_handler : onUploadComplete				
       			};
       			swfu = new SWFUpload(settings);
      }

function onFileDialogComplete(nfilesSelected, nfilesQueued,totalFilesQueued) 
			{
			counter = 0;
			total = 0;
			$("#progress").progressbar();
	        $("#liveProcess").empty();
	        total = totalFilesQueued;
	        this.startUpload();
	        }
function onUploadStart(file) {
                    $("#currentFile").html("<b>" + file.name + "</b>");
                    $("#status").html("Файлов загружено: " + counter + " из " + total);
	                }
function onUploadProgress(file, bytesComplete, totalBytes) {
	                $("#progress").progressbar("value", Math.ceil(100 * bytesComplete / totalBytes));
	                }
function onUploadError(file, error_code, message) {}
function onUploadSuccess(file, server_data, response) {
                    $("#liveProcess").append(server_data);
	                }
function onUploadComplete(file) {
                    counter++;
                    initImageEditForms();              
			        if (counter == total)
			        {
			            $("#status").html("Все файлы успешно загружены.");
			            counter = 0;
			            total = 0;
			        }
			        else
			        {	
			            this.startUpload();	
	                }
			}				


