//	---------------------------------------------------------------------------
//	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});
		
	// make menu options active when the current url matches the href
	$$('#Primary a').each(function(el,index) {
		if (window.location.href == el.href) el.getParents('li').getLast().addClass('Active');
	});
});
