// JavaScript Document that kickstarts the navigation
window.addEvent('domready', function() {
	
	var list = $$('#primaryNav li:nth-child(first)');
	for (x=0; x<list.length; x++) {
		if (list[x].parentNode.parentNode.nodeName=='DIV') {
			list[x].set('class', 'first-child');	
		}
	}
	
	var list = $$('#secondaryNav li:nth-child(first)');
	for (x=0; x<list.length; x++) {
		list[x].set('class', 'first-child');	
	}
	
	/*Moves the primary navigation in ie to the bottom of the flow*/
	var homepage = true;
	if (Browser.Engine.trident && homepage==true) {
		var nav = new Element('div',{ 'html': $('primaryNav').get('html') });
		$('primaryNav').destroy();
		nav.set('id', 'primaryNav');
		nav.inject(document.body, 'bottom');
	}
	
	var list = $$('#primaryNav li');
	if (Browser.Engine.trident4==true){ //if its ie6 then we need to kickstart the nav!
		for (var i=0; i<list.length; i++) {
			list[i].addEvent('mouseenter', function() {
				this.className = this.className + ' hover';
			});
			list[i].addEvent('mouseleave',function() {
				this.className = this.className.replace('hover','');
			});	
		}
	}
	
	
	/* Controls the secondary Nav */
	/*var secondary = $('secondaryNav');
	var secondaryHeight = secondary.getSize();
	secondary.set('styles', {
		'overflow':'hidden',		  
		'height':'0px',
		'padding-top':'0px',
		'padding-bottom':'0px',
		'margin-bottom':'0px'
	});*/
	
	/*var toggler = $('secondaryNavToggle');
	toggler.addEvent('click', function(event) {
		event.stop();	
		var currentHeight = secondary.getSize();
		if (currentHeight.y == 0) {
			var toggleNav = new Fx.Morph('secondaryNav', {duration:750, transition:Fx.Transitions.Quad.easeInOut, link:'ignore'});
			toggleNav.addEvent('complete', function() {
				toggler.set('styles', { 'background-position' : '200px 0' });									
			});
			toggleNav.start({
				'height' : (secondaryHeight.y-28) + 'px',
				'padding-top' : '14px',
				'padding-bottom' : '14px',
				'margin-bottom' : '14px'			
			});
		} else {
			var toggleNav = new Fx.Morph('secondaryNav', {duration:750, transition:Fx.Transitions.Quad.easeInOut, link:'ignore'});
			toggleNav.addEvent('complete', function() {
				toggler.set('styles', { 'background-position' : '200px -42px' });									
			});
			toggleNav.start({
				'height' : '0px',
				'padding-top' :  '0px',
				'padding-bottom' : '0px',
				'margin-bottom' : '0px'			
			});
		}

	});*/
});
