$(document).ready(function () {
	$(function () {
		var $queue = $('.espcms_uploadPicList');
		var percentages = {};
		var fileUploadOk = 0;
		var fileUploaderr = 0;
		var ratio = window.devicePixelRatio || 1;
		var fileCount = 0, fileSize = 0;
		var InterValObj;
		var curCount = 4;
		var uploader = WebUploader.create({
			swf: uploadSWF,
			server: $('#picker').attr('uploadurl'),
			fileVal: 'upfilename',
			pick: '#picker',
			compress: false,
			chunked: true,
			chunkSize: chunksize,
			accept: {
				title: 'Images',
				extensions: upfile_ext,
				mimeTypes: '*'
			},
			threads: 1,
			fileNumLimit: 100,
			fileSizeLimit: 100 * 1024 * 1024, // 200 M
			fileSingleSizeLimit: upload_max_filesize_byte //100kb
		});
		uploader.on('uploadBeforeSend', function (obj, data, headers) {
			var file = obj.file;
			data.upFileType = 'file';
			data.isWater = 0;
			data.isZoom = 0;
			data.filedir_id = $("#filedir_id").val();
			data.window_mode = $("#window_mode").val();
		});
		uploader.on('fileQueued', function (file) {
			fileCount++;
			fileSize += file.size;
			uploader.upload();
			parent.$('#espcms_header_filecount').empty().append(fileCount);
		});
		uploader.on('uploadProgress', function (file, percentage) {
		});
		uploader.on('startUpload', function () {
			espcms_upfile_add_file();
		});
		uploader.onError = function (code) {
		};
		uploader.on('uploadSuccess', function (file, response) {
			$('#' + file.id).find('p.uploadloading').hide();
			if (response.returnVal == '1') {
				fileUploadOk++;
				parent.$('#espcms_header_fileok').empty().append(fileUploadOk);
			} else {
				fileUploaderr++;
				parent.$('#espcms_header_fileno').empty().append(fileUploaderr);
			}
		});
		uploader.on('uploadError', function (file) {
		});
		uploader.on('uploadFinished', function () {
			InterValObj = window.setInterval(hide_floating_windows, 1000);
			var filedir_id = $('#filedir_id').val();
			dialog_diropen(filedir_id);
		});
		function espcms_upfile_add_file(file) {
			var html_body = '<div class="espcms_floating_form"><div class="float_header_title">上传状态：<span id="espcms_header_filecount">0</span>个文件，<span id="espcms_header_fileok">0</span>个成功，<span id="espcms_header_fileno">0</span>个失败！</div></div>';
			parent.$("body").append(html_body);
			parent.$(".espcms_floating_form").animate({"right": "20px", "bottom": "0px"}, 800);
		}
		function hide_floating_windows() {
			if (curCount == 0) {
				window.clearInterval(InterValObj);
				parent.$('.espcms_floating_form').animate({"right": "20px", "bottom": "-45px"}, 200).remove();
			} else {
				curCount--;
			}
		}
	});
});