
var current_path = "";
var file_count = 0;
var file_pre = 0;
var current_page = 0;
var current_index = 0;
var page_size = 21;

function PageShow()
{
	var page_count = page_size;
	if(current_page == 0) page_count -= file_pre;
	var html = "";
	var idx = 0;
	for(var i=0; i<page_count; i++) {
		idx = current_page * page_size + i;
		if(idx >= file_count) break;
		var finfo = fileNames[idx].split("|");

		html += "<div id=\"panel\">";
		if (fileArray[idx].substr(0,1) != "!")
		{
			html += "<div style=\"width:94px;height:94px;text-align:center;border:solid 1px #CCCCCC;margin-bottom:3px;\" onclick=\"PopupShow(" + idx + ")\">";
			if(fileArray[idx].substr(0,1) == "*") {
				html += "<img src=\"/Utility/FileShow.aspx?file=" + fileArray[idx].substr(1) + "\" width=\"94\" onload=\"imageAutoThumbs2(this)\">";
			}
			else {
				html += "<img src=\"/Utility/Thumbs.aspx?file=" + fileArray[idx].substr(1) + "\" width=\"94\" onload=\"imageAutoThumbs2(this)\">";
			}
			html += "</div>";
		}
		else
		{
			html += "<a href=\"/Utility/FileShow.aspx?file=" + fileArray[idx].substr(1) + "\" target=\"_blank\">";
			html += "<img src=\"/images/folders/" + finfo[1] + "\">";
			html += "</a>";
		}
		html += "<div id=\"filename\">" + finfo[0] + "</div>";
		html += "</div>";
	}
	if(idx < file_count) {
		html += "<div style=\"clear:both;height:40px;padding-top:15px;border:solid 1px #CCCCCC;background-color:#FAFAFF;text-align:center;cursor:pointer;font-size:20px;color:#AAAAAA;\" onclick=\"PageNext(this)\">MORE...</div>";
	}

	document.getElementById("show_panel").innerHTML += html;
}

function PageNext(obj)
{
	obj.style.display = "none";
	current_page++;
	PageShow();
}

function imageAutoThumbs_slide(obj)
{
	if(obj.width > 888) 
	{
		obj.width = 888;
	}
}

function scroll_to(div){
	$('html, body').animate({
	scrollTop: $(div).offset().top - 60
	},1000);
}

var html_back = "";

function PopupShow(idx)
{
	current_index = idx;
	html_back = document.getElementById("show_panel").innerHTML;
	var html = "";
	html += "<div id=\"slide_panel\" style=\"clear:both;border:solid 1px #CCCCCC;background-color:#000000;text-align:center;cursor:pointer;\">";
	html += "<table width=\"100%\" height=\"40\" style=\"background-color:#B4D8FC;\">";
	html += "<tr>";
	html += "<td align=center><div style=\"width:70px;height:50px;background-image:url(/images/help/slide.jpg);background-position:-210px -0px;\" onclick=\"PageRestore()\"></div></td>";
	html += "<td align=center id=\"btn_last_1\"><div style=\"width:70px;height:50px;background-image:url(/images/help/slide.jpg);background-position:-0px -0px;\" onclick=\"ShowLast()\"></div></td>";
	html += "<td align=center id=\"btn_next_1\"><div style=\"width:70px;height:50px;background-image:url(/images/help/slide.jpg);background-position:-70px -0px;\" onclick=\"ShowNext()\"></div></td>";
	html += "<td align=center><div style=\"width:70px;height:50px;background-image:url(/images/help/slide.jpg);background-position:-140px -0px;\" onclick=\"PageDown()\"></div></td>";
	html += "</tr>";
	html += "</table>";
	html += "<img id=\"current_image\" src=\"/Utility/FileShow.aspx?file=" + fileArray[idx].substr(1) + "\" onload=\"imageAutoThumbs_slide(this)\">";
	html += "<table width=\"100%\" height=\"40\" style=\"background-color:#B4D8FC;\">";
	html += "<tr>";
	html += "<td align=center><div style=\"width:70px;height:50px;background-image:url(/images/help/slide.jpg);background-position:-210px -0px;\" onclick=\"PageRestore()\"></div></td>";
	html += "<td align=center id=\"btn_last_2\"><div style=\"width:70px;height:50px;background-image:url(/images/help/slide.jpg);background-position:-0px -0px;\" onclick=\"ShowLast()\"></div></td>";
	html += "<td align=center id=\"btn_next_2\"><div style=\"width:70px;height:50px;background-image:url(/images/help/slide.jpg);background-position:-70px -0px;\" onclick=\"ShowNext()\"></div></td>";
	html += "<td align=center><div style=\"width:70px;height:50px;background-image:url(/images/help/slide.jpg);background-position:-140px -0px;\" onclick=\"PageDown()\"></div></td>";
	html += "</tr>";
	html += "</table>";
	html += "</div>";
	document.getElementById("show_panel").innerHTML = html;

	ShowEcho();

	scroll_to("#slide_panel");
}

function ShowEcho()
{
	if(current_index==0) { $("#btn_last_1").css("display","none"); $("#btn_last_2").css("display","none"); }
	else { $("#btn_last_1").css("display",""); $("#btn_last_2").css("display",""); }

	if(current_index >= (file_count-1)) { $("#btn_next_1").css("display","none"); $("#btn_next_2").css("display","none"); }
	else { $("#btn_next_1").css("display",""); $("#btn_next_2").css("display",""); }
}

function ShowLast()
{
	while(current_index > 0) {
		current_index--;
		if(fileArray[current_index].substr(0,1) != "!") {
			document.getElementById("current_image").src = "/Utility/FileShow.aspx?file=" + fileArray[current_index].substr(1);
			scroll_to("#slide_panel");
			break;
		}
	}
	ShowEcho();
}

function ShowNext()
{
	while(current_index < (file_count-1)) { 
		current_index++;
		if(fileArray[current_index].substr(0,1) != "!") {
			document.getElementById("current_image").src = "/Utility/FileShow.aspx?file=" + fileArray[current_index].substr(1);
			scroll_to("#slide_panel");
			break;
		}
	}
	ShowEcho();
}

function keyUp(e) {
	var currKey=0,e=e||event;
	currKey=e.keyCode||e.which||e.charCode;
	var keyName = String.fromCharCode(currKey);
	if(currKey==37) { ShowLast(); }
	if(currKey==39) { ShowNext(); }
}
document.onkeyup = keyUp;

function PageRestore()
{
	document.getElementById("show_panel").innerHTML = html_back;
	document.getElementById("gotop").style.top = "0px";
}

function PageDown()
{
	window.open("/Utility/FileShow.aspx?file=" + fileArray[current_index].substr(1));
}

function ShowAdd()
{
	var html = "";
	html += "<table cellpadding=0 cellspacing=0 style='border-collapse:collapse;'>";
	html += "<tr>";
	html += "<td style=\"padding-right:3px;\"><input type='text' class='normal_text' id='path' name='path' size=50 value='' onfocus='ActionQuery(this)'></td>";
	html += "<td><div class='sbt' onclick='ActionAdd()'><img src='/images/right.gif'></div></td>";
	html += "<td><div class='sbt' onclick='ActionCancel()'><img src='/images/error.gif'></div></td>";
	html += "</tr>";
	html += "</table>";
	$("#new_path").html(html);

}

function ActionCancel()
{
	$("#new_path").html("<a href=\"javascript:void(0);\" onclick=\"ShowAdd();return false;\">添加易享&trade;文件夹</a>");
}

function ActionAdd()
{
	if($("#path").val().length < 1) { return; }
	$.ajax({
		url: "/Utility/PathPrc.aspx",
	    data : { rnd : Math.random(), path : $("#path").val() },
		type : 'POST',
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			alert(XMLHttpRequest.status);
			alert(XMLHttpRequest.readyState);
			alert(textStatus);
        },
		success : function(result){
			if(result.length > 1) {
				alert(result);
			}
			else {
				window.location.reload();
			}
		}
	});
}

function ActionQuery(obj)
{
	$.ajax({
		url: "/Utility/PathPrc.aspx",
	    data : { rnd : Math.random(), opr : "qry" },
		type : 'POST',
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			alert(XMLHttpRequest.status);
			alert(XMLHttpRequest.readyState);
			alert(textStatus);
        },
		success : function(result){
			if(result.length > 1) {
				var html = "<div style='padding:5px;cursor:pointer;'>系统推荐如下文件夹被分享(点击添加)：</div>";
				var ra = result.split("|");
				for(var vi = 0; vi<ra.length; vi++) {
					if(ra[vi].length > 0) {
						html += "<div style='padding:5px;cursor:pointer;' onclick='ActionAppend(this)'>" + ra[vi] + "</div>";
					}
				}
				DropFloat($('#path')[0],obj,365, 50 + ra.length*42 ,html,'ajax','middle');
			}
		}
	});
}

function ActionAppend(obj)
{
	$("#path").val(obj.innerHTML);
}

