var PMCNavigation;

window.addEvent('domready',function(){
	//Detect flash
	PMC.hasFlash = false;
	if (FlashDetect && !(Browser.Engine.gecko==true && Browser.Engine.version==18 && Browser.Platform.mac)){
		PMC.hasFlash = FlashDetect.DetectVersion(9,0,16);										//Determine flash
	}
	if($chk($('flash-navigation-container'))==true){
		PMCNavigation = new PMC.Navigation();
	}
});


PMC.Navigation = new Class({
	settings : {
	},
	initialize : function(){
		if (PMC.hasFlash==true){
			$('flash-navigation-container').setStyle('display','block');
			$('flash-navigation-container').setStyle('overflow','auto');
			
			var tabIndex;
			
			tabs = $('main-navigation-container').getElements('h3');
			tab = $('main-navigation-container').getElement('h3.selected');

			var flashvars = {
				assetPath : "",
				tab : tabs.indexOf(tab)
			};
			
			var params = {
				bgcolor : "#FFFFFF",
				scale : "NOSCALE",
				salign  :  "T",
				allowscriptaccess  :  "always",
				wmode : "transparent"
			};
			
			var attributes = {};

			swfobject.embedSWF("assets/swf/USPSHolidayNavigation.swf", "flash-navigation-object", "675", "100%", "9" , null , flashvars , params , attributes );
		} else {
			var obj;
			$("main-navigation-container").getElements("li.main-nav").each(function(el,index){
				//A NavigationList class is instantiated for each navigation object
				obj = new PMC.Navigation.NavigationList(el,index);
			});
		}
		
		
		
	},
	setHeight : function(height){
		$("flash-navigation-container").setStyles({
			'height':height
		});
	}
});


PMC.Navigation.NavigationList = new Class({
	options : {
	},
	settings : {
		defaultHeight : null,
		transition : {
			duration : 200,
			transition : Fx.Transitions.Quad.easeIn,
			link : 'cancel'
		}
	},
	element : null,
	index : null,
	menuElement : null,
	menuInnerElement : null,
	menuHeight : null,
	FX : null,
	initialize : function(el,index){
		this.element = el;
		this.index = index;
		
		//Set class properties & elements
		this.menuElement = el.getElement("div.menu");
		this.menuInnerElement = this.menuElement.getElement("div.menu-inner");

		//Also calculate height within constructor such that it is calculated once and used as much as necessary
		//	instead of repeatedly calculating height on each mouse interaction
		this.menuHeight = this.menuInnerElement.getSize().y;
		this.settings.defaultHeight = this.menuElement.getSize().y;

		//Add mouse events
		this.setEvents();
	},
	setEvents : function(){
		var _this = this;
		
		//Initialize animation settings
		this.FX = new Fx.Morph(this.menuElement,this.settings.transition);
		
		$("menu-bottom-long").addEvent("mouseenter",function(ev){
			_this.element.getElement("h3").removeClass("over");
			_this.FX.start({
				"height": _this.settings.defaultHeight
			});
		});
		
		//Add mouse events to the li element
		this.element.addEvents({
			'mouseenter':function(ev){
				_this.element.getElement("h3").addClass("over");
				_this.FX.start({
					"height": _this.menuHeight
				});
				var obj = $("package");
				if (PMC.isIE6 && this.id=='menu-srvc' && obj){
					obj.setStyle('visibility','hidden');
				}
			},
			'mouseleave':function(ev){
				_this.element.getElement("h3").removeClass("over");
				_this.FX.start({
					"height": _this.settings.defaultHeight
				});
				var obj = $("package");
				if (PMC.isIE6 && this.id=='menu-srvc' &&  obj){
					obj.setStyle('visibility','visible');
				}
			}
		});
	}
});