function folder(){
	var opts=typeof(arguments[0])!="undefined"?arguments[0]:{};
	opts.folder=typeof(opts.folder)!="undefined"?opts.folder:scope.folder_current;
	//读文件夹
	jQuery.ajax({
		url:"/folder/lists",
	    data:{
	    	folder:opts.folder
	    },
	    dataType: "json",
	    type: "post",
	    timeout: 10000,
	    success: function(data) {
	    	scope.list_folder=data;
	    	scope.$apply();
	    	//读取文件
	    	jQuery.ajax({
	    		url:"/file/lists",
	    	    data:{
	    	    	folder:opts.folder
	    	    },
	    	    dataType: "json",
	    	    type: "post",
	    	    timeout: 10000,
	    	    success: function(data) {
	    	    	scope.list_file=data;
	    			scope.$apply();
	    			//复制下载地址
					try{
						new ClipboardJS('.btn_copy').on('success',function () {
							wd_alert({
				    			msg:"复制成功"
				    		});
						});
						new ClipboardJS('.btn_copy1').on('success',function () {
							wd_alert({
				    			msg:"复制成功"
				    		});
						});
					}catch(e){
					}
	    			//文件右键菜单
	    			jQuery("#list_folder").find('.file').smartMenu([
			    		[{text:"编辑软件",callback:function () {
			    			var the=jQuery(this);
			    			the.closest('tr').find('.btn_file_mod_show,.btn_link_mod_show').click();
			    		}},{text:"删除软件",callback:function () {
			    			var the=jQuery(this);
			    			the.closest('tr').find('.btn_file_del').click();
			    		}},{text:"添加卡密",callback:function () {
			    			var the=jQuery(this);
			    			if (the.closest('tr').find('.btn_card_add_show').length>0) {
			    				the.closest('tr').find('.btn_card_add_show').click();
			    			}else{
			    				wd_alert({
					    			msg:"请先设置价格",
					    			background:"#f00"
					    		});
			    			}
			    		}},{text:"复制链接",callback:function () {
			    			var the=jQuery(this);
			    			the.closest('tr').find('.btn_copy').click();
			    		}},{text:"复制ID",callback:function () {
			    			var the=jQuery(this);
			    			the.closest('tr').find('.btn_copy1').click();
			    		}},{text:"联系我们",callback:function () {
			    			var the=jQuery(this);
			    			window.open('http://www.106pan.com/xag/contact.html');
			    		}},{text:"常见问题",callback:function () {
			    			var the=jQuery(this);
			    			window.open('/v/show/model_id/39/id/11');
			    		}}]
			    	],{
			    		beforeShow: function() {
			        		jQuery.smartMenu.remove();
			        	}
			    	});
	    	    },
	    	    error: function() {
	    	        mui.toast("网络连接超时");
	    	    }
	    	});
	    	jQuery("#list_folder").find('.folder').smartMenu([
	    		[{text:"删除文件夹",callback:function () {
	    			var the=jQuery(this);
	    			the.closest('tr').find('.btn_folder_del').click();
	    		}},{text:"编辑文件夹",callback:function () {
	    			var the=jQuery(this);
	    			the.closest('tr').find('.btn_folder_mod_show').click();
				}},{text:"联系我们",callback:function () {
			    			var the=jQuery(this);
			    			window.open('/xag/contact.html');
			    }},{text:"关于我们",callback:function () {
			    			var the=jQuery(this);
			    			window.open('/xag/bout.html');
				}},{text:"关于文件夹",callback:function () {
			    			var the=jQuery(this);
			    			window.open('/v/show/model_id/39/id/3');
			   	}}]
	    	],{
	    		beforeShow: function() {
	        		jQuery.smartMenu.remove();
	        	}
	    	}); 
	    	if(typeof(opts.callback) == "function") {
				var redata={};
				opts.callback(redata);
			}
	    },
	    error: function() {
	        mui.toast("网络连接超时");
	    }
	});
	
	
}

/*
 * 同步文件夹
 */
try{
	jQuery(document).on('click','.btn_folder_tongbu_show',function () {
		var the=jQuery(this);
		if (userconfig.wangpan_id<2) {
			wd_alert({
    			msg:'您所属网盘为免费用户，请升级后即可使用同步文件夹功能',
    			background:'#f00',
    			width:"370px"
    		});
    		return false;
		}
		jQuery(".folder_tree").load('/folder/tree/top/1');
		jQuery("#modal_folder_tongbu").modal().on('open.modal.amui',function () {
			jQuery("form.folder_tongbu")[0].reset();
		});
	});
	jQuery(document).on('click','.btn_folder_tongbu_submit',function () {
	    var the=jQuery(this);  
	    if (the.html().indexOf('...')!=-1) {
	    	return false;
	    }
	    the.html(the.html()+'...');
	    jQuery.ajax({
			url:"/folder/tongbu",
		    data:the.closest('form').serializeArray(),
		    dataType: "json",
		    type: "post",
		    timeout: 10000,
		    success: function(data) {
		    	if (data.status==1) {
		    		wd_alert({
		    			msg:"同步成功"
		    		});
		    		folder();
		    	}else{
		    		wd_alert({
		    			msg:data.info,
		    			background:'#f00'
		    		});
		    	}
		    	the.html(the.html().replace('...',''));
		    	jQuery("#modal_folder_tongbu").modal('close'); 
		    },
		    error: function() {
		    }
		});          
	});
}catch(e){
	//TODO handle the exception
}

