// JavaScript Document
(function($) { 
     $.fn.extend({  
         accordion : function() {       
            return this.each(function() {
									  
				if ($(this).data('enabled')) {
					return false;
				}
					
				$.each($(this).find('ul.accordion, li div'), function() {
					$(this).data('enabled', true);
					$(this).hide();
				});
				
				$.each($(this).find('a:not(.foo)'), function() {
					$(this).click(function(e) {
						activate(e.target);
						return void(0);
					});
				});
				
				$('ul.accordion li div a:not(.foo)').click(function() {
					var tab = $(this).attr("href");
					activateOuter(tab);
					return void(0);
				});
				
				
				
				/**
				This just opens up any slide based on the
				hash value.
				*/
				var active = false;
				
				if (location.hash) {
					active = $(this).find('a[href=' + location.hash + ']');
				}
				/** 
				If no hash and li is class current,
				then this opens the li on page load.
				*/
				else if ($(this).find('ul.accordion li.current')) {
					active = $(this).find('ul.accordion li.current a');
				}
				
				if (active) {
					activate(active, 'toggle','parents');
					$(active).parents().show();
				}
				
				function activate(el,effect,parents) {
					$(el)[(parents || 'parent')]('li, div').toggleClass('active');
					$(el).siblings('ul, div')[(effect || 'slideToggle')]((!effect)?'fast':null);
				}
				
				function activateOuter(tab) {
					var slide = $('.accordion a[href*=' + tab + ']');	
					$(slide).parents('.accordion li').addClass('active');
					$(slide).siblings('div, ul').show("fast");
					
					var str = tab;
					//alert(str.substring(1));
					var anchored = $('.accordion a[name*=' + str.substring(1) + ']');
					$(anchored).parents('span, div').parents('.accordion li').addClass('active');
					$(anchored).parents('div, ul').show("fast");
				}
        	});
        } 
    }); 
})(jQuery);