// Based on Son of Suckerfish.
// http://htmldog.com/articles/suckerfish/dropdowns/
// Requires MooTools goodness!
// Used to add a class to the parent LI tag of an A link
 function suckerfishNavMenu(pSetDefault) {
	
	var sfEls = $('main-nav').getElements('#nav > li');
	
	if(pSetDefault != ''){
		// highlight a given element
		var el = $('nav').getElement('li.' + pSetDefault);
		if ($defined(el)){
			el.addClass('active');
		}
		//check if element has grandparent LI
		var theParent = el.getParent('ul');
		var theGrandParent = theParent.getParent('li');
		if ($defined(theGrandParent)){
			//highlight grandparent LI
			theGrandParent.addClass('active');
		}
	}
	
	
	for (var i=0; i<sfEls.length; i++) {
		
		sfEls[i].addEvent('mouseover',function() {
			//switch off previous hover state	
			//this uses getElements, since there seems to be times when more than one LI has the class!
			var els = $('main-nav').getElements('li.sfhover');
			//ie7 hack
			if(Browser.Engine.trident && Browser.Engine.version==5) els = $('main-nav').getElements('li');
			
				els.each(function(item, index){
										item.removeClass('sfhover');
										//alert(item.hasClass('sfhover'));
								});
			
			this.addClass('sfhover');
			
			
		});
		
		sfEls[i].addEvent('mouseleave',function() {
			//switch off previous hover state	
			//this uses getElements, since there seems to be times when more than one LI has the class!
			var els = $('main-nav').getElements('li.sfhover');
			//ie7 hack
			if(Browser.Engine.trident && Browser.Engine.version==5) els = $('main-nav').getElements('li');
			els.each(function(item, index){
									//item.addClass('sfhover');
									item.removeClass('sfhover');
			});
			
			
		});
		
		sfEls[i].addEvent('click',function() {
			//switch off previous hover state	
			//this uses getElements, since there seems to be times when more than one LI has the class!
			var els = $('main-nav').getElements('li.sfhover');
			//ie7 hack
			if(Browser.Engine.trident && Browser.Engine.version==5) els = $('main-nav').getElements('li');
			els.each(function(item, index){
								//item.addClass('sfhover');
								item.removeClass('sfhover');
			});
			
			
		});
		
		
		//sfEls[i].onclick=sfEls[i].onmouseout;
		
	}
	
	// hack for menu bug
	if(Browser.Engine.trident && Browser.Engine.version==5){
				// if IE7 
		var allLinks = $('main-nav').getElements('a');
		
		allLinks.each(function(item){
				//alert(item.getProperty('href'));									 
					if(item.getProperty('href').substr(0,7) == 'http://') {
							//if abs. url
							item.addEvent('click',function() { window.location = window.location.href;} );
					}
				});
		//alert(Browser.Engine.version);
				//this.getProperty('href').substr(0,7) == 'http://'; 
				
				
				//if(childLink.getProperty('href').substr(0,7) == 'http://') window.location.reload();
	}
	
	
}


