site = site || {}; 
site.menu = (function($, undefined) {
	var body;
	var items;
	var more = $('<span class="more">(More)</span>');
	var init = function() {
		$('head').append('<style id="menu-initial" type="text/css">#header ul#main-menu li ul { display:none; }</style>')
	}
	var build = function() {
		body = $('body');
		items = $('#main-menu > li');
		items.each(function() {
			var t = this;
			var el = $(this);
			var ul = el.children('ul');
			var a = el.children('a');
			var m = more.clone();
			if (ul.size() == 1) {
				site.element.hide(ul);
				a.append(m);
				m.bind('click', function(event) {
					closeAll(t);
					site.element.toggle(ul);
					a.addClass('over');
					event.stopPropagation();
					return false;
				});
			} 
		});
		body.bind('click', function() {
			closeAll();
			return true;
		});
		$('#menu-initial').remove();
	};
	var closeAll = function(exclusions) {
		exclusions = $.isArray(exclusions) ? exclusions : [exclusions];
		items = $('#main-menu > li');
		items.each(function() {
			if ($.inArray(this, exclusions) > -1) {
				return true;
			}
			var el = $(this);
			var ul = el.children('ul');
			var a = el.children('a');
			site.element.hide(ul);
			a.removeClass('over');
		});	
	};
	return {
		init: init,
		build: build
	}
}(jQuery));

