var Accordion = {
	active_item: "",
	init: function(options) {
		if (options != undefined) {
			if (options.open_on_init != undefined) {
				var open_on_init = options.open_on_init+"_section";
				var open_on_init_button = "toggle_"+options.open_on_init;
			}
		}
		if (open_on_init == undefined) {
			// Pick the first item to be open by default if none specified
			var open_on_init = jQuery("fieldset div.section_container")[0].id;
			var open_on_init_button = "toggle_"+open_on_init.substring(0,open_on_init.length-8);
		}
		this.active_item = open_on_init;
		jQuery('fieldset div.section_container').each(function() {
			// Now hide the element if it's not the one that's set to be open by default
			if (!open_on_init || this.id != open_on_init) {
				jQuery(this).hide();
			}
		});
		if (open_on_init) {
			jQuery("#"+open_on_init_button).addClass("selected");
		}
		jQuery('.section_toggle').click(function() {
			Accordion.ToggleSection(this);
			return false;
		})
		jQuery('.section_toggle').focus(function() {
			Accordion.ToggleSection(this);
			return false;
		})
	},
	ToggleSection: function(button) {
		var my_id = button.id.substring(7)+"_section";
		var my_display_state = jQuery("#"+my_id).css("display");
		if (my_display_state != "block") {
			jQuery("#"+my_id).slideDown("fast");
			jQuery(button).addClass("selected");
			if (Accordion.active_item != "") {
				jQuery("#"+Accordion.active_item).slideUp("fast");
				var active_bttn = "toggle_"+Accordion.active_item.substring(0,Accordion.active_item.length-8);
				jQuery("#"+active_bttn).removeClass("selected");
			}
			Accordion.active_item = my_id;
		}
	}
}

