/*********************
//* jQuery Multi Level CSS Menu (horizontal)- By Dynamic Drive DHTML code library: http://www.dynamicdrive.com
//* Menu instructions page: http://www.dynamicdrive.com/dynamicindex1/ddlevelsmenu/
//* Last modified: Sept 6th, 08'. Usage Terms: http://www.dynamicdrive.com/style/csslibrary/tos/
*********************/

//Specify full URL to down and right arrow images (25 is padding-right to add to top level LIs with drop downs):

var jQueryMenu = {
	fadeSettings: {
		overDuration: 50,
		outDuration: 50
	},
	buildMenu: function (menuid) {
		$(function ($) {
			var mainMenu= $("#"+menuid+">ul");
			var headers = mainMenu.find("ul").parent();
			headers.each(function (i) {
				var curObj = $(this);
				var subul = $(this).find('ul:eq(0)');
				this._dimensions = {
					w: this.offsetWidth,
					h: this.offsetHeight,
					subulw: subul.outerWidth(),
					subulh: subul.outerHeight()
				};
				this.isTopHeader = curObj.parents("ul").length==1? true : false;
				curObj.hover(function (e) {
					var targetul = $(this).children("ul:eq(0)");
					this._offsets = {
						left: $(this).offset().left,
						top: $(this).offset().top
					};
					var menuLeft = this.isTopHeader? 0 : this._dimensions.w;
					menuLeft = (this._offsets.left + menuLeft + this._dimensions.subulw > $(window).width()) ? (this.isTopHeader? -this._dimensions.subulw + this._dimensions.w : -this._dimensions.w) : menuLeft;
					targetul.fadeIn(jQueryMenu.fadeSettings.overDuration);
				},
				function (e) {
					$(this).children("ul:eq(0)").fadeOut(jQueryMenu.fadeSettings.outDuration)
				});
			});
			mainMenu.find("ul").css({
				display:'none', 
				visibility:'visible'
			});
		});
	}
};

//build menu with ID="myjquerymenu" on page:
jQueryMenu.buildMenu("nav")

