window.addEvent('domready', function() {
	var htmlRequest = new Request.HTML({
		url : "/Tree/dynamicTopNav",
		update : "dynamic_nav",
		onSuccess : function (){
			$$('#main_nav div.dropdown').each(function(el){
				var divHeight = el.getCoordinates().height;
				el.setStyle('bottom','-' + divHeight + 'px');
			});

			$$('#main_nav .drop_nav').each(function(el){
				el.addEvents({
					'mouseenter': function() {
						var dropdown = el.getElement('div.dropdown');
						dropdown.setStyle('visibility','visible');
						dropdown.setStyle('z-index','100');
					},
					'mouseleave': function() {
						var dropdown = el.getElement('div.dropdown');
						dropdown.setStyle('visibility','hidden');
						dropdown.setStyle('z-index','0');
					}
				});
			});
		}
	}).send();


        /* For benefit of JS-impaired mobile browsers, set initial content of input#search_box in domready event rather than via its VALUE attribute */
	$('search_box').value = 'search';
	$('search_box').addEvent('focus', function() {
		this.value = '';
	});

	var headerFadeHolder = $('main_nav_cap');
//	var headerFades = $$(headerFadeHolder.getElements('.nav_cap'));
// explicity state nav_caps to assure correct order
	var headerFades = [$('nav_cap1'), $('nav_cap2'), $('nav_cap3'), $('nav_cap4'), $('nav_cap5'), $('nav_cap6')];
	//create instance of the slider, and start it up
	var headFader = new SL_Slider({
		orientation: 'none',      //vertical, horizontal, or none: None will create a fading in/out transition.
		fade: true,
		slideTimer: 14000,
		transitionTime: 2000,
		container: headerFadeHolder,
		items: headerFades,
		numNavActive: false
	});
	headFader.start();
	$$('#main_nav_cap .nav_cap').setStyle('display','block');
	
	var htmlRequest = new Request.HTML({
		url : "/Tree/dynamicBottomNav",
		update : "bottom_nav",
		data : {mobile_url : mobile_url}
	}).send();
	
	var htmlRequest = new Request.HTML({
		url : "/MainNav/getMainNav",
		update : "quicklinks",
		onSuccess: function(){
			if ($('quicklinks_more')) {
				$('quicklinks_more').addEvent('click', function() {
					if (this.type == 'more')
					{
						this.innerHTML = 'Less <span class="slide_arrow">&#9650;</span>';
						this.type = 'less';
						$('quicklinks_slide').tween('height', 21);
					}
					else
					{
						this.innerHTML = 'More <span class="slide_arrow">&#9660;</span>';
						this.type = 'more';
						$('quicklinks_slide').tween('height', 0);
					}
				});
			}
		}
	}).send();
});

