if(typeof(jQuery)!=='undefined'&&window.jQuery){
	(function($){
		$.fn.cfwiTreeMenu = function(params){
			
			var Settings={
				'ToggleSpeed':200,
				'CssClass':{
					'Init':'init',
					'Collapsed':'collapsed',
					'Expanded':'expanded',
					'FirstChild':'first-child',
					'LastChild':'last-child'
				}
			}
			
			return this.each(function(){
				var $menu=$(this);
				if(typeof(params)==='object'&&params!==null){
					$.extend(true,settings,params);
				}
				$menu
					.addClass(Settings.CssClass.Init)
					.find('li:has("> ul")')
						.addClass(Settings.CssClass.Collapsed)
						.find('a.expand-collapse')
							.click(function(e){
								var $a=jQuery(this),$li=$a.parent();
								if($a.siblings('ul').length > 0){
									$li.toggleClass(Settings.CssClass.Collapsed + ' ' + Settings.CssClass.Expanded)
										.find('> ul')
										.slideToggle(Settings.ToggleSpeed);
									if(typeof(e)!=='undefined'&&e!==null){
										if(e.preventDefault){e.preventDefault();}
										if(e.returnValue){e.returnValue=false;}
										return false;
									}
								}
							})
						.end()
						.find('a.no-children')
							.click(function(e){
								if(typeof(e)!=='undefined'&&e!==null){
									if(e.preventDefault){e.preventDefault();}
									if(e.returnValue){e.returnValue=false;}
									return false;
								}
							})
						.end()
						.not('.current')
							.find('ul')
								.slideToggle(5)
							.end()
						.end()
					.end()
					.find('li:first-child')
						.addClass(Settings.CssClass.FirstChild)
					.end()
					.find('li:last-child')
						.addClass(Settings.CssClass.LastChild)
					.end()
					.find('.current.collapsed')
					.toggleClass(Settings.CssClass.Collapsed + ' ' + Settings.CssClass.Expanded)
					.end()
					.removeClass(Settings.CssClass.Init);
			});
			
		}
	})(jQuery);
}
