var expand = function()
{
	this.className = 'selected';
	var u = this.parentNode.parentNode.getElements('ul')[0];
	u.set('morph', {
		duration: 1000,
		transition: Fx.Transitions.Bounce.easeOut,
		link: 'chain'
	});
	u.morph({'height' : [0, u.origheight]});
	this.removeEvent('click', expand);
	this.addEvent('click', collapse);
	$each($('nav-left').childNodes, function(child) {
		if (!(child.tagName && child.tagName.toUpperCase() == 'LI')) {
			return;
		}
		child.className = '';
		var ou = child.getElements('ul')[0];
		if (ou.offsetHeight && ou != u) {
			ou.morph({'height' : [ou.offsetHeight > 4 ? ou.offsetHeight : 0, 0]});
			child.getElements('a')[0].removeEvent('click', collapse);
			child.getElements('a')[0].addEvent('click', expand);
		}
	});
	return false;
}

var collapse = function()
{
	this.className = '';
	var u = this.parentNode.parentNode.getElements('ul')[0];
	u.set('morph', {
		duration: 1000,
		transition: Fx.Transitions.Bounce.easeOut,
		link: 'chain'
	});
	u.morph({'height' : [u.origheight, 0]});
	this.removeEvent('click', collapse);
	this.addEvent('click', expand);
	return false;
}

window.addEvent('load', function() {
	$each($('nav-left').childNodes, function(child) {
		if (!(child.tagName && child.tagName.toUpperCase() == 'LI')) {
			return;
		}
		var u = $(child).getElement('UL');
		u.set('morph', {
			duration: 1000,
			transition: Fx.Transitions.Bounce.easeOut,
			link: 'chain'
		});
		u.origheight = u.offsetHeight;
		if ($(child).hasClass('selected')) {
			child.getElements('a')[0].addEvent('click', collapse);
			return;
		}
		$(child).className = '';
		u.style.height = 0;
		child.getElements('a')[0].addEvent('click', expand);
	});
});
