var dropdown = {

animateduration: {over: 200, out: 100}, //duration of slide in/ out animation, in milliseconds

add:function(menuid,_par){
	jQuery(document).ready(function($){
		var $mainmenu = $("#"+menuid).addClass('ui-menu');
		var $headers=$mainmenu.find("div.ui-menu-item").parent();
		if ($.browser.msie && $.browser.version == '6.0') {
			$('<iframe scrolling="no" frameborder="0" marginheight="0" marginwidth="0"></iframe>').css({
				display:'none',
				position:'absolute',
				zIndex:'-1',
				margin:0,
				padding:0
			}).insertAfter($mainmenu.find('div.ui-menu-item'));
		}
		$headers.each(function(i){
			var $curobj=$(this);
			var $subul=$(this).find('kbd');
			this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()};
			this.istopheader=$curobj.parents(_par).length==1? true : false;
			$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0});
            

            $curobj.hover(
				function(e){
					var $this = this;
					menu = setTimeout(function(e){
                    $curobj.addClass("active").find('a:first').addClass('hover');
                     //remove autocomplete
                     $('body .ac_results').css('display', 'none');
						var $targetul=$($this).children("div:eq(0)");
						$this._offsets={left:$($this).offset().left, top:$($this).offset().top};
                                                if(menuid == 'topnav') {
                                                    var parentHeight = $('#topnav').height();
                                                    var linkHeight = parentHeight - 13;
                                                    $curobj.find('a:first').css('height', linkHeight);
                                                    $targetul.css({top: parentHeight});
                                                }
					var menuleft=0; //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($curobj.hasClass('full-width'))
                        menuleft=menuleft-$curobj.position().left;
					if ($targetul.queue().length<=1) { //if 1 or less queued animations
							$targetul.css({left:menuleft, width:$this._dimensions.subulw}).slideDown(dropdown.animateduration.over,function(){
                            if ($.browser.msie && $.browser.version == '6.0') {
                                $curobj.find('iframe').css({
                                    height:$targetul.height()+'px'
                                })
                            }
                        });
					}
                    // Used to position both directions of ie6 since menu will move if text goes to 2 or more lines.
                    var iframeTop = $curobj.find('.ui-menu-item').css('top');
                    if ($.browser.msie && $.browser.version == '6.0' && $('html').attr('dir') == 'ltr') {
                        $curobj.find('iframe').css({
							top: iframeTop,
                            left:menuleft,
                            width:$targetul.width()+'px'
                        }).show();
                    } else if($.browser.msie && $.browser.version == '6.0' && $('html').attr('dir') == 'rtl') {
                    	// with dir='rtl' we are experiencing positioning issues in ie6
                    	// I'm borrowing the attributes from the parent item and setting them
                    	// explicitly for the iframe and content box
                    	var iframeWidth = $curobj.find('.ui-menu-item').css('width');
                    	var iframeRight = $curobj.find('.ui-menu-item').css('right');
                    	var contentWidth = parseInt(iframeWidth) - 42;
                    	$curobj.find('.ui-menu-content').css('width', contentWidth).end().find('iframe').css({
                    		left: 'auto',
				right: iframeRight,
				width: iframeWidth
                    	}).show();
                    }
                    },500);
				},
				function(e){
					clearTimeout(menu)
                    $curobj.removeClass("active").find('a:first').removeClass('hover');
					var $targetul=$(this).children("div:eq(0)");
					$targetul.slideUp(dropdown.animateduration.out);
					$curobj.find('iframe').hide();
				}
			) //end hover
		}) //end $headers.each()
		$mainmenu.find("div:eq(0)").css({display:'none', visibility:'visible'});
	}) //end document.ready
}
}

//build menu with ID="myslidemenu" on page:
dropdown.add("topnav","ul");
dropdown.add("comparison","span");
dropdown.add("navi","ul");

