
/*only supports nav one level deep. will do dynamic hovers for all first
tier nav nodes, but only show deeper nodes for the selected node*/
var Navigation = {
	default_node:2,
	hover_timer:null,
	re_show_menus:false,
	show_hide_sub_child_items_with_menus:false,
	adjust_menus:function(){
		//moves menu to relevant place on page on page load if you want
		Navigation.hover_node(this.default_node, $('nav_link_'+this.default_node)); 
	},
	adjust_page_padding:function(){
		var padding_offset = 0;
		$$('.nav_sub_child_items').each(function(t){
			if(t.visible()){
				padding_offset += 1;
			}
		});
		//compensate for ie7 making 1st subnav large
		if(BrowserDetect.ie7){
			padding_offset = padding_offset * 22;
			padding_offset = padding_offset + 30;
		}else if(BrowserDetect.safari){
			padding_offset = padding_offset * 20;
		}else{
			padding_offset = padding_offset * 22;
		}
		$('content').style.paddingTop = (padding_offset)+'px';
	},
	hover_home_node:function(o){
		this.clear_and_hide_selected_root(true, -1);
	},
	hover_node:function(id,o){
		if(this.hover_timer != null) clearTimeout(this.hover_timer);
		
		this.clear_and_hide_selected_root(true, id);
		
		//for application link there are no child items
		try{
			var cnd = $('nav_child_items_'+id);
			cnd.show();
			
			o=$(o);
			var xoffset = o.positionedOffset()[0];
			//-3 for shadow
			cnd.style.marginLeft = (xoffset-3)+'px';
			
			$(o).addClassName('nav_selected_root_item');
		}catch(ex){}
	},
	clear_hover_node:function(){
		this.hover_timer = setTimeout(function(){
			this.clear_and_hide_selected_root(false, -1);
		}.bind(this), 1000);
	},
	suspend_clear_timer:function(){
		if(this.hover_timer != null) clearTimeout(this.hover_timer);
	},
	resume_clear_timer:function(){
		this.clear_hover_node();
	},
	clear_and_hide_selected_root:function(force_switch, sel_id){
		
		$$('.nav_child_items').each(function(t){
			t.hide();
		});
		$$('.nav_selected_root_item').each(function(t){
			t.removeClassName('nav_selected_root_item');
		});
		//restore to default menu, not empty. if nothing set this will skip and
		//restore to empty.
		if(!force_switch && this.default_node > 0){
			//for application link there are no child items
			try{
				$('nav_link_'+this.default_node).addClassName('nav_selected_root_item');
				if(this.re_show_menus){
					$('nav_child_items_'+this.default_node).show();
					if(this.show_hide_sub_child_items_with_menus){
						$$('.nav_sub_child_items').each(function(t){t.show();});
					}
				}
			}catch(ex){}
		}else{
			if(this.show_hide_sub_child_items_with_menus){
				if(sel_id == this.default_node){
					$$('.nav_sub_child_items').each(function(t){t.show();});
				}else{
					$$('.nav_sub_child_items').each(function(t){t.hide();});
				}
			}
		}
	}
}






















