//Specify full URL to down and right arrow images (25 is padding-right to add to top level LIs with drop downs):
jQuery.noConflict();
//jQuery(document).ready(function($){
    var arrowimages={down:['downarrowclass', '', 25], right:['rightarrowclass', '']}
    //  RG - Comment out per new GL design 
    //var arrowimages={down:['downarrowclass', 'arrow-down.gif', 25], right:['rightarrowclass', 'arrow-right.gif']}
    var jquerycssmenu={
        buildmenu:function(arrowsvar){
	        jQuery(document).ready(function($){
	            var $menus = $(".jmenu");
	            $menus.each(function(m){
                    //find all the child UL elements
		            var $mainmenu=$("#"+ $(this).attr("id") +">ul")
		            var $fadeindelay = parseInt($(this).attr("fadeindelay"))
		            var $fadeoutdelay = parseInt($(this).attr("fadeoutdelay"))
		            var $effects = $(this).attr("effects")
		            var $imagepath = $(this).attr("imagepath")
		            //get parents of all child UL elements
		            var $headers=$mainmenu.find("ul").parent()
		            $headers.each(function(i){
			            var $curobj=$(this)
			            //find all the sub UL under the current LI element, and select the top one.
			            var $subul=$(this).find('ul:eq(0)')
			            //set the dimensions for the current header element
			            this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
			            //verify if the current LI element is TOP header or not
			            this.istopheader=$curobj.parents("ul").length==1? true : false
			            $subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
			            //puts the arrow image based on whether the LI element is TOP or not...
			            $curobj.children("a:eq(0)").css(this.istopheader? {paddingRight: arrowsvar.down[2]} : {}).append(
			                //  RG - Comment out per new GL design 
				            //'<img src="'+ $imagepath + (this.istopheader? arrowsvar.down[1] : arrowsvar.right[1])
				            // +'" class="' + (this.istopheader? arrowsvar.down[0] : arrowsvar.right[0])
				            //+ '" style="border:0;" />'
			            )
			            $curobj.hover(
			                //mouse over
				            function(e){
				                //get the ul to show on mouse over
					            var $targetul=$(this).children("ul:eq(0)")
					            //set the position
					            //$(this).css({height:"20px"})
					            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
					            switch($effects)
					            {
					                case "Appear": $targetul.css({left:menuleft+"px"}).fadeIn($fadeindelay); break;
					                case "Slide": $targetul.css({left:menuleft+"px"}).slideDown($fadeindelay); break;
					            }
				            },
				            //mouse out
				            function(e){
				                switch($effects)
					            {
					                case "Appear": $(this).children("ul:eq(0)").fadeOut($fadeoutdelay); break;
					                case "Slide": $(this).children("ul:eq(0)").slideUp($fadeoutdelay); break;
					            }
					            
				            }
			            ) //end hover
		            }) //end $headers.each()
		            $mainmenu.find("ul").css({display:'none', visibility:'visible'})	            
	            })
	        }) //end document.ready
        }
    }
    //build menu with ID="myjquerymenu" on page:
    jquerycssmenu.buildmenu(arrowimages)
//});

