<%
Function Swfup(UpType,DeafultRs,Filelimit)
%>
<style type="text/css">
/*整体框架*/
ul.fileList { margin:8px 0;}
ul.fileList li {width:92px; height:69px; padding:1px; border:1px solid #ccc; margin:0 5px 5px 0; float:left; position:relative;}
ul.fileList li .info_img {width:92px; height:69px;}

/*进度条*/
ul.fileList li .progress {position:absolute; width:90px; height:15px; top:28px; left:1px; border:1px solid #D5D5D5;}
ul.fileList li .progress s {height:15px;display:inline-block;background-color:#ddd;width:0%; text-decoration:none;}
ul.fileList li .progress s span { text-align:center; position:absolute; width:90px; height:15px; font-size:12px;}

/*删除按钮*/
ul.fileList li .delFile {display:block; position:absolute; top:1px; right:1px; width:15px; height:15px;}
ul.fileList li .delFile img {width:15px; height:15px;}

.welcome {}
</style>
<script type="text/javascript" src="swfupload/swfupload.js"></script>
<script type="text/javascript" src="js/jquery.dragsort-0.5.1.min.js"></script>
<script type="text/javascript"> 
var upLoadBox = {
	swfu: null,
	init: function(options) {
		var self = this;
		var upLoadBox = $("div.upLoadBox");
		//初始化swfupland组件
		self.swfu = new SWFUpload(options);
	},
	preLoad: function() {
		if (!this.support.loading) {
			alert("需要安装9.028以上的flashPlayer");
			return false;
		}
	},
	loadFailed: function() {
		function loadFailed() {
			alert("加载失败");
		}
	},
	fileQueued: function(file) {
		try {
			var innerList = $("div.innerBox ul.fileList"),
				welcome = $("p.welcome");
			var fileList = "<li id='" + file.id + "'>";
			fileList += "<a href='#' class='delFile' title=\"删除\"><img src=\"swfupload/close.gif\" /></a>";
			fileList += "<span class='progress'><s><span class='jdNum'>等待上传...</span></s></span>";
			//fileList += "<p class='info'>等待上传...</p>";
			fileList += "</li>";

			//welcome.text("");
			innerList.append($(fileList));

			$("a.delFile").click(function(event) {
				event.preventDefault();
				var p = $(this).parent(),
					fid = p.attr("id");

				upLoadBox.swfu.cancelUpload(fid, false);
				p.remove();
			});

		} catch (ex) {
			this.debug(ex);
		}
	},
	fileQueueError: function(file, errorCode, message) {
		var welcome = $("p.welcome");
		try {
			if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
				alert("你一次上传的文件超过设置");
				return;
			}

			switch (errorCode) {
			case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
				welcome.append("<div>"+file.name+"上传失败，请压缩至1M以内重新上传</div>");
				break;
			case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
				welcome.append("<div>"+file.name+"上传失败，不能上传零字节文件</div>");
				break;
			case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
				welcome.append("<div>"+file.name+"上传失败，无效的文件类型</div>");
				break;
			default:
				if (file !== null) {
					welcome.append("<div>"+file.name+"上传失败，未处理的错误</div>");
				}
				break;
			}
		} catch (ex) {
			this.debug(ex);
		}
	},
	fileDialogComplete: function(numFilesSelected, numFilesQueued) {

		try {
			this.startUpload();
		} catch (ex) {
			this.debug(ex);
		}
	},
	uploadStart: function(file) {
		try {
			var stats = $("#" + file.id).find("p.info");
			stats.html("已上传<s class='yscSize'>0</s>Kb");
		} catch (ex) {}
		return true;
	},
	uploadProgress: function(file, bytesLoaded, bytesTotal) {
		try {
			var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
			var fileList = $("#" + file.id),
				progress = fileList.find(".progress"),
				jdNum = fileList.find(".jdNum"),
				yscSize = fileList.find("s.yscSize");

			progress.find("s").css("width", percent + "%");
			jdNum.html(percent + "%");
			yscSize.text(bytesLoaded);

		} catch (ex) {
			this.debug(ex);
		}
	},
	uploadSuccess: function(file, serverData) {
		try {
			var stats = $("#" + file.id).find(".progress");
			var info_img = $("#" + file.id);
			info_img.prepend("<img src=\"../upload_files/"+serverData+"\" class=\"info_img\" />");
			info_img.append("<input type=\"hidden\" name=\"DefaultPic\" value=\""+serverData+"\" />");
			stats.remove();
			
		} catch (ex) {
			this.debug(ex);
		}
	},
	uploadError: function(file, errorCode, message) {
		try {
			var stats = $("#" + file.id).find("p.info");

			switch (errorCode) {
			case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
				stats.text("上传错误: " + message);
				this.debug("错误提示：http错误，文件名：" + file.name + ", 信息： " + message);
				break;
			case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
				stats.text("上传失败");
				this.debug("错误提示：上传失败，文件名称: " + file.name + ", 文件大小：" + file.size + ", 信息：" + message);
				break;
			case SWFUpload.UPLOAD_ERROR.IO_ERROR:
				stats.text("服务器错误");
				this.debug("错误提示：服务器错误, 文件名称: " + file.name + ", 信息： " + message);
				break;
			case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
				progress.setStatus("安全性错误");
				this.debug("错误提示： 安全性错误, 文件名称: " + file.name + ", 信息： " + message);
				break;
			case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
				progress.setStatus("上传超过限制。");
				this.debug("错误提示：上传超过限制,文件名称:  " + file.name + ", 文件大小： " + file.size + ", 信息：" + message);
				break;
			case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
				progress.setStatus("验证失败。上传跳过。");
				this.debug("错误提示： 验证失败，上传跳过。文件名称: " + file.name + ", 文件大小： " + file.size + ", 信息：" + message);
				break;
			case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
				break;
			case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
				stats.text("停止");
				break;
			default:
				stats.text("未知错误: " + errorCode);
				this.debug("错误提示： " + errorCode + ", 文件名称: " + file.name + ", 文件大小：" + file.size + ", 信息： " + message);
				break;
			}
		} catch (ex) {
			this.debug(ex);
		}
	},
	uploadComplete: function(file) {
		var self = this;
		if (file.filestatus != -5) {
			if (self.getStats().files_queued !== 0) {
				self.startUpload();
			}

		} else {
			self.startUpload();
		}
	}
};

window.onload = function() {
	var settings = {
		flash_url : "swfupload/swfupload.swf",
		upload_url: "inc/up_swf.asp",
		file_post_name : "Filedata",
		file_size_limit :1024,  //文件大小
		file_types : "*.jpg;*.gif;*.png",
		file_types_description : "图片文件",
		file_upload_limit : 0,
		file_queue_limit : 0,
		debug:false,
		
		//按钮设置
		button_image_url: "swfupload/buttonimg.png",
		button_width: "75",
		button_height: "23",
		button_placeholder_id: "spanButtonPlaceHolder",
		button_text: ' ',
		button_text_left_padding: 0,
		button_text_top_padding: 0,
		button_cursor:SWFUpload.CURSOR.HAND, //手形光标
		
		//事件定义
		swfupload_preload_handler : upLoadBox.preLoad,
		swfupload_load_failed_handler : upLoadBox.loadFailed,
		file_queued_handler : upLoadBox.fileQueued,
		file_queue_error_handler : upLoadBox.fileQueueError,
		file_dialog_complete_handler : upLoadBox.fileDialogComplete,
		upload_start_handler : upLoadBox.uploadStart,
		upload_progress_handler : upLoadBox.uploadProgress,
		upload_error_handler : upLoadBox.uploadError,
		upload_success_handler : upLoadBox.uploadSuccess,
		upload_complete_handler : upLoadBox.uploadComplete
		//queue_complete_handler : queueComplete	// Queue plugin event
	};
	upLoadBox.init(settings);   
};

$(function(){
	$(".delFile").click(function(){
	
/*去掉源文件图*/
var lujing=$(this).prev().attr("src");  
/*alert(lujing); */
$.post("/sy/ajax.asp",
    {
      picname:lujing,
      action:"del"
    },
    function(data,status){
      alert("数据：" + data + "\n状态：" + status);
    });

  
$(this).parent().remove();
});
			
	$('.fileList').dragsort({dragSelector: "li",dragSelectorExclude:".delFile", dragEnd: function(){}, dragBetween: true, placeHolderTemplate: "<li></li>" });
});

</script>
<div class='upLoadBox'>
	<span id='spanButtonPlaceHolder'></span>
	<div class='innerBox'>
		<ul class='fileList'><li style="display:none;"></li><%If uptype="edit" And DeafultRs<>"" then
            DefaultPics=Split(DeafultRs,",")
            For i =0 to ubound(DefaultPics)
		%><li id="SWFUpload_0_<%=randomStr(0,4)%>"><img src="../upload_files/<%=DefaultPics(i)%>" class="info_img"><a href="#" onclick="" class="delFile" title="删除"><img src="swfupload/close.gif"></a><input type="hidden" name="DefaultPic" value="<%=DefaultPics(i)%>"><%
            Next
		End If
		%></li></ul>
		<%If Filelimit=1 Then%>
		<p class='welcome' style="clear:both; line-height:20px; background:#FFFAF4; border:1px DASHED #FF6633; padding:2px 5px;">支持多图上传、拖动排序，第一张图片为主图，注意：单个文件不能超过1M</p>
		<%Else%>
		<p class='welcome' style="clear:both; line-height:20px; background:#FFFAF4; border:1px DASHED #FF6633; padding:2px 5px;">支持多图上传、拖动排序，第一张图片为主图，注意：单个文件不能超过1M</p>
		<%End If%>
	</div>
</div>
<%
End Function
%>

<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
