// JavaScript Document
window.addEvent('domready', function(){
    //list of target elements
	var list = $$('#main-content .module-collapse .module-c');
	//list elements to be clicked on
	var headings = $$('#main-content .module-collapse .module-t');
	//array to store all of the collapsibles
	var collapsibles = new Array();

	headings.each( function(heading, i) {
		//for each element create a slide effect
		heading.setStyle('cursor', 'pointer');
		var collapsible = new Fx.Slide(list[i], {
			duration: 500,
			transition: Fx.Transitions.linear
		});

		//and store it in the array
		collapsibles[i] = collapsible;
		if (Cookie.read('modulecollapse_'+i)) {
			collapsible.hide();
		} else {
			collapsible.show();
		}
		
		var span = heading.getElement('span.toggler-indicator');
		if(span){
			var newHTML = collapsible.open ? '-' : '+';
			span.set('html', newHTML);
		}

		heading.onclick = function(){
			if(span){
				var newHTML = span.get('html') == '+' ? '-' : '+';
				span.set('html', newHTML);
			}
			if (Cookie.read('modulecollapse_'+i)) {
				Cookie.dispose('modulecollapse_'+i);
			} else {
				Cookie.write('modulecollapse_'+i, true, {duration: 1});
			}
			collapsible.toggle();
			return false;
		}
	});
});