var Prototip={Version:"1.2.0_pre1",REQUIRED_Prototype:"1.6.0",REQUIRED_Scriptaculous:"1.8.0",start:function(){this.require("Prototype");Tips.initialize();Element.observe(window,"unload",this.unload)},require:function(A){if((typeof window[A]=="undefined")||(this.convertVersionString(window[A].Version)<this.convertVersionString(this["REQUIRED_"+A]))){throw ("Prototip requires "+A+" >= "+this["REQUIRED_"+A])}},convertVersionString:function(A){var B=A.split(".");return parseInt(B[0])*100000+parseInt(B[1])*1000+parseInt(B[2])},viewport:{getDimensions:function(){var A={};var C=Prototype.Browser;$w("width height").each(function(E){var B=E.capitalize();A[E]=(C.WebKit&&!document.evaluate)?self["inner"+B]:(C.Opera)?document.body["client"+B]:document.documentElement["client"+B]});return A}},capture:function(A){if(!Prototype.Browser.IE){A=A.wrap(function(D,C){var B=C.relatedTarget,E=C.currentTarget;if(B&&B.nodeType==Node.TEXT_NODE){B=B.parentNode}if(B&&B!=E&&B.descendantOf&&!(B.descendantOf(E))){D(C)}})}return A},unload:function(){Tips.removeAll()}};var Tips={closeButtons:false,zIndex:1200,tips:[],visible:[],initialize:function(){this.zIndexTop=this.zIndex},useEvent:(function(A){return{mouseover:(A?"mouseenter":"mouseover"),mouseout:(A?"mouseleave":"mouseout"),mouseenter:(A?"mouseenter":"mouseover"),mouseleave:(A?"mouseleave":"mouseout")}})(Prototype.Browser.IE),fixIE:(function(B){var A=new RegExp("MSIE ([\\d.]+)").exec(B);return A?(parseFloat(A[1])<=6):false})(navigator.userAgent),add:function(A){this.tips.push(A)},remove:function(A){var B=this.tips.find(function(C){return C.element==$(A)});if(B){B.deactivate();if(B.tooltip){B.wrapper.remove();if(Tips.fixIE){B.iframeShim.remove()}}this.tips=this.tips.without(B)}},removeAll:function(){this.tips.each(function(A){this.remove(A.element)}.bind(this))},raise:function(B){if(B.highest){return }if(this.visible.length==0){this.zIndexTop=this.zIndex;for(var A=0;A<this.tips.length;A++){this.tips[A].wrapper.style.zIndex=this.zIndex}}B.style.zIndex=this.zIndexTop++;for(var A=0;A<this.tips.length;A++){this.tips[A].wrapper.highest=false}B.highest=true},addVisibile:function(A){this.removeVisible(A);this.visible.push(A)},removeVisible:function(A){this.visible=this.visible.without(A)}};Tips.initialize();var Tip=Class.create({initialize:function(A,B){this.element=$(A);Tips.remove(this.element);this.content=B;var D=(arguments[2]&&arguments[2].hook);var C=(arguments[2]&&arguments[2].showOn=="click");this.options=Object.extend({className:"default",closeButton:Tips.closeButtons,delay:!C?0.2:false,duration:0.3,effect:false,hideAfter:false,hideOn:"mouseleave",hook:false,offset:D?{x:0,y:0}:{x:16,y:16},fixed:D?true:false,showOn:"mousemove",target:this.element,title:false,viewport:D?false:true},arguments[2]||{});this.target=$(this.options.target);this.setup();if(this.options.effect){Prototip.require("Scriptaculous");this.queue={position:"end",limit:1,scope:this.wrapper.identify()}}Tips.add(this);this.activate()},setup:function(){this.wrapper=new Element("div",{"class":"prototip"}).setStyle({display:"none",zIndex:Tips.zIndex});this.wrapper.identify();if(Tips.fixIE){this.iframeShim=new Element("iframe",{"class":"iframeShim",src:"javascript:false;"}).setStyle({display:"none",zIndex:Tips.zIndex-1})}this.tip=new Element("div",{"class":"content"}).insert(this.content);this.tip.insert(new Element("div").setStyle({clear:"both"}));if(this.options.closeButton||(this.options.hideOn.element&&this.options.hideOn.element=="closeButton")){this.closeButton=new Element("a",{href:"#","class":"close"})}},build:function(){if(Tips.fixIE){document.body.appendChild(this.iframeShim).setOpacity(0)}var D="wrapper";if(this.options.effect){this.effectWrapper=this.wrapper.appendChild(new Element("div",{"class":"effectWrapper"}));D="effectWrapper"}this.tooltip=this[D].appendChild(new Element("div",{"class":"tooltip "+this.options.className}));if(this.options.title||this.options.closeButton){this.toolbar=this.tooltip.appendChild(new Element("div",{"class":"toolbar"}));this.title=this.toolbar.appendChild(new Element("div",{"class":"title"}).update(this.options.title||" "))}this.tooltip.insert(this.tip);document.body.appendChild(this.wrapper);var A=(this.options.effect)?[this.wrapper,this.effectWrapper]:[this.wrapper];if(Tips.fixIE){A.push(this.iframeShim)}var C=this.wrapper.getWidth();A.invoke("setStyle",{width:C+"px"});if(this.toolbar){this.wrapper.setStyle({visibility:"hidden"}).show();this.toolbar.setStyle({width:this.toolbar.getWidth()+"px"});this.wrapper.hide().setStyle({visibility:"visible"})}if(this.closeButton){this.title.insert({top:this.closeButton}).insert(new Element("div").setStyle({clear:"both"}))}var B=this.wrapper.getHeight();A.invoke("setStyle",{width:C+"px",height:B+"px"});this[this.options.effect?D:"tooltip"].hide()},activate:function(){this.eventShow=this.showDelayed.bindAsEventListener(this);this.eventHide=this.hide.bindAsEventListener(this);if(this.options.fixed&&this.options.showOn=="mousemove"){this.options.showOn="mouseover"}if(this.options.showOn==this.options.hideOn){this.eventToggle=this.toggle.bindAsEventListener(this);this.element.observe(this.options.showOn,this.eventToggle)}var C={element:this.eventToggle?[]:[this.element],target:this.eventToggle?[]:[this.target],tip:this.eventToggle?[]:[this.wrapper],closeButton:[],none:[]};var A=this.options.hideOn.element;this.hideElement=A||(!this.options.hideOn?"none":"element");this.hideTargets=C[this.hideElement];if(!this.hideTargets&&A&&Object.isString(A)){this.hideTargets=this.tip.select(A)}var D={mouseenter:"mouseover",mouseleave:"mouseout"};$w("show hide").each(function(H){var G=H.capitalize();var F=(this.options[H+"On"].event||this.options[H+"On"]);this[H+"Action"]=F;if(["mouseenter","mouseleave","mouseover","mouseout"].include(F)){this[H+"Action"]=(Tips.useEvent[F]||F);this["event"+G]=Prototip.capture(this["event"+G])}}.bind(this));if(!this.eventToggle){this.element.observe(this.options.showOn,this.eventShow)}if(this.hideTargets){this.hideTargets.invoke("observe",this.hideAction,this.eventHide)}if(!this.options.fixed&&this.options.showOn=="click"){this.eventPosition=this.position.bindAsEventListener(this);this.element.observe("mousemove",this.eventPosition)}this.buttonEvent=this.hide.wrap(function(F,E){E.stop();F(E)}).bindAsEventListener(this);if(this.closeButton){this.closeButton.observe("click",this.buttonEvent)}if(this.options.showOn!="click"&&(this.hideElement!="element")){this.eventCheckDelay=Prototip.capture(function(){this.clearTimer("show")}).bindAsEventListener(this);this.element.observe(Tips.useEvent.mouseout,this.eventCheckDelay)}var B=[this.element,this.wrapper];this.activityEnter=Prototip.capture(function(){Tips.raise(this.wrapper);this.cancelHideAfter()}).bindAsEventListener(this);this.activityLeave=Prototip.capture(this.hideAfter).bindAsEventListener(this);B.invoke("observe",Tips.useEvent.mouseover,this.activityEnter);B.invoke("observe",Tips.useEvent.mouseout,this.activityLeave)},deactivate:function(){if(this.options.showOn==this.options.hideOn){this.element.stopObserving(this.options.showOn,this.eventToggle)}else{this.element.stopObserving(this.options.showOn,this.eventShow);if(this.hideTargets){this.hideTargets.invoke("stopObserving")}}if(this.eventPosition){this.element.stopObserving("mousemove",this.eventPosition)}if(this.closeButton){this.closeButton.stopObserving()}if(this.eventCheckDelay){this.element.stopObserving("mouseout",this.eventCheckDelay)}this.wrapper.stopObserving();this.element.stopObserving(Tips.useEvent.mouseover,this.activityEnter);this.element.stopObserving(Tips.useEvent.mouseout,this.activityLeave)},showDelayed:function(A){if(!this.tooltip){this.build()}this.position(A);if(this.wrapper.visible()){return }this.clearTimer("show");this.showTimer=this.show.bind(this).delay(this.options.delay)},clearTimer:function(A){if(this[A+"Timer"]){clearTimeout(this[A+"Timer"])}},show:function(){if(this.wrapper.visible()&&this.options.effect!="appear"){return }if(Tips.fixIE){this.iframeShim.show()}Tips.addVisibile(this.wrapper);this.wrapper.show();if(!this.options.effect){this.tooltip.show()}else{if(this.activeEffect){Effect.Queues.get(this.queue.scope).remove(this.activeEffect)}this.activeEffect=Effect[Effect.PAIRS[this.options.effect][0]](this.effectWrapper,{duration:this.options.duration,queue:this.queue})}},hideAfter:function(A){if(!this.options.hideAfter){return }this.cancelHideAfter();this.hideAfterTimer=this.hide.bind(this).delay(this.options.hideAfter)},cancelHideAfter:function(){if(this.options.hideAfter){this.clearTimer("hideAfter")}},hide:function(){this.clearTimer("show");if(!this.wrapper.visible()){return }if(!this.options.effect){if(Tips.fixIE){this.iframeShim.hide()}this.tooltip.hide();this.wrapper.hide();Tips.removeVisible(this.wrapper)}else{if(this.activeEffect){Effect.Queues.get(this.queue.scope).remove(this.activeEffect)}this.activeEffect=Effect[Effect.PAIRS[this.options.effect][1]](this.effectWrapper,{duration:this.options.duration,queue:this.queue,afterFinish:function(){if(Tips.fixIE){this.iframeShim.hide()}this.wrapper.hide();Tips.removeVisible(this.wrapper)}.bind(this)})}},toggle:function(A){if(this.wrapper&&this.wrapper.visible()){this.hide(A)}else{this.showDelayed(A)}},position:function(A){Tips.raise(this.wrapper);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"topMiddle":L[H][0]+=(K[H].width/2);break;case"rightMiddle":L[H][0]+=K[H].width;L[H][1]+=(K[H].height/2);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;case"bottomMiddle":L[H][0]+=(K[H].width/2);L[H][1]+=K[H].height;break;case"leftMiddle":L[H][1]+=(K[H].height/2);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=document.viewport.getScrollOffsets();var G=Prototip.viewport.getDimensions();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]}}}var M={left:I.left+"px",top:I.top+"px"};this.wrapper.setStyle(M);if(Tips.fixIE){this.iframeShim.setStyle(M)}}});
