var Tip=Class.create();Tip.prototype={zIndex:1200,visible:false,initialize:function(B,D){this.element=$(B);this.content=D;this.options=Object.extend({className:"tooltip",duration:0.3,effect:false,hook:false,offset:(arguments[2]&&arguments[2].hook)?{x:0,y:0}:{x:16,y:16},fixed:false,target:this.element,title:false,viewport:true},arguments[2]||{});this.target=$(this.options.target);if(this.options.hook){this.options.fixed=true;this.options.viewport=false}if(this.options.effect){this.scope="";var E="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";for(var A=0;A<6;A++){var C=Math.floor(Math.random()*E.length);this.scope+=E.substring(C,C+1)}}this.setup()},setup:function(){this.element.observe("mousemove",this.showTip.safeBind(this));this.element.observe("mouseout",this.hideTip.safeBind(this))},buildTip:function(){if(Prototype.Browser.IE){this.underlay=document.createElement("iframe");Element.setStyle(this.underlay,{position:"absolute",display:"none",border:0,margin:0,opacity:0.01,padding:0,background:"none",zIndex:this.zIndex});document.body.appendChild(this.underlay)}this.wrapper=document.createElement("div");Element.setStyle(this.wrapper,{position:"absolute",zIndex:this.zIndex+1,display:"none"});if(this.options.width){this.wrapper.setStyle({width:this.options.width+"px"})}this.tooltip=this.wrapper.appendChild(document.createElement("div"));this.tooltip.className=this.options.className;this.tooltip.style.position="relative";if(this.options.title){this.title=this.tooltip.appendChild(document.createElement("div"));this.title.className="title";Element.update(this.title,this.options.title)}this.tip=this.tooltip.appendChild(document.createElement("div"));this.tip.className="content";Element.update(this.tip,this.content);document.body.appendChild(this.wrapper);var A=this.wrapper.getDimensions();this.wrapper.setStyle({width:A.width+"px",height:A.height+"px"});if(Prototype.Browser.IE){this.underlay.setStyle({width:A.width+"px",height:A.height+"px"})}Element.hide(this.tooltip);Element.show(this.wrapper)},showTip:function(A){if(!this.wrapper){this.buildTip()}this.positionTip(A);if(this.visible){return }if(Prototype.Browser.IE){this.underlay.show()}this.wrapper.show();this.visible=true;if(!this.options.effect){this.tooltip.show()}else{this.tooltip.visualEffect(Effect.PAIRS[this.options.effect][0],{duration:this.options.duration,queue:{scope:this.scope,position:"end"}})}},hideTip:function(A){if(!this.visible){return }if(!this.options.effect){if(Prototype.Browser.IE){this.underlay.hide()}this.tooltip.hide();this.wrapper.hide();this.visible=false}else{this.tooltip.visualEffect(Effect.PAIRS[this.options.effect][1],{duration:this.options.duration,queue:{scope:this.scope,position:"end"},afterFinish:function(){if(Prototype.Browser.IE){this.underlay.hide()}this.wrapper.hide();this.visible=false}.bind(this)})}},positionTip:function(A){var E={left:this.options.offset.x,top:this.options.offset.y};var F=Position.cumulativeOffset(this.target);var B=this.wrapper.getDimensions();var I={left:(this.options.fixed)?F[0]:Event.pointerX(A),top:(this.options.fixed)?F[1]:Event.pointerY(A)};I.left+=E.left;I.top+=E.top;if(this.options.hook){var K={target:this.target.getDimensions(),tip:B};var L={target:Position.cumulativeOffset(this.target),tip:Position.cumulativeOffset(this.target)};for(var H in L){switch(this.options.hook[H]){case"topRight":L[H][0]+=K[H].width;break;case"bottomLeft":L[H][1]+=K[H].height;break;case"bottomRight":L[H][0]+=K[H].width;L[H][1]+=K[H].height;break}}I.left+=-1*(L.tip[0]-L.target[0]);I.top+=-1*(L.tip[1]-L.target[1])}if(!this.options.fixed&&this.element!==this.target){var C=Position.cumulativeOffset(this.element);I.left+=-1*(C[0]-F[0]);I.top+=-1*(C[1]-F[1])}if(!this.options.fixed&&this.options.viewport){var J=this.getScrollOffsets();var G=this.viewportSize();var D={left:"width",top:"height"};for(var H in D){if((I[H]+B[D[H]]-J[H])>G[D[H]]){I[H]=I[H]-B[D[H]]-2*E[H]}}}this.wrapper.setStyle({left:I.left+"px",top:I.top+"px"});if(Prototype.Browser.IE){this.underlay.setStyle({left:I.left+"px",top:I.top+"px"})}},viewportWidth:function(){if(Prototype.Browser.Opera){return document.body.clientWidth}return document.documentElement.clientWidth},viewportHeight:function(){if(Prototype.Browser.Opera){return document.body.clientHeight}if(Prototype.Browser.WebKit){return this.innerHeight}return document.documentElement.clientHeight},viewportSize:function(){return{height:this.viewportHeight(),width:this.viewportWidth()}},getScrollLeft:function(){return this.pageXOffset||document.documentElement.scrollLeft},getScrollTop:function(){return this.pageYOffset||document.documentElement.scrollTop},getScrollOffsets:function(){return{left:this.getScrollLeft(),top:this.getScrollTop()}}};Function.prototype.safeBind=function(){var A=this,C=$A(arguments),B=C.shift();return function(){if(typeof $A=="function"){return A.apply(B,C.concat($A(arguments)))}}};