
	$(document).ready(function(){

		$('#tree .fold').disableSelection();			
		$('#tree li').disableSelection();			

		$('#tree .fold').live('click',function(){
			if ($(this).parent().parent().hasClass('closed')) {
				$(this).html('-');			
				$(this).parent().parent().removeClass('closed');			
			}
			else {
				$(this).html('+');
				$(this).parent().parent().addClass('closed');			
			}
			return false;
		});		

		$('#tree li > a').click(function(event) {

			$('#tree .selected').removeClass('selected');
			$(this).addClass('selected');
			
			var folderId = $(this).children('input').val();
			//alert(folderId);
			getFileList(folderId, 'customerFiles');
			getFileList(folderId, 'agentFiles');			

		});

		getFileList(0, 'customerFiles');

	});
	
	function getFileList(folderId, target) {

		$.ajax({ 
			type: 'GET', 
		    url: 'ajax/ajaxTree.php?cmd=fileList&folderId='+ folderId +'&target='+ target, 
			cache: false,								
		    success: function(data) { 	

				$('#'+ target).html(data);
				
			}		
		});
			
	}	
