function addHandlers(a, eventName) {
	
	var li = $(a.parentNode.parentNode);
	var wrapper = li.select('.expandedWrapper').first();
	
	Event.observe(a, eventName, function(event) {

		$$('li.expanded').each(function(li) {
			li.removeClassName("expanded");
			li.addClassName("retracted");
		});
		$$('.expandedWrapper').each(function(element) {
			element.hide();
			$(element.parentNode).select('.notexpanded').first().show();
		});

		if (wrapper) {
		
			var span = $(a.parentNode);
			span.hide();
			li.addClassName("expanded");
			li.removeClassName("retracted");
			wrapper.show();
			
			if (event.type == 'focus') {
				wrapper.down('a').focus();
			}
			else {
				event.stop();
			}
			
		}

	});
	
}


document.observe("dom:loaded", function() {

	$$('a.closeCategory').each(function(a) {
		addHandlers(a, 'mouseover');
		addHandlers(a, 'focus');
	});
	
});