/*********************
//* jQuery Multi Level CSS Menu #2- By Dynamic Drive: http://www.dynamicdrive.com/
//* Last update: Nov 7th, 08': Limit # of queued animations to minmize animation stuttering
//* Menu avaiable at DD CSS Library: http://www.dynamicdrive.com/style/
*********************/

var jQuerySlideMenu = {

	animateDuration: { over: 200, out: 100 }, // Duration of the slide in/out animation, in milliseconds

	buildMenu: function(menuID) {
		jQuery(document).ready(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;
				$subul.css({ top: this.isTopHeader ? this._dimensions.h + "px" : 0 });
				$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;
						if ($targetUL.queue().length <= 1) //if 1 or less queued animations
							$targetUL.css({ left: menuLeft + "px", width: this._dimensions.subulw + 'px' }).slideDown(jQuerySlideMenu.animateDuration.over);
					},
					function(e) {
						var $targetUL = $(this).children("ul:eq(0)");
						$targetUL.slideUp(jQuerySlideMenu.animateDuration.out);
					}) //end hover
			}) //end $headers.each()
			$mainmenu.find("ul").css({ display: 'none', visibility: 'visible' });
		}) //end document.ready
	}
}

jQuerySlideMenu.buildMenu("slideMenu");

