(function($){ 
     $.fn.extend({  
         accordion: function() {    
			hArray = new Array();
            return this.each(function() {
				$(this).find('.heading').each(function(i){
					hArray[i] = $(this).next().height()+20;
				});
				$(this).find('.heading').next().hide().css({height: 0});
				$(this).find('.heading:first').addClass('active').next().css({height: hArray[0]}).show();
				$.each($(this).find('.heading'), function(){
					$(this).click(function(e){
						var ind = $('.heading').index($(this));								
						$(this).addClass('active').siblings().removeClass('active');						
						var $toShow = $(this).next();//.slideDown(700);						
						$toShow.show().animate({ height : hArray[ind]}, { duration: 500 });						
						var $toHide = $(this).siblings(':not(.active)').next('.content');//.slideUp(700);						
						$toHide.animate({ height: 0 }, { duration: 500, complete: function () {
							$toHide.hide();
						}});
						return void(0);
					});
				});							
            });
        } 
    }); 
})(jQuery);
