var _id = 'nav';
var _slideEl = 'div';
var _duration = 300;
var _hide = false;

$(document).ready(function() {
	$('#'+_id+' a').click(function () {
		if (_hide) hideLevels(this);
		$(this).next(_slideEl).toggle(_duration);
		$(this).parent().toggleClass('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);
			$(this).removeClass('active');
		}
	});
}
