//jQuery accordion list
//Daniel Posch
//Gumball Capital
//2008.11
//
//provides an 'accordion' list
//be sure to link the jquery script (of course) and mark list items with the following class:
//.toggler -- any list item or other dom element that can be toggled
//togglers can have some combinations of these additional classes:
//.collapsed -- allows custom styles for any element currently collapsed; also used to mark which elements should be collapsed initially
//.expanded -- opposite of collapsed
//.click -- items toggled by clicking
//.dblclick -- items toggled by double-clicking
//.mouseover -- items toggled on mouseover. automatically implies	 'single':
//.single -- only one item in any given list (taken to be a set of 'toggler' elements that are DOM siblings) can be expanded at a time
//(so mousing over, clicking, or double clicking (depending on the settings above) will toggle the current element and collapse any expanded siblings)
//
//TODO: ajax on-expand loading support; explicit support for outlines/trees
(function($){
	var toggle = function(){ //expand item passed as 'this' and collapse any expanded siblings
		$(this).hasClass("collapsed") ?
			$(this).removeClass("collapsed").addClass("expanded").next().slideDown("fast") :
			$(this).next().slideUp("fast").end().removeClass("expanded").addClass("collapsed");
	};
	var toggleSingle = function(){
		var cur = $(this).parent().children(".expanded"); //currently expanded item in this list
		if(cur.length > 0) //if another item is already open, collapse it first
			cur.next().slideUp("fast").end().removeClass("expanded").addClass("collapsed");
		this.toggle = toggle; //heinous hack
		this.toggle();
	}
	//accordion menu
	$(document).ready(function(){
		//alert("born ready");
		$(".toggler.collapsed").next().hide(); //collapse all items initially marked 'collapsed'
		$(".toggler.dblclick").filter(".single").dblclick(toggleSingle).end().click(toggle);
		$(".toggler.click").filter(".single").click(toggleSingle).end().click(toggle);
		$(".toggler.mouseover").mouseover(toggleSingle); //.filter(".single").mouseover(toggleSingle).end()
	});
})(jQuery);
