/* Avs Menu System */

$(document).ready(function() {
	
	// Menu Container Setting
	var menuSpeed = 250;
	var menuAnimation = "slide";
	
	//Menu Item Settings
	var menuItemBGDefault = "#ffffff";
	var menuItemBGHover = "#dddddd";
	
	var menuItemBorderDefault = "#ffffff";
	var menuItemBorderHover = "#aaaaaa";
	
	// Menu Container Hovers
	
	// The fade in and out - Needs to be slightly slower otherwise looks jerky and unprofessional
	if(menuAnimation == "fade") {
			// Assign hover funnctions to each element
			$('.MenuItemHover').hover(function() {
				// Reset the opacity of the menus incase to overcome animation not finishing bug
			   $("#" + this.id + " > .MenuSubCont").css("opacity","1");
			   $("#" + this.id + " > .MenuSubCont").css("MozOpacity","1");
			   $("#" + this.id + " > .MenuSubCont").css("filter","alpha(opacity=100");
				
				$("#" + this.id + " > .MenuSubCont").fadeIn({queue:false, duration: menuSpeed}); // FADE IN!
			},
			function () {
				$("#" + this.id + " > .MenuSubCont").fadeOut({queue:false, duration: menuSpeed}); // OH CRAP! FADE OUT!
			});
	}
	
	// The slide down and up - looks the best.. works when fast, very fluid
	if(menuAnimation == "slide") {
		$('.MenuItemHover').each(function(e) {
			
			// Set the original height value to enable hover function to access it and reset the css height if the slide animation is ended before it completes
			if(($("#" + this.id + " > .MenuSubCont").height()) != null) {
				$(this).attr("origHeight", $("#" + this.id + " > .MenuSubCont").height());
			} else { $(this).attr("origHeight", 0 ); } // If no sub content just set the original height to 0 (could possibly be omitted for speed?)
			// Assign the hover functions to each element
			$(this).hover(function() {
				$("#" + this.id + " > .MenuSubCont").height(parseInt($(this).attr("origHeight"))); // Reset the div to be displayed to its original height to overcome a bug caused by the animation stopping before it compeltes
				$("#" + this.id + " > .MenuSubCont").slideDown({queue:false, duration: menuSpeed, easing: "easeInOutCirc"}); // Transformers! ROLL OUT!
			},
			function () {
				$("#" + this.id + " > .MenuSubCont").slideUp({queue:false, duration: menuSpeed, easing: "easeInOutCirc"}); // TRANSFORMERS! I MESSED UP! ROLL IN!
			});
		});
	}
	
	
	// ExperimentaL!
	if(menuAnimation == "step") { // DK DESCRUCTION
			$('.MenuItemHover').hover(function() {
				$("#" + this.id + " > .MenuSubCont").show(); 
				$("#" + this.id + " > .MenuSubCont td").each(function(e) {
					$(this).fadeIn({queue:"mi", duration: 1});
				});
			},
			function () {
				$("#" + this.id + " > .MenuSubCont").hide();
				$("#" + this.id + " > .MenuSubCont td").each(function(e) {
					$(this).fadeOut({queue:false, duration: 100});
				});
			});
	}
	
	// Menu Item Hovers
	/*$('.MenuItem').each(function(e) {
		// Assing hovers to each element within the menu
		$(this).hover(function() {
			//$("#" + this.id + " > a").animate({color: "#ffffff"}, 200); // Un comment this to animate text color
			$(this).animate({backgroundColor: menuItemBGHover, borderTopColor: menuItemBorderHover, borderBottomColor: menuItemBorderHover}, {queue: false, duration: menuSpeed});
		},
		function () {
			//$("#" + this.id + " > a").animate({color: "#000000"}, 200); // Un comment this to animate text color
			$(this).animate({backgroundColor: menuItemBGDefault, borderTopColor: menuItemBorderDefault, borderBottomColor: menuItemBorderDefault}, {queue: false, duration: menuSpeed});
		});
	});*/
});
