var newAccordion;

var CodepuzzleAccordion = {
	title: '',
	init: function() {
		newAccordion = new accordion('accordion_container', {
			// The speed of the accordion
			//resizeSpeed : 1,
			// The classnames to look for
			classNames : {
				// The standard class for the title bar
			    toggle : 'accordion_toggle',
			    // The class used for the active state of the title bar
			    toggleActive : 'accordion_toggle_active',
			    // The class used to find the content
			    content : 'accordion_content'
			},
			// If you don't want the accordion to stretch to fit 
			// its content, set a value here, handy for horizontal examples.
			defaultSize : {
			    height : null,
			    width : null
			},
			// The direction of the accordion
			//direction : 'vertical', //'horizontal'
			// Should the accordion activate on click or say on mouseover? (apple.com)
			onEvent : 'click'
		});
	},
	open: function() {
		newAccordion.activate($$('#accordion_container .accordion_toggle')[0]);
		var accordions = $$('.accordion_toggle');
		accordions.each(function(accordion) {
		    $(accordion.next(0)).setStyle({ height: '0px', width: '400px' });
		});
	},
	reorder: function() {
		var serializedOrder = Sortable.serialize("accordion_container");
		new Ajax.Request('accordioncms.php?' + serializedOrder, {
			method: 'post',
			parameters: {
				'p': CodepuzzleAccordion.title,
				'action': 'reorder'
			},
			onSuccess: function(transport) {
				if (!transport.responseJSON.success) {
					alert("Fehler beim Speichern der Änderungen!\r\n\tLade Seite neu.");
					window.location.reload();
				}
			}
		});
	},
	initCMS: function(pageTitle) {
		this.title = pageTitle;
		Sortable.create("accordion_container", {
			constraint: false,
			onUpdate: CodepuzzleAccordion.reorder
		});
	}
}
//Event.observe(window, 'load', CodepuzzleAccordion.init, false);
//Event.observe(window, 'load', CodepuzzleAccordion.open, false);
