
// This script is written by john king and all rights remain with john king.
// Permission is to be obtained before using this script.

	active_status = "unset";
var ktooltip = Class.create({
							
	ktooltiphooktype: '[datatitle]',
	
	ktooltipevent1: 'mouseover',
	
	ktooltipevent2: 'mouseout',
	
	ktooltiptype: 'div',
	
	kclassname: 'balloonstyle',
	
	k_attachto: 'body',
	
	k_show_delay: 250,
	
	_timer: "stopped",
	
	initialize: function(name) {
		
		this.k_create_tooltip(this.k_attachto);
		
		this.ktooltiphook = $$(this.ktooltiphooktype);
		
		this.ktooltiphook.each(function(e) {
										
			e.observe(this.ktooltipevent1 , this.k_hook_mouseover.bind(this));
		
			e.observe(this.ktooltipevent2 , this.k_hook_mouseout.bind(this));
		
		}.bind(this));
		
		this.setTimer;
		
		this.resetTimer;
		
	},
	
	k_create_tooltip: function(k_attachment) {
		
		this.ktooltipdiv = new Element(this.ktooltiptype, { 'id': 'mytip' , 'class': this.kclassname , 'style': 'display: none;'});
		this.ktooltipdiv1 = new Element('div', { 'id': 'mytip_title' });
		this.ktooltipdiv2 = new Element('div', { 'id': 'mytip_text' });
		this.ktooltipdiv3 = new Element('img', { 'id': 'mytip_arrowhead' , 'src': '/~bestresu/includes/images/dialog_down_pointer.gif' });
		$$(k_attachment).first().insert(this.ktooltipdiv);
		
	},
	
	k_hook_mouseover: function(e) {
			
		this._timer = setTimeout( this.k_show_tooltip.bind(this, e) , this.k_show_delay);
	
	},
		
	k_show_tooltip: function(e) {
			
		k_eventid3 = "undefined"	
			
		k_eventid = Event.element(e);
		
		k_eventid2 = $(k_eventid.readAttribute('dataleft'));
		
		if(k_eventid.readAttribute('dataoffset') && Prototype.Browser.IE && !Prototype.Browser.IE7) {
			k_eventid3 = k_eventid;
			k_eventid = $(k_eventid.readAttribute('dataoffset'));
		}
		
		k_container = $$(k_eventid.readAttribute('datacontainer')).first();
		
		k_title = k_eventid.readAttribute('datatitle');
		
		k_text = k_eventid.readAttribute('data');
		
		if(k_title)	this.ktooltipdiv.insert(this.ktooltipdiv1.update(k_title));
		if(k_text) this.ktooltipdiv.insert(this.ktooltipdiv2.update(k_text));
		this.ktooltipdiv.insert(this.ktooltipdiv3);
		//this.ktooltipdiv;
		k_ie6_extras = 0;
		if(Prototype.Browser.IE && !Prototype.Browser.IE7) {
			if(k_eventid3 != "undefined") {
				k_ie6_extras = (k_eventid.getWidth() + (k_eventid.cumulativeOffset()[0]-k_eventid2.cumulativeOffset()[0])) - (k_eventid.cumulativeOffset()[0]-k_eventid3.cumulativeOffset()[0]);
			}
			else k_ie6_extras = (k_eventid.getWidth() + (k_eventid.cumulativeOffset()[0]-k_eventid2.cumulativeOffset()[0]));
		}
		
		k_max_width = (k_container.cumulativeOffset()[0]+k_container.getWidth()) - k_eventid2.cumulativeOffset()[0]-30 - k_ie6_extras;
		
		if(this.ktooltipdiv.getWidth() > k_max_width) {	
			this.ktooltipdiv.setStyle( {
				'width': k_max_width+"px"
			});
		}
		k_position1 = (k_eventid2.cumulativeOffset()[0]-10) + this.ktooltipdiv.getWidth();
		k_position2 = k_eventid.cumulativeOffset()[0]+k_eventid.getWidth()+30;
		
		if(k_position1 < k_position2) k_xoffset = k_position2 - this.ktooltipdiv.getWidth();
		else k_xoffset = k_eventid2.cumulativeOffset()[0]-10;
		
		k_yoffset = -3-(this.ktooltipdiv.getHeight()+k_eventid.getHeight());
		if (Prototype.Browser.IE) k_yoffset = k_yoffset - parseInt(k_eventid.getStyle('margin-top'.gsub('px', '')))+4;
		
		k_x = k_xoffset;
		k_y = k_eventid.cumulativeOffset()[1] + k_yoffset;
		k_width = k_eventid.getWidth();
		k_height = this.ktooltipdiv.getHeight();
				
		if(Prototype.Browser.IE && !Prototype.Browser.IE7) k_x = k_x+k_ie6_extras;
			
		this.ktooltipdiv.setStyle( {
			'left': k_x+"px",
			'top': k_y+"px"
		});
				
		this.ktooltipdiv.show();
		
		k_anchor_offset = ( k_eventid.cumulativeOffset()[0] + k_eventid.getWidth() ) - this.ktooltipdiv.cumulativeOffset()[0];
		
		this.ktooltipdiv3.setStyle( {
			'left': k_anchor_offset+k_ie6_extras+"px",
			'top': k_height+"px",
			'width': "15px"
		});
		
	},
	
	k_hook_mouseout: function(e) {
		
		clearTimeout(this._timer);
		
		this.ktooltipdiv.update("").setStyle( {
			'left': "-500px",
			'top': "-500px",
			'width': ""
		});
		
		this.ktooltipdiv.hide();
		
	}
	
});