jQuery: The Write Less, Do More JavaScript Library

/*
I'm just posting the code, I would explain it - but someone else may do that
the demo is below - here is the code
*/
jQuery.fn.accordion=function(wrapped_triggers,index,orientation) {
if (typeof(orientation)=='undefined') {
	orientation='bottom';
}
/*
a form with multiple fieldsets and legends will be condensed into one fieldset and legend, the inactive legends becoming buttons
at the bottom of the form, using the buttons, you may toggle which section is active.
wrapped triggers : the jquery object pointing to any set of elements each contained within a containing element
		e.g. <fieldset><legend>title</legend></fieldset><fieldset><legend>title</legend></fieldset>
		applied to: the containing element of the containing elements which containn the final target
		example: To turn all forms in the format "form > fieldset >input" into tabbable forms
		$('form').accordion('fieldset input');
index:		the container that should remain active (open)
*/
	var watashi=this;
	var anata=wrapped_triggers;
	var self=this;
	return self.each(function() {
			var me=this;
			if ($(me).attr('rel')=='accordion') {
				wrapped_triggers.parent().show().end(); //unhide everything
				$('.menu, hr',me).remove(); //remove the buttons we added
			} else {
				//let future calls know that accordion has been called before
				$(me).attr('rel','accordion');
				//cycle through all wrapped_triggers
				$(wrapped_triggers,me).each(function(i) {
						$(this).attr('rel',i);
				});
			}
			//alert($(wrapped_triggers).size());
			var active=wrapped_triggers[index]; //the active legend in the case of a form context
			var targetTag=wrapped_triggers[index].nodeName;  //this is the tag from which we will extract the label for the button
			var inputs=[]; //to hold the buttons
			//now, in the fieldset/legend example
			//out of all the fieldset/legends (the wrapped_triggers) - except for the active one, and for each of those parents,HIDE them - and to
			//each of them   -- create an input derived from searching for 'targetTag' and extracting the text,. append these to the input array
			inputs.push($($.INPUT({Class:'active-tab-bottom-'+orientation,type:'button',value:$(active).text(),disabled:true})).attr('rel',$(active).attr('rel'))[0]);
			$(wrapped_triggers,me).not(active).parent().hide().each(function(i) {
				var yo=this;
				//alert($(targetTag,yo)[0]==active);
				inputs.push(
				$($.INPUT({Class:'tab-bottom-'+orientation,type:'button',value:$(targetTag,yo).text()})).click(function(){
					var idx=$(wrapped_triggers).parent().index(yo);
					$(watashi).accordion(anata,idx,orientation);
				}).attr('rel',$(targetTag,yo).attr('rel'))[0]
				);
			});
			//alert($(inputs[0]).attr('value')+$(inputs[0]).attr('rel'));
			var sorted=[];
			for (j=0;j<inputs.length;j++) {
				sorted[parseInt($(inputs[j]).attr('rel'))]=inputs[j];
			}
			inputs=sorted;
			if (orientation=='bottom') {
				$(me).append("<hr/>");
				$(me).append($.DIV({Class:'menu'},inputs)); //append the new buttons to me
			 } else if (orientation=='top') {
				$(me).prepend("<hr/>");
				$('span.title',watashi).after($.DIV({Class:'menu'},inputs));
				//$($.DIV({Class:'menu'},inputs)).insertAfter();
				//$(me).prepend();
			 }
	});
}
$(document).ready(function() {
	$('form.page').accordion($('fieldset legend'),0,'top')
}

http://www.ctatechs.com/iratik/compact_buttons.html