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 b=Prototype.Browser;$w("width height").each(function(e){var c=e.capitalize();a[e]=(b.WebKit&&!document.evaluate)?self["inner"+c]:(b.Opera)?document.body["client"+c]:document.documentElement["client"+c]});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)}}});Prototip.start();
