var vm = avalon.define({
	$id: "myController",
	list_folder_top:[],
	list_folder_current:[],
	list_file:[],
	win_height:0,
	rows:0,
	folder_current:''
});
jQuery(document).ready(function($){ 
    try{
    	win_height=jQuery("#desktop").height()-20;
    	rows=Math.floor(win_height/110);
    	folder();
    }catch(e){}
});
//双击顶级目录
jQuery("a.icon").live('dblclick',function(){
	vm.list_folder_current='';
	vm.list_file='';
	var the=jQuery(this);
	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')
	});
});
//双击子目录
jQuery("tr.folder").live('dblclick',function(){
	vm.list_folder_current='';
	vm.list_file='';
	var the=jQuery(this);
	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')
	});
});
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;
	    	}else{
	    		vm.list_folder_current=data;
	    	}
	   		vm.win_height=win_height;
	   		vm.rows=rows;
	    },
	    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;
		    },
		    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;
}