var MenuSwitcher = {
		
	visible: undefined,
	fallback: undefined,
	
	Switch: function(id){
		if(this.visible != undefined){
			if($(this.visible) != undefined){
				$(this.visible).hide();
			}
		}
		
		if(this.fallback != undefined){
			$(this.fallback).hide();
		}
		
		if($(id) != undefined){
			this.visible = id;
			$(id).show();
		}
	
	},
	
	Hide: function(){
		if(this.visible != undefined){
			if($(this.visible) != undefined && this.visible != this.fallback){
				$(this.visible).hide();
				if(this.fallback != undefined){
					$(this.fallback).show();
				}
			}
		}
	},
	
	_fallbackSelect: function(id){
		this.fallback = id;
	}
		
}

Event.observe(window, 'load', function(){
	nodes = $('page-navigation').childElements();
	i = 0;
	
	nodes.each(function(item){
		if($(item).firstDescendant().readAttribute('class') == 'selected'){
			MenuSwitcher._fallbackSelect(($(item).firstDescendant().readAttribute('id').replace('mainmenu', 'submenu')));
		};
	});
	
	Event.observe('page-content-container', 'mouseover', function(){
		MenuSwitcher.Hide();
	});
	
	Event.observe('logo', 'mouseover', function(){
		MenuSwitcher.Hide();
	});
	
	Event.observe('search', 'mouseover', function(){
		MenuSwitcher.Hide();
	});
});

