var accord = null;
var fps = 50;

window.addEvent('domready', function() {
	$$("div.bodyBlock div.p").forEach(function(p) {
		p.setStyles({ display: "block", visibility: "visible" });
	});

	accord = new Accordion("div.bodyBlock h4", "div.bodyBlock div.p", 
								{ 	opacity: false,
									display: null, // => none open at startup
									fps: fps,
									onActive: function (toggler, element) {
												new Fx.Style(element, "marginBottom", { fps: fps }).start("20px");
											},
									onBackground: function (toggler, element) {
												new Fx.Style(element, "marginBottom", { fps: fps }).start("0px");
											}
								});
});

function accordOpenAll() {
	$$("div.bodyBlock div.p").each(function(p) {
		new Fx.Styles(p, { fps: fps }).start( { "height": p.scrollHeight, "marginBottom": 20 } );
	});
	accord.previous = null; // so we can click on any toggler (ie <h4>) to close all but this toggler when all are open
}

function accordCloseAll() {
	if (accord.previous === null) // to handle the closeall-openall-closeall events chain
		accord.previous = 1;      //  so the last closeall does something
	accord.display(null); // force close of all elements
}

