var vm = avalon.define({
	$id: "myController",
	list_folder_top:[],
	list_folder_current:[],
	list_file:[],
	folder_current:''
});
jQuery(document).ready(function($){ 
    try{
    	folder();
    }catch(e){}
});
jQuery(document).on('click','ul#folder li',function () {
    vm.list_folder_current='';
	vm.list_file='';
	var the=jQuery(this);
	if (the.children('ul').length==0) {
		var str='<ul>';
		vm.folder_current={
			id:the.attr('data-pk4'),
			name:the.attr('data-name'),
			icon:the.attr('data-icon'),
			about:the.attr('title'),
		};
		folder({
			re:the.attr('data-pk4'),
			callback:function (data) {
				for(var i=0;i<data.length;i++){
					str+='<li data-pk4="'+data[i].pk4+'"><img class="folder_icon_close" src="'+static_url+'/static/public/images/folder_close.png?imageMogr2/thumbnail/!16x16r/gravity/center/crop/16x16/interlace/1/quality/80" /><img class="folder_icon_open" src="'+static_url+'/static/public/images/folder_open.png?imageMogr2/thumbnail/!16x16r/gravity/center/crop/16x16/interlace/1/quality/80" />'+data[i].name+'</li>';
				}
			},
			callback1:function (data) {
				for(var i=0;i<data.length;i++){
					str+='<li><img src="'+static_url+'/static/public/images/file/'+data[i].type.replace('/','_')+'.png?imageMogr2/thumbnail/!16x16r/gravity/center/crop/16x16/interlace/1/quality/80">'+data[i].name+'</li>';
				}
				str+='</ul>';
				the.append(str);
				the.children('.folder_icon_open').show();
				the.children('.folder_icon_close').hide();
				the.closest('.top').siblings('.top').find('ul').remove();
				the.closest('.top').siblings('.top').find('.folder_icon_open').hide();
				the.closest('.top').siblings('.top').find('.folder_icon_close').show();
			}
		});  
	}
})
function folder () {
	var opts=arguments[0]?arguments[0]:{};
	var re=typeof(opts.re)!="undefined"?opts.re:'';
	jQuery.ajax({
		url:url_list_folder,
	    data:{
	    	re:re
	    },
	    dataType: "json",
	    type: "get",
	    timeout: 10000,
	    success: function(data) {
	    	if (re=='') {
	    		vm.list_folder_top=data;
	    	}
	    	vm.list_folder_current=data;
	    	if (typeof(opts.callback)!="undefined") {
	    		opts.callback(data);
	    	}
	    },
	    error: function() {
	    }
	});
	
	//文件列表
	if (re!='') {
		jQuery.ajax({
			url:url_list_file,
		    data:{
		    	re:re
		    },
		    dataType: "json",
		    type: "get",
		    timeout: 10000,
		    success: function(data) {
		    	vm.list_file=data;
		    	if (typeof(opts.callback1)!="undefined") {
		    		opts.callback1(data);
		    	}
		    },
		    error: function() {
		    }
		});
	}
	
	
}
avalon.filters.size = function (x) {
    if (x<1048576) {
		x=Math.floor(x/1024)+'KB';
	}else if(x<1073741824){
		x=Math.floor(x/1048576)+'MB';
	}else if(x<1073741824){
		x=Math.floor(x/1099511627776*100)/100+'GB';
	}
	return x;
}