(function($) {
	$.fn.dlToggle = function(settings) {
		var opt = $.extend({}, $.fn.dlToggle.options, settings);

		return this.each(function() {
			var $dl = $(this);
			if(!$dl.is('dl')) {return;}
			$dt = $dl.find('dt');
			$dt.css('cursor', 'pointer').each(function(){
				var height,
				$dt = $(this),
				$dd = $dt.next();
				
				if($dd.is('dd')) {
					height = $dd.height();
					$dd.hide().css({height : 0});
				} else { return; }
				
				$dt.click(function(){
					$(this).toggleClass('active');
					if(!$dd.is(':visible')) {
						if(opt.toggleAll) {
							$dl.find('dd:visible').animate({height : 0}, {duration : opt.hideSpeed, easing : opt.hideEasing, complete: function(){
								var $active = $(this)
								$active.prev().toggleClass('active');
								$active.hide();
							}});
						} 
						$dd.show().animate({height : height}, {duration : opt.showSpeed, easing : opt.showEasing});
					} else {
						$dd.animate({height : 0}, {duration : opt.hideSpeed, easing : opt.hideEasing, complete: function(){
							$dd.hide();
						}});
					}
				});
			});
		});
	};

	$.fn.dlToggle.options = {
		showSpeed: 200,
		hideSpeed: 200,
		toggleAll: true
	};
})(jQuery);
