//	---------------------------------------------------------------------------
//	CLASS:		Menu()
//	AUTHOR:		Ryan J. Salva
//	REVISED:	December 2007
//
//	Creates a drop-down menu for navigation. Also Corrects Windows IE support 
//	for LI:hover and adds an <IFRAME> behind drop-down menus to keep the 
//	menu above <SELECT> elements.
//
//	REQUIREMENTS:
//	Styles found in default.css
//	
//	TESTED IN:
//	Windows: IE 6, Firefox 1, Opera 8
//	Mac: IE 5.2, Firefox 1, Safari 1

var Menu = new Class({
	Implements: Options,
	options: {
		iframe: false,
		onComplete: Class.empty,
		onStart: Class.empty
	},
	initialize: function(el,options){
		this.el = $(el);
		this.setOptions(options);
		
		this.el.getElements('li').each(function(li,index) {
			li.addEvent('mouseenter',function() {
				this.addClass('iehover');
			});
			li.addEvent('mouseleave',function() {
				this.removeClass('iehover');
			});
		});
		if (this.options.iframe) this.addIframe();
	},
	addIframe: function() {
		this.el.getElements('ul').each(function(ul,index) {
			var coord = ul.getCoordinates();
			var iframe = new IFrame({ 				
				src: 'about:blank', 
				styles: { 
					overflow:'hidden',
					border:0,
					width: coord.width,
					height: coord.height,
					left: 0,
					top: 0,
					zIndex: -10,
					opacity: 0
				}
			}); 
			iframe.inject(ul,'top');
			ul.setStyle('z-index',9999);
		});
	}
});

// functions attached to load event
window.addEvent('load',function() {

	// add menu events for IE mouseover compatibility
	var primary = new Menu('Primary',{iframe:false});
	var secondary = new Menu('Secondary',{iframe:false});
	
	
	// make menu options active when the current url matches the href
	$$('#Primary a, #Secondary a').each(function(el,index) {
		if (window.location.href == el.href) el.getParents('li').getLast().addClass('Active');
		//if (window.location.href == el.href) el.getChildren('li ul li').getLast().addClass('Active');
		/*if (window.location.href == el.href){
			var lastli=el.getParents('li').getLast();
			lastli.addClass('Active');
			lastli.'li ul li ul'.addClass('Active');
		}*/
	});

	// add animation to primary navigation
	$$('a.Animate').each(function(el,index) {
		
		if (el.getParent().hasClass('Active')) return false; // no animation for active elements
		el.setStyle('background-position','0px 20px');
		var fx = new Fx.Morph(el, { duration: 250, wait:false });
		el.addEvent('mouseenter',function() {
			fx.start({ 
				'background-position': '0px 40px',
				'color':'#FFFFFF'
			});
		});
		el.addEvent('mouseleave',function() {
			fx.start({ 
				'background-position': '0px 20px',
				'color':'#000000'
			});
		});
	});
});

