var Tips={tips:[],zIndex:1200,add:function(a){this.tips.push(a)},remove:function(a){var b=this.tips.find(function(c){return c.element==$(a)});if(b){this.tips=this.tips.reject(function(c){return c==b});b.deactivate();b.tooltip&&b.wrapper.remove();b.underlay&&b.underlay.remove()}}},Tip=Class.create();
Tip.prototype={initialize:function(a,b,c){this.element=$(a);Tips.remove(this.element);this.content=b;this.options=Object.extend({className:"tooltip",duration:0.3,effect:false,hook:false,offset:c&&c.hook?{x:0,y:0}:{x:16,y:16},fixed:false,target:this.element,title:false,viewport:true},c||{});this.target=$(this.options.target);if(this.options.hook){this.options.fixed=true;this.options.viewport=false}if(this.options.effect){this.queue={position:"end",limit:1,scope:""};a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
for(b=0;b<6;b++){c=Math.floor(Math.random()*a.length);this.queue.scope+=a.substring(c,c+1)}}this.buildWrapper();Tips.add(this);this.activate()},activate:function(){this.eventShow=this.showTip.safeBind(this);this.eventHide=this.hideTip.safeBind(this);this.element.observe("mousemove",this.eventShow);this.element.observe("mouseout",this.eventHide)},deactivate:function(){this.element.stopObserving("mousemove",this.eventShow);this.element.stopObserving("mouseout",this.eventHide)},buildWrapper:function(){this.wrapper=
document.createElement("div");Element.setStyle(this.wrapper,{position:"absolute",zIndex:Tips.zIndex+1,display:"none"});if(Prototype.Browser.IE){this.underlay=document.createElement("iframe");this.underlay.src="javascript:;";Element.setStyle(this.underlay,{position:"absolute",display:"none",border:0,margin:0,opacity:0.01,padding:0,background:"none",zIndex:Tips.zIndex})}},buildTip:function(){Prototype.Browser.IE&&document.body.appendChild(this.underlay);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"});Prototype.Browser.IE&&this.underlay.setStyle({width:a.width+"px",height:a.height+"px"});Element.hide(this.tooltip)},showTip:function(a){this.tooltip||this.buildTip();this.positionTip(a);if(!(this.wrapper.visible()&&this.options.effect!="appear")){Prototype.Browser.IE&&this.underlay.show();this.wrapper.show();if(this.options.effect){this.activeEffect&&Effect.Queues.get(this.queue.scope).remove(this.activeEffect);this.activeEffect=Effect[Effect.PAIRS[this.options.effect][0]](this.tooltip,{duration:this.options.duration,
queue:this.queue})}else this.tooltip.show()}},hideTip:function(){if(this.wrapper.visible())if(this.options.effect){this.activeEffect&&Effect.Queues.get(this.queue.scope).remove(this.activeEffect);this.activeEffect=Effect[Effect.PAIRS[this.options.effect][1]](this.tooltip,{duration:this.options.duration,queue:this.queue,afterFinish:function(){Prototype.Browser.IE&&this.underlay.hide();this.wrapper.hide()}.bind(this)})}else{Prototype.Browser.IE&&this.underlay.hide();this.tooltip.hide();this.wrapper.hide()}},
positionTip:function(a){var b={left:this.options.offset.x,top:this.options.offset.y},c=Position.cumulativeOffset(this.target),g=this.wrapper.getDimensions();a={left:this.options.fixed?c[0]:Event.pointerX(a),top:this.options.fixed?c[1]:Event.pointerY(a)};a.left+=b.left;a.top+=b.top;if(this.options.hook){var f={target:this.target.getDimensions(),tip:g},e={target:Position.cumulativeOffset(this.target),tip:Position.cumulativeOffset(this.target)};for(var d in e)switch(this.options.hook[d]){case "topRight":e[d][0]+=
f[d].width;break;case "bottomLeft":e[d][1]+=f[d].height;break;case "bottomRight":e[d][0]+=f[d].width;e[d][1]+=f[d].height;break}a.left+=-1*(e.tip[0]-e.target[0]);a.top+=-1*(e.tip[1]-e.target[1])}if(!this.options.fixed&&this.element!==this.target){f=Position.cumulativeOffset(this.element);a.left+=-1*(f[0]-c[0]);a.top+=-1*(f[1]-c[1])}if(!this.options.fixed&&this.options.viewport){c=this.getScrollOffsets();f=this.viewportSize();e={left:"width",top:"height"};for(d in e)if(a[d]+g[e[d]]-c[d]>f[e[d]])a[d]=
a[d]-g[e[d]]-2*b[d]}this.wrapper.setStyle({left:a.left+"px",top:a.top+"px"});Prototype.Browser.IE&&this.underlay.setStyle({left:a.left+"px",top:a.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,b=$A(arguments),c=b.shift();return function(){if(typeof $A=="function")return a.apply(c,b.concat($A(arguments)))}};
Event.observe(window,"load",function(){var a=$$("delete");a.each(function(b){new Tip(b,"Eintrag l&ouml;schen!");return false});a=$$("edit");a.each(function(b){new Tip(b,"Eintrag editieren!");return false})});
