﻿var Menu={_timeout:null,curr_ctrl:null,curr_menu:null,timeout:500,warp_x:0,warp_y:18,shadow:false,winclick:false,nohide:false,DragDrop:null,backBg:false,pos:null,init:function(a,b){if(this.curr_ctrl&&this.curr_ctrl!=$(a))this.hide();this.options=b;this.curr_ctrl=$(a);this.curr_menu=$(b.curr_menu?b.curr_menu:a+'_menu');b=b||{};if(!b.timeout&&b.timeout!=0)b.timeout=this.timeout;if(!b.warp_x)b.warp_x=this.warp_x;if(!b.warp_y)b.warp_y=this.warp_y;if(!b.shadow)b.shadow=this.shadow;if(!b.winclick)b.winclick=this.winclick;if(this.curr_ctrl&&!this.curr_ctrl.initialized){this.show();this.setStyles(b);if(!b.nohide)if(!b.winclick){this.ctrl_event(b);this.menu_event(b)}else{this.win_event(b)}if(b.backBg){this.FullDiv(b);this.selDisable()}if(b.DragDrop){new DragDrop.Drop(Object.extend({element:this.curr_menu},b.DragDrop));this.Droped=true}}else{if(b.backBg){$(a+'_fulls').show();this.selDisable()}if(b.DragDrop){if(!this.Droped)new DragDrop.Drop(Object.extend({element:this.curr_menu},b.DragDrop));if(!b.warp_x)b.warp_x=this.warp_x;if(!b.warp_y)b.warp_y=this.warp_y}}this.setPosition(b);this.show()},show:function(){this.curr_menu.show()},hide:function(){if(this.fulls){this.fulls.hide();this.selEnable()}this.curr_menu.hide();clearTimeout(this._timeout);this._timeout=null},setStyles:function(a){var b=$(this.curr_ctrl.id+'_iframe');var c=$(this.curr_ctrl.id+'_table');if(b){var d=Element.getDimensions(c);var e=d.height;b.style.cssText='left:0; top:0;position:absolute;width:100%;height:'+e+'px;z-index:2;filter:alpha(opacity=0);opacity:0;';c.style.cssText='left:0; top:0;position:absolute; z-index:1000';if(!this.Sel)this.Sel=document.getElementsByTagName('select')}},setPosition:function(a){if(a.pos){if(typeof a.pos=='function')a.pos();else switch(a.pos){case'setPosCenter':Menu.setPosCenter(a);default:return}return}var b=Element.getDimensions(this.curr_menu);var c=b.width;var d=b.height;var e=Position.cumulativeOffset(this.curr_ctrl);var f=e[0]+a.warp_x;var g=e[1]+a.warp_y;if((c+f)>=getWindowWidth())f-=c+a.warp_x;if((d+g)>=getWindowHeight())g-=d+a.warp_y;this.curr_menu.setStyle({top:g+'px',left:f+'px'})},setPosCenter:function(a){var b=(document.documentElement.clientWidth-this.curr_menu.clientWidth)/2+a.warp_x;var c=document.documentElement.scrollTop+((document.documentElement.clientHeight-this.curr_menu.clientHeight)/2)+a.warp_y;this.curr_menu.setStyle({top:c+'px',left:b+'px'})},FullDiv:function(a){var b=getWindowWidth();var c=getWindowHeight();var d=a.backBg.index?a.backBg.index:1;var e=a.backBg.background?a.backBg.background:'#fff';var f=a.backBg.opacity?a.backBg.opacity:'50';this.fulls=document.createElement('div');this.fulls.id=this.curr_ctrl.id+'_fulls';this.fulls.style.cssText='position:absolute;left:0;top:0;width:'+b+'px;height:'+c+'px;z-index:'+d+';background:'+e+';filter:alpha(opacity='+f+');opacity:'+f+';';document.body.appendChild(this.fulls);this.fulls=$(this.fulls)},ctrl_event:function(a){var b=this.curr_ctrl;b.initialized=true;b.outfunc=typeof b.onmouseout=='function'?b.onmouseout:null;b.overfunc=typeof b.onmouseover=='function'?b.onmouseover:null;b.onmouseout=function(){if(b.outfunc)b.outfunc();this._timeout=setTimeout(function(){this.hide()}.bind(this),a.timeout)}.bind(this);b.onmouseover=function(){if(b.overfunc)b.overfunc();clearTimeout(this._timeout);this._timeout=null}.bind(this)},menu_event:function(a){var b=this.curr_menu;b.outfunc=typeof b.onmouseout=='function'?b.onmouseout:null;b.overfunc=typeof b.onmouseover=='function'?b.onmouseover:null;b.onmouseout=function(){if(b.outfunc)b.outfunc();this._timeout=setTimeout(function(){this.hide()}.bind(this),a.timeout)}.bind(this);b.onmouseover=function(){if(b.overfunc)b.overfunc();clearTimeout(this._timeout);this._timeout=null}.bind(this);if(Prototype.Browser.IE&&a.shadow){b.style.filter+="progid:DXImageTransform.Microsoft.shadow(direction=135,color=#CCCCCC,strength=2)"}},win_event:function(f){var g=this.curr_ctrl;var h=this.curr_menu;g.initialized=true;var i=function(a){var b=$(g.id+'_iframe');element=Event.element(a);if(element==g||Menu.options.nohide)return;var c=[Event.pointerX(a),Event.pointerY(a)];var d=Position.within((b?b:h),c[0],c[1]);if(!d){h.hide();clearTimeout(this._timeout);this._timeout=null;var e=$(g.id+'_fulls');if(e){e.hide();if(!Menu.curr_menu.visible())Menu.selEnable()}}};Event.observe(document,"click",i,false)},selDisable:function(){if(this.Sel){$A(this.Sel).each(function(s){$(s).disable()})}},selEnable:function(){if(this.Sel){$A(this.Sel).each(function(s){$(s).enable()})}}};function iframeStyle(e){var a=$(e+'_iframe');var b=$(e+'_table');var c=Element.getDimensions(b);var d=c.height;a.style.cssText='left:0; top:0;position:absolute;width:100%;height:'+d+'px;z-index:2;filter:alpha(opacity=0);opacity:0;'}var pop='';pop+='<TABLE cellpadding="0" cellspacing="0" class="pop"><TBODY><TR>';pop+='<TD class="p_bg1"></TD><TD class="p_border"></TD><TD class="p_bg2"></TD></TR>';pop+='<TR><TD class="p_border"></TD><TD class="con"><H2 id="pop_h"></H2>';pop+='<DIV class="texts" id="pop_text"></DIV>';pop+='<DIV class="btnbox" id=pop_btn></DIV>';pop+='</TD><TD class="p_border"></TD></TR><TR><TD class="p_bg3"></TD><TD class="p_border"></TD><TD class="p_bg4"></TD></TR></TBODY></TABLE>';var pop_btn='<INPUT name="button" type="button" value="确定" class="pop_btns" onclick="$(\'pop_Tab\').hide()">';var pop_cancel='<INPUT name="button" type="button" value="取消" class="btnscan" onclick="$(\'pop_Tab\').hide()">';function popWin(a){if(!$('pop_Tab')){pop_Tab=document.createElement('div');pop_Tab.setAttribute('id','pop_Tab');document.body.appendChild(pop_Tab);pop_Tab.innerHTML=pop}$('pop_h').update(a.h);$('pop_text').update(a.text);$('pop_btn').update(a.btn)}function popWinNo(a){if(!$('pop_Tab')){pop_Tab=document.createElement('div');pop_Tab.setAttribute('id','pop_Tab');document.body.appendChild(pop_Tab);pop_Tab.innerHTML=pop}$('pop_btn').hide();$('pop_h').update(a.h);$('pop_text').update(a.text)}function popAlter(a,t){popWin({h:a,text:t,btn:pop_btn});Menu.init(null,{curr_menu:'pop_Tab',pos:'setPosCenter',warp_y:-50})}function popErr(t){popWin({h:'错误提示',text:t,btn:pop_btn});Menu.init(null,{curr_menu:'pop_Tab',pos:'setPosCenter',warp_y:-50})}function popFred(){popWinNo({h:'加为好友',text:'正在发送请求...',btn:pop_btn});Menu.init(null,{curr_menu:'pop_Tab',pos:'setPosCenter',warp_y:-50})}function popFredComp(){$('pop_text').update('成功加对方为好友！');$('pop_btn').show().update(pop_btn);popHide(1000)}function popFredDel(){popWinNo({h:'删除好友',text:'正在发送请求...',btn:pop_btn});Menu.init(null,{curr_menu:'pop_Tab',pos:'setPosCenter',warp_y:-50})}function popFredDelComp(){$('pop_text').update('你已取消对方为好友！');$('pop_btn').show().update(pop_btn);popHide(1000)}function popHide(a){setTimeout(function(){$('pop_Tab').hide()},a)}function popPro(a,t,b){popWin({h:a,text:t,btn:b});Menu.init(null,{curr_menu:'pop_Tab',pos:'setPosCenter',warp_y:-50,DragDrop:{handle:'pop_h'}})}function popLoad(t){$('pop_btn').hide();$('pop_text').update(t)}function popLoaded(t){$('pop_btn').update(pop_btn).show();$('pop_text').update(t);popHide(1000)}