if(jQuery) (function($){

	$.extend($.fn, {
		fileTree: function(o, h) {
			if( !o ) var o = {};
			if( o.folderEvent == undefined ) o.folderEvent = 'click';
			if( o.expandSpeed == undefined ) o.expandSpeed= 500;
			if( o.collapseSpeed == undefined ) o.collapseSpeed= 500;
			if( o.expandEasing == undefined ) o.expandEasing = null;
			if( o.collapseEasing == undefined ) o.collapseEasing = null;
			
			$(this).each( function() {
				
				function bindTree(t) {
					$(t).find('LI A').bind(o.folderEvent, function() {
						if( $(this).prev('span').hasClass('directory') ) {
							$(this).parent().children('UL').slideToggle(
									{ duration: o.collapseSpeed, easing: o.collapseEasing }
							);
							if($(this).prev('span').hasClass('expanded')) 
								$(this).prev('span').removeClass('expanded').addClass('collapsed');
							else 
								$(this).prev('span').removeClass('collapsed').addClass('expanded');
						}
						//return h($(this).attr('rel'));
					});
					$(t).find('LI SPAN').bind(o.folderEvent, function() {
						if( $(this).hasClass('directory') ) {
							$(this).parent().children('UL').slideToggle(
									{ duration: o.collapseSpeed, easing: o.collapseEasing }
							);
							if($(this).hasClass('expanded')) 
								$(this).removeClass('expanded').addClass('collapsed');
							else 
								$(this).removeClass('collapsed').addClass('expanded');
						}
					});
					// Prevent A from triggering the # on non-click events
					if( o.folderEvent.toLowerCase != 'click' ) $(t).find('LI A').bind('click', function() { return true; });
				}
				bindTree($(this));
			});
		}
	});
	
})(jQuery);
