var Tooltip=Class.create({initialize:function(a,b,c){c=Object.extend({start_effect:function(){},end_effect:function(){},zindex:1E3,offset:{x:0,y:0},hook:{target:"topRight",tip:"bottomLeft"},trigger:false,DOM_location:false,className:false,delay:{}},c||{});this.target=$(a);this.tooltip=$(b);this.options=c;this.event_target=this.options.trigger?$(this.options.trigger):this.target;this.options.className&&this.tooltip.addClassName(this.options.className);this.tooltip.hide();this.display=false;this.mouse_over=
this.displayTooltip.bindAsEventListener(this);this.mouse_out=this.removeTooltip.bindAsEventListener(this);this.event_target.observe("mouseover",this.mouse_over);this.event_target.observe("mouseout",this.mouse_out)},displayTooltip:function(a){a.stop();if(!this.display)if(this.options.delay.start){var b=this;this.timer_id=setTimeout(function(){b.timer_id=false;b.showTooltip(a)},this.options.delay.start*1E3)}else this.showTooltip(a)},showTooltip:function(a){this.display=true;position=this.positionTooltip(a);
this.clone=this.tooltip.cloneNode(true);parentId=this.options.DOM_location?$(this.options.DOM_location.parentId):this.target.parentNode;successorId=this.options.DOM_location?$(this.options.DOM_location.successorId):this.target;parentId.insertBefore(this.clone,successorId);this.clone.setStyle({position:"absolute",top:position.top+"px",left:position.left+"px",display:"inline",zIndex:this.options.zindex});this.options.start_effect&&this.options.start_effect(this.clone)},positionTooltip:function(){target_position=
this.target.cumulativeOffset();tooltip_dimensions=this.tooltip.getDimensions();target_dimensions=this.target.getDimensions();this.positionModify(target_position,target_dimensions,this.options.hook.target,1);this.positionModify(target_position,tooltip_dimensions,this.options.hook.tip,-1);target_position.top+=this.options.offset.y;target_position.left+=this.options.offset.x;return target_position},positionModify:function(a,b,c,d){if(c=="topRight")a.left+=b.width*d;else if(c!="topLeft")if(c=="bottomLeft")a.top+=
b.height*d;else if(c=="bottomRight"){a.top+=b.height*d;a.left+=b.width*d}else if(c=="topMid")a.left+=b.width/2*d;else if(c=="leftMid")a.top+=b.height/2*d;else if(c=="bottomMid"){a.top+=b.height*d;a.left+=b.width/2*d}else if(c=="rightMid"){a.top+=b.height/2*d;a.left+=b.width*d}},removeTooltip:function(){if(this.timer_id){clearTimeout(this.timer_id);this.timer_id=false}else{this.options.end_effect&&this.options.end_effect(this.clone);if(this.options.delay.end){var a=this;setTimeout(function(){a.clearTooltip()},
this.options.delay.end*1E3)}else this.clearTooltip()}},clearTooltip:function(){this.clone.remove();this.clone=null;this.display=false},destroy:function(){this.event_target.stopObserving("mouseover",this.mouse_over);this.event_target.stopObserving("mouseout",this.mouse_out);this.clearTooltip()}});
