Tipper=Class.create({element:null,tooltip:null,timerShow:null,timerHide:null,state:"hidden",isAnimating:false,stylesheet:"stylesheets/tipper.css",initialize:function(b,a){var c=-1;if(navigator.appName=="Microsoft Internet Explorer"){if(new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})").exec(navigator.userAgent)!=null){c=parseFloat(RegExp.$1)}}if(0<c&&c<7){return}this.element=$(b);if(!this.element){throw (s2.fx.elementDoesNotExistError);return false}this.options=Object.extend({duration:0.2,delayShow:0.5,delayHide:0.7,position:"auto"},a);this.render()},render:function(){if(this.element.title.blank()){return}this.back=new Element("span").addClassName("back");this.fin=new Element("span");this.cont=new Element("span").addClassName("cont").addClassName(this.element.readAttribute("lang")).writeAttribute("lang",this.element.readAttribute("lang")).update(this.element.title);this.tooltip=new Element("div").addClassName("tt").setOpacity(0).hide().insert(this.fin).insert(this.back).insert(this.cont);this.viewport=($("viewport"))?$("viewport"):new Element("div",{id:"viewport"});$(document.body).insert(this.viewport.insert(this.tooltip));this.element.title="";var f=this.element.cumulativeOffset();var d=this.element.getDimensions();var a=this.tooltip.getDimensions();var b=this.element.getStyle("position")=="fixed"||this.element.ancestors().find(function(k){return k.getStyle("position")=="fixed"});if(this.options.position=="auto"){this.position="right"}else{this.position=this.options.position}var h=0,g=0,j=12,e={},c={},i;switch(this.position){case"top":i="bottom";h=f.left-(a.width-d.width)/2;g=f.top-a.height-j;break;case"left":i="right";h=f.left-a.width-j;g=f.top-(a.height-d.height)/2;break;case"bottom":i="top";h=f.left-(a.width-d.width)/2;g=f.top+d.height;break;case"right":i="left";h=f.left+d.width;g=f.top-(a.height-d.height)/2;break}e.left=h.round()+"px";e.top=g.round()+"px";e["margin"+i.capitalize()]=j+"px";e.position=(b)?"fixed":"absolute";this.tooltip.setStyle(e);this.fin.addClassName(i.charAt(0)+"fin");this.element.observe("mouseenter",this.onHover.bindAsEventListener(this));this.element.observe("mouseleave",this.onBlur.bindAsEventListener(this))},onHover:function(a){if(this.timerHide){clearTimeout(this.timerHide)}this.timerShow=setTimeout(this.showTooltip.bind(this),this.options.delayShow*1000)},onBlur:function(a){if(this.timerShow){clearTimeout(this.timerShow)}this.timerHide=setTimeout(this.hideTooltip.bind(this),this.options.delayHide*1000)},showTooltip:function(){this.tooltip.morph("opacity:1",{before:function(){this.isAnimating=true;this.tooltip.show()}.bind(this),after:function(){this.isAnimating=false;this.state="visible"}.bind(this),duration:this.options.duration})},hideTooltip:function(){this.tooltip.morph("opacity:0",{before:function(){this.isAnimating=true}.bind(this),after:function(){this.isAnimating=false;this.state="hidden";this.tooltip.hide()}.bind(this),duration:this.options.duration})}});
