(function($j){ 
     $j.fn.extend({  
         accordion: function() {       
            return this.each(function() {
				if($j(this).data('accordiated'))
					return false;
				$j.each($j(this).find('ul.accordion, li>div'), function(){
					$j(this).data('accordiated', true);
					$j(this).hide();
				});
				$j.each($j(this).find('a.slide:not(.foo)'), function(){
					$j(this).click(function(e){
						activate(e.target);
						return void(0);
					});
				});
				
				var active = false;
				if(location.hash)
					active = $j(this).find('a[href=' + location.hash + ']')[0];
				else if($j(this).find('li.current'))
					active = $j(this).find('li.current a.slide')[0]; 
				
				if(active){
					activate(active, 'toggle','parents');
					$j(active).parents().show();
				}
				
				function activate(el,effect,parents){
					$j(el)[(parents || 'parent')]('li').toggleClass('active').siblings().removeClass('active').children('ul, div').slideUp('fast');
					$j(el).siblings('ul, div')[(effect || 'slideToggle')]((!effect)?'fast':null);
				}
				
            });
        } 
    }); 
})(jQuery);