var dur = 0.3;
var curmenuid = false;

document.observe("dom:loaded", function() {
	// hide all accordian divs
	$$('.accordian').invoke('hide');
	
	// show a special one depending on page?
	if (document.body.className == "body_category" || document.body.className == "body_franchise") {
		$('acc_categories').show();
		curmenuid = 'acc_categories';
	}
	if (document.body.className == "body_filter") {
		$('acc_investment').show();
		curmenuid = 'acc_investment';
	}
	
	// observe click on categories
	$('acc_categories_link').observe('click', blindFactory('acc_categories'));
	
	// observe click on investment level
	$('acc_investment_link').observe('click', blindFactory('acc_investment'));
});


function blindFactory(id) {
	return function (e) {
		if (curmenuid == id) {
			
			// if we're clicking one that's down, just blind it up
			$(curmenuid).blindUp({ duration: dur });
			curmenuid = false;
			
		} else if (curmenuid) {
			
			// if we're clicking one that's not down, blind up current one first
			$(curmenuid).blindUp({
				duration: dur,
				afterFinish: function () {
					// and after that, blind down the right one
					$(id).blindDown({ duration: dur });
				}
			});
			
			// set this as current
			curmenuid = id;
			
		} else {
			
			// if one's not down, then just blind down the one clicked
			$(id).blindDown({ duration: dur });
			
			// set this as current
			curmenuid = id;
			
		}
		
		// get rid of possible focus fectangle
		e.target.up().blur();
		
		// stop the link being done
		e.stop();
	}
}