var MenuCategories = {
		tops: null,
		subs: {},
		current: null,
		
		init: function(){
			this.tops = $('.mainnav-item > a');
			var self = this;
			this.tops.each(function(index){
				var top = $(this);
				var id = top.attr('id');
				if (id){
					id = id.replace('top-', '');
					self.subs[id] = $('#sub-'+id).bind({
						mouseover: function(){
							self.showMenu(id);
						},
						mouseout: function(){
							self.hideMenu(id);
						}
					});
					$(this).mouseover(function(){
						self.showMenu(id);
					},this);
					$(this).mouseout(function(){
						self.hideMenu(id);
					},this);
				}
			});
		},
		
		showMenu: function(name){
			if (this.current){
				this.hideMenuContainer(this.current);
			}
			
			if (this.current != name){
				this.subs[name].css('display', 'block');
			}else{
				this.subs[name].css('display', 'block');
			}
			this.current = name;
		},
		
		hideMenu: function(name){
			this.hideMenuContainer(name);
			this.current = null;
		},
		
		hideMenuContainer: function(name){
			this.subs[name].css('display', 'none');
		}
	};

ITc.onReady(MenuCategories.init, MenuCategories);
