var jmenu={
dur: {over: 350, out: 600},
buildmenu:function(menuid, arr){
	jQuery(document).ready(function($){
		var $mmenu=$("#"+menuid+">ul")
		var $head=$mmenu.find("ul").parent()
		var isRtl=($("#"+menuid).attr("dir")=="rtl");
		$head.each(function(i){
			var $curobj=$(this)
			var $subul=$(this).find('ul:eq(0)')
			this._dim={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
			this.isroot=$curobj.parents("ul").length==1? true : false
			$subul.css({top:this.isroot? this._dim.h+"px" : 0})
			$curobj.children("a:eq(0)").css(this.isroot? (isRtl?{paddingLeft: arr.down[2]}:{paddingRight: arr.down[2]}) : {}).append(
				'<div class="'+(this.isroot? arr.down[0] : arr.right[0])
				+ '"></div>'
			)
			$curobj.each(
				function(){
					var $targetul=$(this).children("ul:eq(0)");
					this._offsets={left:$(this).offset().left, top:$(this).offset().top}
					var menuright=this.isroot? 0 : this._dim.w
					menuright=((this._offsets.left+$(this).width())-menuright-this._dim.subulw<0)? (this.isroot? -this._dim.subulw+this._dim.w : -this._dim.w) : menuright
					$targetul.css({right:(menuright)+"px",visibility:'hidden'});
				}
			)	
			$curobj.hover(
				function(e){			
				    var $targetul=$(this).children("ul:eq(0)")
					this._offsets={left:$(this).offset().left, top:$(this).offset().top}
					var mpos=this.isroot? 0 : this._dim.w				
					if(isRtl){
					    mpos=((this._offsets.left+$(this).width())-mpos-this._dim.subulw<0)? (this.isroot? -this._dim.subulw+this._dim.w : -this._dim.w) : mpos
					    $targetul.css({right:(mpos)+"px",visibility:'visible'}).fadeIn();
					}
					else{
					    mpos=(this._offsets.left+mpos+this._dim.subulw>$(window).width())? (this.isroot? -this._dim.subulw+this._dim.w : -this._dim.w) : mpos
                        $targetul.css({left:(mpos)+"px",visibility:'visible'}).fadeIn();
                    }
				},
				function(e){
					$(this).children("ul:eq(0)").fadeOut();
				}
			)
		})
		$mmenu.find("ul").hide();
	})
}
}
