var _id = 'nav';
var _slideEl = '.sub';
var _duration = 300;
var _hide = true;

jQuery(document).ready(function() {
	jQuery("#nav .sub").each(function() {
		jQuery(this).parent().children("a").click(function(){
			if (_hide) hideLevels(this);
			jQuery(this).parent().children(".sub").animate({"height": "toggle"}, "slow");
			jQuery(this).parent().addClass('active');
			return false;
		});
	});
	
});

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