var tipclick = {
	vertical_offset : '-81px',

	//I added horizontal_offset as a parameter to the show function
	//horizontal_offset : '-100px',
	delay_disappear : 200,
	delay_appear : 100,

	show : function(content, obj, e, h_offset) {
		this.horizontal_offset = h_offset;
		if (window.event) { 
			event.cancelBubble=true;
		} else if (e.stopPropagation) {
			e.stopPropagation();
		}
		this._do_hide();
		var tooltip = document.getElementById("tipclick_div");
		tooltip.innerHTML = content;
		if ((e.type == "click" && tooltip.style.visibility == 'hidden') || e.type == "mouseover") {
			var self = this;
			this._show_handler = setTimeout(function() {self._do_show();}, this.delay_appear);
		} else if (e.type=="click") {
			tooltip.style.visibility = 'hidden';
		}
		tooltip.x = this._get_pos_offset(obj, true);
		tooltip.y = this._get_pos_offset(obj, false);
		tooltip.style.left = tooltip.x - this._clear_browser_edge(obj, true) + "px";
		tooltip.style.top = tooltip.y - this._clear_browser_edge(obj, false) + obj.offsetHeight + "px";
		return true;
	},


	show_cust : function(content, obj, e, h_offset,str_Search,str_Listen,lang,textlp,stripped_piece,piece,underscore_escaped_piece,speakercounter,version,audiblelang) {
		this.horizontal_offset = h_offset;
		if (window.event) { 
			event.cancelBubble=true;
		} else if (e.stopPropagation) {
			e.stopPropagation();
		}
		this._do_hide();
		var tooltip = document.getElementById("tipclick_div");

		intermediateHTML = '<div class="results"><table class="results"><tbody class="results"><tr valign="middle"><td>' + str_Search + ': ';
		intermediateHTML += '</td><td><a href="lookup.php?lang=' + lang + '&lp=' + textlp + '&q=' + stripped_piece + '">' + piece + '</a></td></tr>'; 
		intermediateHTML += '<tr><td valign="middle">' + str_Listen + ': ';
		intermediateHTML += '</td><td valign="middle"><span id=soundspan></span><a href=\'/audibles/' + audiblelang + '/all/' + underscore_escaped_piece + '.' + version + '.mp3\' onclick="event.returnValue = false; return false;")"><img border=0 name="speaker' + speakercounter + '" id="speaker' + speakercounter + '" alt="Listen" title="' + str_Listen + '" src="images/speakernavy.gif" width="17" height="18" onClick="DHTMLSound(\'/audibles/' + audiblelang + '/all/' + underscore_escaped_piece + '.' + version + '.mp3\')"></a></td></tr></tbody></table></div>';

		tooltip.innerHTML = intermediateHTML;

		if ((e.type == "click" && tooltip.style.visibility == 'hidden') || e.type == "mouseover") {
			var self = this;
			this._show_handler = setTimeout(function() {self._do_show();}, this.delay_appear);
		} else if (e.type=="click") {
			tooltip.style.visibility = 'hidden';
		}
		tooltip.x = this._get_pos_offset(obj, true);
		tooltip.y = this._get_pos_offset(obj, false);
		tooltip.style.left = tooltip.x - this._clear_browser_edge(obj, true) + "px";
		tooltip.style.top = tooltip.y - this._clear_browser_edge(obj, false) + obj.offsetHeight + "px";
		return true;
	},

	hide : function() {
		this._must_hide = true;
		var self = this;
 		this._hide_handler = setTimeout(function() { self._do_hide(); }, this.delay_disappear);
 		return true;
	},
	
	//---Private
	_show_handler : null,
	_hide_handler : null,
	_must_hide : true,

	_clear_tip : function() {
		if (typeof this._hide_handler != "undefined" || this._hide_handler !== null) {
			clearTimeout(this._hide_handler);
			delete(this._hide_handler);
		}
		if (typeof this._show_handler != "undefined" || this._show_handler !== null) {
			clearTimeout(this._show_handler);
			delete(this._show_handler);
		}
	},
	
	_get_pos_offset : function(what, is_left) {
		var total_offset = (is_left) ? what.offsetLeft : what.offsetTop;
		var parentEl = what.offsetParent;
		while (parentEl !== null) {
			total_offset = (is_left) ? total_offset + parentEl.offsetLeft : total_offset + parentEl.offsetTop;
			parentEl = parentEl.offsetParent;
		}
		return total_offset;
	},
	
	_clear_browser_edge : function(obj, is_horizontal) {
		var tooltip = document.getElementById("tipclick_div");
		var edge_offset = (is_horizontal) ? parseInt(this.horizontal_offset, 10)*-1 : parseInt(this.vertical_offset, 10)*-1;
		var is_ie = document.all && !window.opera;
		var window_edge, content_measure;
		if (is_ie) {
			var ie_body = this._ie_body();
		}
		if (is_horizontal) {
			window_edge = is_ie ? ie_body.scrollLeft + ie_body.clientWidth-15 : window.pageXOffset+window.innerWidth-15;
			content_measure = tooltip.offsetWidth;
			if (window_edge - tooltip.x < content_measure) {
				edge_offset= content_measure - obj.offsetWidth;
			}
		} else {
			window_edge = is_ie ? ie_body.scrollTop + ie_body.clientHeight-15 : window.pageYOffset+window.innerHeight-18;
			content_measure= tooltip.offsetHeight;
			if (window_edge - tooltip.y < content_measure) {
				edge_offset = content_measure + obj.offsetHeight;
			}
		}
		return edge_offset;
	},
	
 	_ie_body : function() {
 		return (document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body;
	 },
	 
 	_do_show : function() {
	 	document.getElementById("tipclick_div").style.visibility="visible";
 	},
 	
 	_do_hide : function() {
 		if (this._must_hide) {
			document.getElementById("tipclick_div").style.visibility="hidden";
 		}
		this._clear_tip();
 	},
 	
 	_continue : function() {
 		this._must_hide = false;
 	},
 	
 	_stop : function() {
 		this._must_hide = true;
 		this.hide();
 	}
};

