window.addEvent('domready', function(){
	var handles = [];
	var panes = [];
	var index = -1;
	var backupIndex = -1;
	$$('.news-item').each(function(el, i) {
		handles.push(el.getElement('h2'));
		panes.push(el.getElement('.body'));
		if (backupIndex == -1 && !el.hasClass('closed')) {
			backupIndex = handles.length - 1;
		}
		if (index == -1 && window.location.hash && el.id && window.location.hash=='#'+el.id) {
			index = handles.length-1;
		}
	});
	$$('fieldset.expando').each(function(el, i) {
		handles.push(el.getElement('legend'));
		panes.push(el.getElement('.body'));
		if (index == -1 && window.location.hash && el.id && window.location.hash=='#'+el.id) {
			index = handles.length-1;
		}
		if (index == -1 && el.hasClass('has-errors')) {
			index = handles.length-1;
		}
		if ((backupIndex == -1) && !(el.hasClass('closed'))) {
			backupIndex = handles.length - 1;
		}
	});
	handles.each(function(handle, i) {
		handle.setStyle('cursor', 'pointer');
		handle.addEvent('mouseover', function() {
			handle.tween('color', '#2C840F', '#FF9900');
		});
		handle.addEvent('mouseout', function() {
			handle.tween('color', '#FF9900', '#2C840F');
		});
	});
	if (index == -1) {
		index = backupIndex;
	}
	if (index == -1) {
		index = null;
	}
	new Accordion(handles, panes, { show: index, alwaysHide: true });
});