jQuery(document).ready(function($) {
	var visible = null;

	$.each(['concepts', 'projects'], function() {
		var that = this, navEl = $('#nav-'+this+' a'), subEl = $('#submenu-'+this);

		this.open = function() {
			if(visible != null) {
				// need to hide expanded submenu
				visible.close("slow", function(){
					navEl.addClass("active");
					subEl.slideDown("slow");
					visible = that;
				});
			} else {
				navEl.addClass("active");
				subEl.slideDown("slow");
				visible = that;
			}
		};
		this.close = function(speed, callback) {
			visible = null;
			subEl.slideUp(speed, function(){
				navEl.removeClass("active");
				if(typeof(callback) != 'undefined'){
					callback();
				}
			});
		};
		navEl.click(function (event) {
			event.preventDefault();
			if (subEl.is(":hidden")) {
				that.open();
			} else {
				that.close('slow');
			}
		});
	});

});

