eval(function(p,a,c,k,e,r){e=function(c){return(c<62?'':e(parseInt(c/62)))+((c=c%62)>35?String.fromCharCode(c+29):c.toString(36))};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'([3-579cf-hj-mp-rt-yCG-NP-RT-Z]|[12]\\w)'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('5 $$,$$B,$$A,$$E,$$F,$$D,$$S;(3(){5 O,B,A,E,F,D,S;O=3(id){4"1F"==1p id?Q.getElementById(id):id};O.extend=3(v,U){w(5 I V U){v[I]=U[I]}4 v};O.deepextend=3(v,U){w(5 I V U){5 11=U[I];7(v===11)continue;7(1p 11==="1G"){v[I]=1c.callee(v[I]||{},11)}u{v[I]=11}}4 v};B=(3(x){5 b={12:/12/.y(x)&&!/1q/.y(x),1q:/1q/.y(x),1H:/webkit/.y(x)&&!/1r/.y(x),1I:/1I/.y(x),1r:/1r/.y(x)};5 1d="";w(5 i V b){7(b[i]){1d=i}}7(b.1H){1d="1e"}b.1e=parseInt((x.1J(eval("/(?:"+1d+")[\\\\/: ]([\\\\d.]+)/"))||[])[1]);b.ie=b.12;b.1K=b.12&&b.1e==6;1L{b.1M=b.12&&!!external.max_version}1N(e){b.1M=J}4 b})(1s.navigator.userAgent.toLowerCase());A={isArray:3(1O){4 Object.1P.toString.R(1O)==="[1G 1Q]"},1f:3(c,C,p){7(c.1f){c.1f(C,p)}u{w(5 i=0,K=c.14;i<K;i++){C.R(p,c[i],i,c)}}},W:3(c,C,p){7(c.W){4 c.W(C,p)}u{5 15=[];w(5 i=0,K=c.14;i<K;i++){C.R(p,c[i],i,c)&&15.push(c[i])}4 15}},1t:3(c,C,p){7(c.1t){4 c.1t(C,p)}u{5 15=[];w(5 i=0,K=c.14;i<K;i++){7(!C.R(p,c[i],i,c))4 J};4 1g}},1u:3(c,1v){7(c.1u){4 c.1u(1v)}u{5 15=[];w(5 i=0,K=c.14;i<K;i++){7(c[i]===1v)4 i};4-1}}};F=(3(){5 17=1Q.1P.17;4{bind:3(1h,p){5 1i=17.R(1c,2);4 3(){4 1h.1R(p,1i.1S(17.R(1c)))}},bindAsEventListener:3(1h,p){5 1i=17.R(1c,2);4 3(9){4 1h.1R(p,[E.G(9)].1S(1i))}}}})();D={1j:3(h){5 X=h?h.1T:Q;4 1U.1V(X.1W.1X,X.1Y.1X)},1k:3(h){5 X=h?h.1T:Q;4 1U.1V(X.1W.1Z,X.1Y.1Z)},1l:3(a,b){4(q.1l=a.1l?3(a,b){4 a!=b&&a.1l(b)}:3(a,b){4!!(a.compareDocumentPosition(b)&16)})(a,b)},r:3(h){5 j=0,H=0,L=0,M=0;7(!h.20||(B.ie&&B.1e==8)){5 n=h;while(n){j+=n.offsetLeft,H+=n.offsetTop;n=n.offsetParent};L=j+h.offsetWidth;M=H+h.offsetHeight}u{5 r=h.20();j=L=q.1k(h);H=M=q.1j(h);j+=r.j;L+=r.L;H+=r.H;M+=r.M};4{"j":j,"H":H,"L":L,"M":M}},clientRect:3(h){5 r=q.r(h),1w=q.1k(h),1x=q.1j(h);r.j-=1w;r.L-=1w;r.H-=1x;r.M-=1x;4 r},21:3(g){4(q.21=Q.1y?3(g){4 Q.1y.22(g,23)}:3(g){4 g.1m})(g)},24:3(g,k){4(q.24=B.ie?3(g,k){5 f=g.1m;7(k=="T"){5 T=f.W.1J(/1z\\(T=(.*)\\)/i);7(T){5 o=parseFloat(T[1]);4 o?o/25:0}4 1};7(k=="26"){k="27"}5 Y=f[k]||f[S.1A(k)];7(!/^\\-?\\d+(px)?$/i.y(Y)&&/^\\-?\\d/.y(Y)){f=g.f,j=f.j,29=g.1B.j;g.1B.j=g.1m.j;f.j=Y||0;Y=f.pixelLeft+"px";f.j=j;g.1B.j=29}4 Y}:3(g,k){5 f=Q.1y.22(g,23);4 k V f?f[k]:f.getPropertyValue(k)})(g,k)},setStyle:3(18,f,Z){7(!18.14){18=[18]}7(1p f=="1F"){5 s=f;f={};f[s]=Z}A.1f(18,3(g){w(5 k V f){5 Z=f[k];7(k=="T"&&B.ie){g.f.W=(g.1m.W||"").2a(/1z\\([^)]*\\)/,"")+"1z(T="+Z*25+")"}u 7(k=="26"){g.f[B.ie?"27":"cssFloat"]=Z}u{g.f[S.1A(k)]=Z}}})}};E=(3(){5 19,1a,10=1;7(1s.2b){19=3(l,m,t){l.2b(m,t,J)};1a=3(l,m,t){l.removeEventListener(m,t,J)}}u{19=3(l,m,t){7(!t.$$10)t.$$10=10++;7(!l.N)l.N={};5 P=l.N[m];7(!P){P=l.N[m]={};7(l["on"+m]){P[0]=l["on"+m]}}P[t.$$10]=t;l["on"+m]=1n};1a=3(l,m,t){7(l.N&&l.N[m]){delete l.N[m][t.$$10]}};3 1n(){5 1o=1g,9=G();5 P=q.N[9.m];w(5 i V P){q.$$1n=P[i];7(q.$$1n(9)===J){1o=J}}4 1o}}3 G(9){7(9)4 9;9=1s.9;9.pageX=9.clientX+D.1k();9.pageY=9.clientY+D.1j();9.target=9.srcElement;9.1D=G.1D;9.1E=G.1E;7(9.m=="mouseout"){9.2c=9.toElement}u 7(9.m=="mouseover"){9.2c=9.fromElement}4 9};G.1E=3(){q.1o=J};G.1D=3(){q.cancelBubble=1g};4{"19":19,"1a":1a,"G":G}})();S={1A:3(s){4 s.2a(/-([a-z])/ig,3(all,2d){4 2d.toUpperCase()})}};7(B.1K){1L{Q.execCommand("BackgroundImageCache",J,1g)}1N(e){}};$$=O;$$B=B;$$A=A;$$E=E;$$F=F;$$D=D;$$S=S})();',[],138,'|||function|return|var||if||event|||array|||style|elem|node||left|name|element|type|||thisp|this|rect||handler|else|destination|for|ua|test||||callback||||fixEvent|top|property|false|len|right|bottom|events||handlers|document|call||opacity|source|in|filter|doc|ret|value|guid|copy|msie||length|res||slice|elems|addEvent|removeEvent||arguments|vMark|version|forEach|true|fun|args|getScrollTop|getScrollLeft|contains|currentStyle|handleEvent|returnValue|typeof|opera|chrome|window|every|indexOf|elt|sLeft|sTop|defaultView|alpha|camelize|runtimeStyle||stopPropagation|preventDefault|string|object|safari|firefox|match|ie6|try|maxthon|catch|obj|prototype|Array|apply|concat|ownerDocument|Math|max|documentElement|scrollTop|body|scrollLeft|getBoundingClientRect|curStyle|getComputedStyle|null|getStyle|100|float|styleFloat||rsLeft|replace|addEventListener|relatedTarget|letter'.split('|'),0,{}))
var RelativePosition = function(){
	function getLeft( align, rect, rel ){
		var iLeft = 0;
		switch (align.toLowerCase()) {
			case "left" :
				return rect.left - rel.offsetWidth;
			case "clientleft" :
				return rect.left;
			case "center" :
				return ( rect.left + rect.right - rel.offsetWidth ) / 2;
			case "clientright" :
				return rect.right - rel.offsetWidth;
			case "right" :
			default :
				return rect.right;
		};
	};
	function getTop( valign, rect, rel ){
		var iTop = 0;
		switch (valign.toLowerCase()) {
			case "top" :
				return rect.top - rel.offsetHeight;
			case "clienttop" :
				return rect.top;
			case "center" :
				return ( rect.top + rect.bottom - rel.offsetHeight ) / 2;
			case "clientbottom" :
				return rect.bottom - rel.offsetHeight;
			case "bottom" :
			default :
				return rect.bottom;
		};
	};
	//定位元素 相对定位元素
	return function ( fix, rel, options ) {
		//默认值
		var opt = $$.extend({
			align:			"clientleft",//水平方向定位
			vAlign:			"clienttop",//垂直方向定位
			customLeft:		0,//自定义left定位
			customTop:		0,//自定义top定位
			percentLeft:	0,//自定义left百分比定位
			percentTop:		0,//自定义top百分比定位
			adaptive:		false,//是否自适应定位
			reset:			false//自适应定位时是否重新定位
		}, options || {});
		//定义参数
		var rect = $$D.clientRect(fix)
			,iLeft = getLeft(opt.align, rect, rel) + opt.customLeft
			,iTop = getTop(opt.vAlign, rect, rel) + opt.customTop;
		//自定义百分比定位
		if (opt.percentLeft) { iLeft += .01 * opt.percentLeft * fix.offsetWidth; };
		if (opt.percentTop) { iTop += .01 * opt.percentTop * fix.offsetHeight; };
		//自适应视窗定位
		if (opt.adaptive) {
			//修正定位参数
			var doc = fix.ownerDocument
				,maxLeft = doc.clientWidth - rel.offsetWidth
				,maxTop = doc.clientHeight - rel.offsetHeight;
			if (opt.reset) {
				//自动重新定位
				if (iLeft > maxLeft || iLeft < 0) {
					iLeft = getLeft(2 * iLeft > maxLeft ? "left" : "right", rect, rel) + opt.customLeft;
				};
				if (iTop > maxTop || iTop < 0) {
					iTop = getTop(2 * iTop > maxTop ? "top" : "bottom", rect, rel) + opt.customTop;
				};
			} else {
				//修正到适合位置
				iLeft = Math.max(Math.min(iLeft, maxLeft), 0);
				iTop = Math.max(Math.min(iTop, maxTop), 0);
			};
		};
		//加上滚动条
		iLeft += $$D.getScrollLeft(fix); iTop += $$D.getScrollTop(fix);
		//返回定位参数
		return { Left: iLeft, Top: iTop };
	};
}();
//容器集合
var FixedMenu = function(containers, options) {
	this._timerContainer = null;//容器定时器
	this._timerMenu = null;//菜单定时器
	this._frag = document.createDocumentFragment();//碎片对象，保存菜单元素
	this._menus = {};//菜单对象
	
	this._containers = [];//容器集合
	
	this._setOptions(options);
	var opt = this.options;
	
	this._custommenu = opt.menu;
	
	this.css = opt.css;
	this.hover = opt.hover;
	this.active = opt.active;
	this.tag = opt.tag;
	this.html = opt.html;
	this.relContainer = opt.relContainer;
	this.relative = opt.relative;
	this.attribute = opt.attribute;
	this.property = opt.property;
	
	this.onBeforeShow = opt.onBeforeShow;
	
	this.delay = parseInt(opt.delay) || 0;
	
	//修正自定义容器
	$$A.forEach($$A.isArray(containers) ? containers : [containers], function(o, i){
		//自定义容器 id:定位元素 menu:插入菜单元素
		var pos, menu;
		if ( o.id ) {
			pos = o.id; menu = o.menu ? o.menu : pos;
		} else {
			pos = menu = o;
		};
		pos = $$(pos); menu = $$(menu);
		//容器对象 pos:定位元素 menu:插入菜单元素
		pos && menu && this._iniContainer( i, { "pos": pos, "menu": menu } );
	}, this);
	
	//初始化程序
	this._iniMenu();
};
FixedMenu.prototype = {
  //设置默认属性
  _setOptions: function(options) {
	this.options = {//默认值
		menu:			[],//自定义菜单集合
		delay:			200,//延迟值(微秒)
		tag:			"div",//默认生成标签
		css:			undefined,//默认样式
		hover:			undefined,//触发菜单样式
		active:			undefined,//显示下级菜单时显示样式
		html:			"",//菜单内容
		relContainer:	false,//是否相对容器定位（否则相对菜单）
		relative:		{ align: "clientleft", vAlign: "bottom" },//定位对象
		attribute:		{},//自定义attribute属性
		property:		{},//自定义property属性
		onBeforeShow:	function(){}//菜单显示时执行
	};
	$$.extend( this.options, options || {} );
  },
  //程序初始化
  _iniMenu: function() {
	this.hide();//隐藏菜单
	this._buildMenu();//生成菜单对象
	this._forEachContainer(this._resetContainer);//重置容器属性
	this._insertMenu(0, 0);//显示菜单
  },
  //根据自定义菜单对象生成程序菜单对象
  _buildMenu: function() {
	//清除旧菜单dom(包括自定义的)
	this._forEachMenu(function(o){
		var elem = o._elem;
		if ( elem ) {
			//防止dom内存泄漏
			$$E.removeEvent( elem, "mouseover", o._event );
			elem.parentNode.removeChild(elem);
			o._elem = o.elem = null;
		};
	});
	//设置菜单默认值
	var options = {
		id:				0,//id
		rank:			0,//排序
		elem:			"",//自定义元素
		tag:			this.tag,
		css:			this.css,
		hover:			this.hover,
		active:			this.active,
		html:			this.html,
		relContainer:	!!this.relContainer,
		relative:		this.relative,
		attribute:		this.attribute,
		property:		this.property
	};
	//先定义"0"顶级菜单
	this._menus = { "0": { "_children": [] } };
	//整理自定义菜单并插入到程序菜单对象
	$$A.forEach(this._custommenu, function(o) {
		//生成菜单对象(由于包含对象，要用深度扩展)
		var menu = $$.deepextend( $$.deepextend( {}, options ), o || {} );
		//去掉相同id菜单，同时排除了id为"0"的菜单
		if ( !!this._menus[ menu.id ] ) { return; };
		//重置属性
		menu._children = []; menu._index = -1;
		this._menus[menu.id] = menu;
	}, this);
	//建立树形结构
	this._forEachMenu(function( o, id, menus ) {
		if ( "0" === id ) { return; };//顶级没有父级菜单
		var parent = this._menus[o.parent];
		//父级菜单不存在或者父级是自己的话，当成一级菜单
		if ( !parent || parent === o ) { parent = menus[o.parent = "0"]; };
		//插入到父级菜单对象的_children中
		parent._children.push(o);
	});
	//整理菜单对象
	this._forEachMenu(function(o) {
		//如果有自定义元素的话先放到碎片文档中
		!!o.elem && ( o.elem = $$(o.elem) ) && this._frag.appendChild(o.elem);
		//修正样式,优先使用自定义元素的class
		if ( !!o.elem && o.elem.className ) {
			o.css = o.elem.className;
		} else if ( o.css === undefined ) { o.css = ""; };
		if ( o.hover === undefined ) { o.hover = o.css; };
		if ( o.active === undefined ) { o.active = o.hover; };
		//对菜单对象的_children集合排序(先按rank再按id排序)
		o._children.sort(function( x, y ) { return x.rank - y.rank || x.id - y.id; });
	});
  },
  //插入菜单
  _insertMenu: function(index, parent) {
	var container = this._containers[index];
	//如果是同一个父级菜单不用重复插入
	if ( container._parent === parent ) { return; };
	container._parent = parent;
	//把原有容器内菜单移到碎片对象中
	$$A.forEach( container._menus, function(o) { o._elem && this._frag.appendChild(o._elem); }, this );
	//重置子菜单对象集合
	container._menus = [];
	//把从父级菜单元素的子菜单对象集合获取的元素插入到容器
	$$A.forEach(this._menus[parent]._children, function( menu, i ){
		this._checkMenu( menu, index );//检查菜单
		container._menus.push(menu);//加入到容器的子菜单集合，方便调用
		container.menu.appendChild(menu._elem);//菜单元素插入到容器
	}, this);
  },
  //检查菜单
  _checkMenu: function(menu, index) {
	//索引保存到菜单对象属性中，方便调用
	menu._index = index;
	//如果菜单对象没有元素
	if ( !menu._elem ) {
		var elem = menu.elem;
		//如果没有自定义元素的话创建一个
		if ( !elem ) { elem = document.createElement(menu.tag); elem.innerHTML = menu.html; };
		//设置property
		$$.extend( elem, menu.property );
		//设置attribute
		var attribute = menu.attribute;
		for (var att in attribute) { elem.setAttribute( att, attribute[att] ); };
		//设置样式
		elem.className = menu.css;
		//设置事件
		menu._event = $$F.bindAsEventListener( this._hoverMenu, this, menu );//用于清除事件
		$$E.addEvent( elem, "mouseover", menu._event );
		//保存到菜单对象
		menu._elem = elem;
	};
  },
  //触发菜单
  _hoverMenu: function(e, menu) {
	var elem = menu._elem;
	//如果是内部元素触发直接返回
	if ( $$D.contains( elem, e.relatedTarget ) || elem === e.relatedTarget ) { return; };
	clearTimeout(this._timerMenu);
	//可能在多个容器间移动，所以全部容器都重新设置样式
	this._forEachContainer(function(o, i){
		if ( o.pos.visibility === "hidden" ) { return; };
		this._resetCss(o);
		//设置当前菜单为active样式
		var menu = o._active;
		if ( menu ) { menu._elem.className = menu.active; };
	});
	//设置当前菜单为触发样式
	if ( this._containers[menu._index]._active !== menu ) { elem.className = menu.hover; };
	//触发显示菜单
	this._timerMenu = setTimeout( $$F.bind( this._showMenu, this, menu ), this.delay );
  },
  //显示菜单
  _showMenu: function(menu) {
	var index = menu._index, container = this._containers[index], child = !!menu._children.length;
	//隐藏不需要的容器
	this._forEachContainer( function(o, i) { i > index && this._hideContainer(o); } );
	//重置当前容器_active
	container._active = null;
	//如果有子级菜单
	if ( child ) {
		//设置当前容器_active
		container._active = menu;
		//显示下一级容器
		index++;//设置索引
		this._checkContainer(index);//检查容器
		this._insertMenu(index, menu.id);//插入菜单
		this._showContainer(menu);//显示容器
	};
	//重置当前容器的css
	this._resetCss(container);
	//设置当前菜单样式
	menu._elem.className = child ? menu.active : menu.hover;
  },
  //初始化容器(索引, 容器元素)
  _iniContainer: function(index, container) {
	var oContainer = container.pos;
	//重置属性
	this._resetContainer(container);
	//添加事件
	$$E.addEvent(oContainer, "mouseover", $$F.bind(function(){ clearTimeout(this._timerContainer); }, this));
	$$E.addEvent(oContainer, "mouseout", $$F.bindAsEventListener(function(e){
		//先判断是否移出到所有容器之外
		var elem = e.relatedTarget,
			isOut = $$A.every(this._containers, function(o){ return  o.pos == elem || !($$D.contains(o.pos, elem)); });
		if ( isOut ) {
			//清除定时器并隐藏
			clearTimeout(this._timerContainer); clearTimeout(this._timerMenu);
			this._timerContainer = setTimeout( $$F.bind( this.hide, this ), this.delay );
		};
	}, this));
	//除了第一个容器外设置浮动样式
	if ( index ) {
		$$D.setStyle(container.pos, {
			position: "absolute", display: "block", margin: 0,
			zIndex: this._containers[index - 1].pos.style.zIndex + 1//要后面的覆盖前面的
		});
	};
	//ie6处理select
	if ( $$B.ie6 ) {
		var iframe = document.createElement("<iframe style='position:absolute;filter:alpha(opacity=0);display:none;'>");
		document.body.insertBefore(iframe, document.body.childNodes[0]);
		container._iframe = iframe;
	};
	//记录索引，方便调用
	container._index = index;
	//插入到容器集合
	this._containers[index] = container;
  },
  //检查容器
  _checkContainer: function(index) {
	if ( index > 0 && !this._containers[index] ) {
		//如果容器不存在，根据前一个容器复制成新容器，第一个容器必须自定义
		var pre = this._containers[index - 1].pos
		//用了新的添加事件方式，没有ie的cloneNode的bug
			,container = pre.parentNode.insertBefore( pre.cloneNode(false), pre );
		//清除id防止冲突
		container.id = "";
		//初始化容器
		this._iniContainer( index, { "pos": container, "menu": container } );
	};
  },
  //显示容器
  _showContainer: function(menu) {
	var index = menu._index
		,container = this._containers[index + 1].pos
		,elem = menu.relContainer ? this._containers[index].pos : menu._elem
		,pos = RelativePosition( elem, container, menu.relative );
	//执行显示前事件
	this.onBeforeShow(container, menu);
	//定位并显示容器
	$$D.setStyle(container, {
		left: pos.Left + "px", top: pos.Top + "px", visibility: "visible"
	});
	//ie6处理select
	if ( $$B.ie6 ) {
		$$D.setStyle(this._containers[index + 1]._iframe, {
			width: container.offsetWidth + "px",
			height: container.offsetHeight + "px",
			left: pos.Left + "px", top: pos.Top + "px",
			display: ""
		});
	};
  },
  //隐藏容器
  _hideContainer: function(container) {
	//设置隐藏
	$$D.setStyle( container.pos, { left: "-9999px", top: "-9999px", visibility: "hidden" } );
	//重置上一个菜单的触发菜单对象
	this._containers[container._index - 1]._active = null;
	//ie6处理select
	if ( $$B.ie6 ) { container._iframe.style.display = "none"; };
  },
  //重置容器对象属性
  _resetContainer: function(container) {
	container._active = null;//重置触发菜单
	container._menus = [];//重置子菜单对象集合
	container._parent = -1;//重置父级菜单id
  },
  //隐藏菜单
  hide: function() {
	this._forEachContainer(function(o, i){
		if ( i === 0 ) {
			//如果是第一个重设样式和_active
			this._resetCss(o);
		} else {//隐藏容器
			this._hideContainer(o);
		};
	});
  },
  //重设容器菜单样式
  _resetCss: function(container) {
	$$A.forEach( container._menus, function(o, i){ o._elem.className = o.css; }, this );
  },
  //历遍菜单对象集合
  _forEachMenu: function(callback) {
	for ( var id in this._menus ) { callback.call( this, this._menus[id], id, this._menus ); };
  },
  //历遍容器对象集合
  _forEachContainer: function(callback) {
	$$A.forEach( this._containers, callback, this );
  },
  //添加自定义菜单
  add: function(menu) {
	this._custommenu = this._custommenu.concat(menu);
	this._iniMenu();
  },
  //修改自定义菜单
  edit: function(menu) {
	$$A.forEach( $$A.isArray( menu ) ? menu : [ menu ], function(o){
		//如果对应id的菜单存在
		if ( o.id && this._menus[o.id] ) {
			//从自定义菜单中找出对应菜单,并修改
			$$A.every( this._custommenu, function(m, i){
				if ( m.id === o.id ) {
					this._custommenu[i] = $$.deepextend( m, o ); return false;
				};
				return true;
				//用every可以跳出循环
			}, this );
		};
	}, this );
	this._iniMenu();
  },
  //删除自定义菜单
  del: function() {
	var ids = Array.prototype.slice.call(arguments);
	this._custommenu = $$A.filter( this._custommenu, function(o){
		return $$A.indexOf(ids, o.id) === -1;
	});
	this._iniMenu();
  }
};
