var _duration = 1;
var _hide = true;

$(document).ready(function() {
	$('div.sidebar-nav li:has(ul) > a').each(function(i, link){
		$(link).click(function () {
			if (_hide) hideLevels(this);
			$(this).next('ul').toggle(_duration);
			$(this).parent().toggleClass('active');
			return false;
		});
		if ($(link).parent().hasClass('active')) {
			$(link).next('ul').toggle(_duration);
		}
	});
});

function hideLevels(_this){
	$('div.sidebar-nav li:has(ul)').each(function() {
		var _f = false;
		var _a = $('a', this).each(function(i, _el) {
			if (_el == _this) _f = true;
		});
		if (!_f)  {
			$('ul', this).hide(_duration);
			$(this).removeClass('active');
		}
	});
}
