var _duration = 1;
var _hide = true;

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

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