UpStat(500);
try{
var len = data.length;
}catch(e){
var len = 0;
}
var url = decodeURI(window.location.href).replace("%23","#");
var baseurl = url.substr(0,url.lastIndexOf("/")+1);
//面包屑
var tmp_url = url.substr(0,url.lastIndexOf("/"));
var basename = tmp_url.substr(tmp_url.lastIndexOf("/")+1);
var tmp_i = 0;
var url_list=new Array();
var name_list=new Array();
while(tmp_url.lastIndexOf("/")>0){
	tmp_url = tmp_url.substr(0,tmp_url.lastIndexOf("/"));
	if(tmp_url=="http:/")break;
	tmp_name = tmp_url.substr(tmp_url.lastIndexOf("/")+1);
	url_list[tmp_i] = tmp_url;
	name_list[tmp_i] = tmp_name;
	tmp_i++;
}
var url_list_size = url_list.length;
var title_name = window.location.hostname;
var title_host = "";
var crumb_html = "";
if(url_list_size>0){
	title_host = url_list[url_list_size-1];
	$(".btn_back").attr("href",URLencode(url_list[0]+"/"));
	$(".btn_back").show();
	crumb_html = url.replace(title_host,"");
	crumb_html_arr = crumb_html.split("/");
	crumb_html_arr.pop();
	crumb_html_arr.shift();
	crumb_html = crumb_html_arr.join("/ ");
	while(crumb_html.length>30&&crumb_html_arr.length>2){
		crumb_html_arr = crumb_html.split("/");
		var first = crumb_html_arr.shift();
		if(first=="..."){
			crumb_html_arr.shift();
		}
		crumb_html_arr.unshift("...");
		crumb_html = crumb_html_arr.join("/ ");
	}
	crumb_html_arr = crumb_html.split("/");
	crumb_html_arr.unshift("");
	crumb_html = crumb_html_arr.join("/ ");
}else{
	title_host = url.substr(0,url.lastIndexOf("/"));
	crumb_html = "";
}
//获取信息
var passwd = "";
var client_ip = "127.0.0.1";
$.ajax({
	url: title_host+"/res.dynamic/queryinfo/",
	cache:false,
	async:false,
	success: function(data){
		data = $.parseJSON(data);
		passwd = data.passwd;
		title_name = data.pcname;
		client_ip = data.requireip;
	}
});

//头部信息
$("#title_crumb").html('全部文件'+crumb_html);
$("#title_name").html(title_name);
$(".other_pc").attr("href",title_host+"/res.page/queryconnectedlist");
$(".pass_tt").html('"'+title_name+'" 设置了需要密码访问，请输入密码：');
var pass = false;
if(passwd=="" || checkPasswd(getCookie(title_host),passwd)){
	pass = true;
}
if(len>0 && pass){
	$(".no_file").hide();
	$(".content").show();
	//文件列表
	var html = "";
	var html_t = "";
	for(i=0;i<len;i++){
		var filelink = "";
		if(data[i].isdir=="true"){
			filelink = URLencode(baseurl+data[i].filename+"/");
		}else{
			filelink = URLencode(baseurl+data[i].filename);
		}
		var cssType = "icon_file";
		if(data[i].isdir!="true"){
			cssType = getFileCssType(data[i].filename);
		}
		html += '<div class="list_item" _href="'+filelink+'" isdir="'+data[i].isdir+'"><a class="list_main" href="javascript:void(0)"><div class="icon_box '+cssType+'"><img src="/res.static/images/icon.png" alt=""></div>'+
				'<p class="list_tt">'+data[i].filename+'</p>';
		if(data[i].isdir!="true"){
			html += '<p class="list_txt">'+sizeFormat(data[i].filesize)+'</p></a>';
		}
		html += '<div class="tips_box"><p>更新时间：'+data[i].time+'</p><a class="btn_down_in" href="javascript:void(0)"><img alt="" src="/res.static/images/icon_down.png">下载</a></div>';
		if(data[i].isdir!="true"){
			html += '<a class="btn_down" href="javascript:void(0)"><img src="/res.static/images/icon.png" alt="下载"></a>';
		}
		html += '</div>';
	}
	$(".content").html(html);
}else if(!pass){
	$("#title_crumb").hide();
	$(".btn_back").hide();
	$(".no_file").hide();
	$(".set_password").show();
}
$("#btn_passwd").click(function(){
	var in_passwd_raw = $("#input_passwd").val();
	in_passwd = hex_md5(in_passwd_raw).toUpperCase();
	if(checkPasswd(in_passwd,passwd)){
		sentCookie(title_host,in_passwd)
		window.location.reload();
	}else{
		if(in_passwd_raw==""){
			$("#txt_passwd").html("<span></span>请输入密码");
		}else{
			$("#txt_passwd").html("<span></span>密码错误，请重新输入");
		}
		$("#txt_passwd").show();
	}
});

var _list=$('.list_item');
function show(listIndex){
	var _listClick=_list.eq(listIndex);
	if(_listClick.hasClass('item_tips_show')){
		_listClick.animate({height:'48px'},300,function(){
			_listClick.removeClass('item_tips_show');									   
		});
	}else{
		_listClick.addClass('item_tips_show');
		_listClick.animate({height:'196px'},300)
	}
}
function hide_all(){
	var show_item = $('.list_item.item_tips_show');
	show_item.animate({height:'48px'},300,function(){
		show_item.removeClass('item_tips_show');									   
	});
}
$('html').click(function(){
	hide_all();
});
$('.other_pc').click(function(){
	UpStat(901);
});
//点击文件
$('.list_item .list_main').click(function(event){
	var item = $(this).parent();
	if(item.attr("isdir")=="true"){
		xl_OpenFile(item.attr("_href"));
	}else{
		hide_all();
		var listIndex=item.index();
		show(listIndex);
	}
	stopBubble(event);
});
$('.btn_down,.btn_down_in').click(function(){
	var item = $(this).parents(".list_item");
	xl_OpenFile(item.attr("_href"));
});
$('.tips_box').click(function(event){
	stopBubble(event);
});
//打开文件夹
function xl_OpenFile(url){
	if(CheckPathExist(url)=="true"){
		window.location.href=url;
	}else{
		$(".pop_area").show();
	}
}
$(".pop_btn").click(function(){
	window.location.reload();
})
function CheckPathExist(url){
	var path = url.replace(title_host,"");
	var re = "false";
	$.ajax({
		url: title_host+"/res.dynamic/pathexist"+path,
		cache:false,
		async:false,
		timeout:2000,
		success: function(data){
			data = $.parseJSON(data);
			re = data.exist;
        } 
	});
	return re;
}
function LinkUpStat(id,this_a){
	UpStat(id);
	setTimeout(function(){
		document.location.href = this_a.attr("_href");
	},100);
}
function UpStat(id){
	var timestamp = Date.parse(new Date());
	src = "http://stat.download.xunlei.com:8080/?aid=1021&id="+id+"&val1=1&t="+timestamp;
	var up = new Image();
	up.src = src;
}
function URLencode(url){
	return encodeURI(url).replace("#","%23");
}