var _id = 'side-nav';
var _slideEl = 'ul';
var _duration = 300;
var _hide = true;
var prev = null;

$(document).ready(function() {
  
	$('#'+_id+' a.opener').click(function () {
		if (_hide)
			hideLevels(this);
			
		$(this).next().next(_slideEl).toggle(_duration);

		$(this).parent().siblings().removeClass('active');
		$(this).parent().toggleClass('active');
		
		if(this.parentNode.parentNode.id == "side-nav")
		{
			$('#'+_id+' li ul li').removeClass('active');
		}
	});

});

function hideLevels(_this)
{
	$('#'+_id+' li').each(function()
	{
		var _f = false;
		var _a = $('a', this).each(function(i, _el)
		{
			if (_el == _this) _f = true;
		});
		if (!_f) $(_slideEl, this).hide(_duration)
	});
}