/*********************
//* 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/
*********************/

//Specify full URL to down and right arrow images (23 is padding-right to add to top level LIs with drop downs):
var arrowImages = { down: ['downArrow', '/App_Themes/Default/Images/jQuerySlideMenuDown.gif', 23], right: ['rightArrow', '/App_Themes/Default/Images/jQuerySlideMenuRight.gif'] };

var jQuerySlideMenu = {

	animateDuration: { over: 200, out: 100 }, // Duration of the slide in/out animation, in milliseconds

	buildMenu: function(menuID, arrowsVar) {
		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.children("a:eq(0)")
					.css(this.isTopHeader ? { paddingRight: arrowsVar.down[2]} : {})
					.append(
						'<img src="' + (this.isTopHeader ? arrowsVar.down[1] : arrowsVar.right[1]) +
						'" class="' + (this.isTopHeader ? arrowsVar.down[0] : arrowsVar.right[0]) +
						'" style="border: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("topSlideMenu", arrowImages);
jQuerySlideMenu.buildMenu("categorySlideMenu", arrowImages);
