/*1306443779,169776069*/

if (window.CavalryLogger) { CavalryLogger.start_js(["hipy9"]); }

add_properties('Hovercard',{ARROW_LEFT_OFFSET:32,RESERVED_WIDTH:297,RESERVED_HEIGHT:237,cache:{},lastEndpoint:null,isShowing:false,fetchDelay:200,showDelay:1250,loadingDelay:1750,hideDelay:250,fetchTimer:null,showTimer:null,loadingTimer:null,hideTimer:null,build:function(){this.build=bagofholding;var a=$N('div',{className:'arrow'},$N('i'));this.loading=$N('div',{className:'loading'},_tx("Cargando..."));this.stage=$N('div',{className:'stage'},this.loading);this.preload=$N('div',{id:'hovercardPreload'});this.overlay=$N('div',{className:'HovercardOverlay'});this.container=$N('div',{className:'hovercard clearfix'},[this.stage,a]);Event.listen(this.container,'mouseout',bind(this,'hide',false));Event.listen(this.container,'mouseover',function(){clearTimeout(this.hideTimer);}.bind(this));Arbiter.subscribe('page_transition',function(){this.hide(true);this.dirty();}.bind(this),Arbiter.SUBSCRIBE_NEW);Arbiter.subscribe('new_layer',this.hide.shield(this,true),Arbiter.SUBSCRIBE_NEW);document.body.appendChild(this.preload);document.body.insertBefore(this.overlay,document.body.firstChild);},process:function(b){var d=Event.listen(b,'mouseout',function(){clearTimeout(this.fetchTimer);clearTimeout(this.showTimer);d.remove();this.hide();}.bind(this));if(!this.active.moveToken)this.active.moveToken=Event.listen(b,'mousemove',function(event){this.active.pos=Vector2.getEventPosition(event);}.bind(this));clearTimeout(this.fetchTimer);clearTimeout(this.showTimer);clearTimeout(this.hideTimer);var a=this.fetchDelay;var c=this.isShowing?this.hideDelay:this.showDelay;if(b.getAttribute('data-hovercard-instant'))a=c=100;this.fetchTimer=setTimeout(this.fetch.bind(this,b),a);this.showTimer=setTimeout(this.show.bind(this,b),c);},show:function(c,b){this.build();if(this.active.node!=c)return;var a;if(this.cache[this.getEndpoint(c)]){a=this.cache[this.getEndpoint(c)];}else if(b){a={content:'',node:this.loading};}else{var d=this.isShowing?this.hideDelay:this.showDelay;this.loadingTimer=setTimeout(this.show.bind(this,c,true),this.loadingDelay-d);}a&&this.update(a);},hide:function(a){if(a){var b=this.container&&this.container.parentNode;b&&b.removeChild(this.container);this.isShowing=false;}else this.hideTimer=setTimeout(this.hide.bind(this,true),this.hideDelay);},update:function(a){if(this.stage.firstChild)this.stage.removeChild(this.stage.firstChild);var b=a.node||HTML(a.content).getRootNode();var d=b&&b.getAttribute('data-hovercard-layout');if(d)this.container.className='hovercard '+d;var e=this.active.node;var c=this.getEndpoint(e);if(c!=this.lastEndpoint)(function(){new AsyncSignal('/ajax/hovercard/shown.php').send();user_action(e,'himp',null,'FORCE',{ft:{evt:39}});}).defer();this.stage.appendChild(b);this.position(e,e.getAttribute('data-hovercard-fixed'));this.overlay.appendChild(this.container);this.lastEndpoint=c;this.isShowing=true;},position:function(f,e){if(!this.wCheck&&e){this.wCheck=$N('div',{className:'HovercardWidthCheck'});document.body.appendChild(this.wCheck);}var h;var c=this.wCheck&&e?this.wCheck.offsetWidth:0;var b=this.getBounds(f);var i=b.getPositionVector().convertTo('viewport');var a=i.y<this.RESERVED_HEIGHT;var j=Vector2.getViewportDimensions();var g=(c||j.x)<this.RESERVED_WIDTH+b.l;var d=g?c-b.r:b.l;if(b.w()<2*this.ARROW_LEFT_OFFSET)d+=b.w()/2-this.ARROW_LEFT_OFFSET;if(a){h=e?i.y+b.h():b.b;}else h=e?j.y-i.y:-b.t;CSS.conditionClass(this.container,'HovercardFromRight',g);CSS.conditionClass(this.container,'HovercardBelow',a);CSS.conditionClass(this.container,'HovercardFixed',e);CSS.setStyle(this.container,(g?'right':'left'),d+'px');CSS.setStyle(this.container,(g?'left':'right'),'auto');CSS.setStyle(this.container,(a?'top':'bottom'),h+'px');CSS.setStyle(this.container,(a?'bottom':'top'),'auto');},getBounds:function(e){var a=this.active.pos;var h=e.getClientRects();if(!a||h.length===0)return Rect.getElementBounds(e);var b;var c=false;for(var d=0;d<h.length;d++){var g=new Rect(Math.round(h[d].top),Math.round(h[d].right),Math.round(h[d].bottom),Math.round(h[d].left),'viewport').convertTo('document');var f=g.getPositionVector();var i=f.add(g.getDimensionVector());if(!b||(f.x<=b.l&&f.y>b.t)){if(c)break;b=new Rect(f.y,i.x,i.y,f.x,'document');}else{b.t=Math.min(b.t,f.y);b.b=Math.max(b.b,i.y);b.r=i.x;}if(g.contains(a))c=true;}return b;},fetch:function(d,a){a=typeof a==='function'?a:bagofholding;if(d.id&&this.cache[d.id]!=null)return a();var b=this.getEndpoint(d);if(this.cache[b]!=null)return a();this.setFetchInProgress(b);var c=function(){this.dirty(b);this.hide(true);clearTimeout(this.showTimer);clearTimeout(this.loadingTimer);}.bind(this);new AsyncRequest(b).setMethod('GET').setReadOnly(true).setHandler(function(f){var e=f.getPayload();if(!e||!e.content){c();return;}this.setCache(b,e);}.bind(this)).setErrorHandler(c).setTransportErrorHandler(c).setFinallyHandler(a).send();},setFetchInProgress:function(a){this.cache[a]=false;},setCache:function(b,a){this.build();this.cache[b]=a;if(this.active.endpoint==b&&this.isShowing){this.update(a);}else{var c=HTML(a.content).getRootNode();a.node=c;DOM.appendContent(this.preload,c);}},dirty:function(b){var a;if(b){a=this.cache[b];var d=a.node&&a.node.parentNode;d&&d.removeChild(node);delete this.cache[b];}else for(var c in this.cache){a=this.cache[c];if(a&&!a.cachepermanently){var d=a.node&&a.node.parentNode;d&&d.removeChild(a.node);delete this.cache[c];}}}});
var HovercardLoader={loadAll:function(a){a=$(a||'content');var e={};var g={};var c=DOM.scry(a,'a[data-hovercard]');for(var f=0;f<c.length;f++){var d=c[f].getAttribute('data-hovercard');if(Hovercard.cache[d]==null){var b=URI(d).getQueryData();if(b.id){e[d]=b.id;if(b.type)g[b.id]=b.type;}}}if(!is_empty(e))this._multifetch(e,g);},_multifetch:function(b,e){var f=[];var g={};for(var a in b){var d=b[a];f.push(d);g[d]=a;Hovercard.setFetchInProgress(a);}var c=function(){keys(b).each(Hovercard.dirty.bind(Hovercard));};new AsyncRequest('/ajax/hovercard/multifetch.php').setData({ids:f,id_type_map:e}).setHandler(function(j){var i=j.getPayload();for(var h in g)if(i[h])Hovercard.setCache(g[h],{content:i[h]});}).setErrorHandler(c).setTransportErrorHandler(c).send();}};
