jQuery.fn.collapseDL = function(){
	jQuery.collapseDL(this);
	return this;
}

jQuery.collapseDL = function(el){
	var cdl = this;
	cdl.defaults = {
		accordion : true,
		speed : ''
	}
	el.each(function(){
		var thisDL = this;
		eval("thisOpts={"+this.title+"}");
		thisDL.props = $.extend(cdl.defaults, thisOpts);
		if($(this).is('dl')){
			$('dd',this).hide();
			$('dt',this).css({cursor:'pointer'}).click(function(){
				var thisDT = this;
				$(this).next('dd')
					.filter(':visible').slideUp(thisDL.props.speed,function(){
						// fix height bug
						$(this).height('');
						$('img',thisDT).each(function(){
							this.src = this.src.replace(/_hide/,'_show');
						});
					}).end()
					.filter(':hidden').each(function(){
						// hide the other visible ones if we're in accordion mode
						if(thisDL.props.accordion){
							$('dd:visible',thisDL).prev('dt').click();
						}
						$(this).slideDown(thisDL.props.speed,function(){
							// fix height bug
							$(this).height('');
							$('img',thisDT).each(function(){
								this.src = this.src.replace(/_show/,'_hide');
							});
						});
					});
				return false;
			});
		}
	});
}

// make it happen on DOM load
$(function(){
	$('dl.collapsible').collapseDL();
});