
tooltip = {
	init : function() {
		$('.tooltip')
			.mouseover(function(){
				tooltip.show(this);
			})
			.mouseout(function(){
				tooltip.hide();
			})
	},
	
	timer : false,

	show : function (_this, txt) {	
		clearTimeout(this.timer);

		var de = document.documentElement;
		var screen = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
		screen = screen - _this.offsetLeft;
		var offset = $(_this).offset();
		
		if(!this.gebi('tooltip')) {
			$('body').append('<div id="tooltip" class="ttip ttip-ne" style="visibility:hidden;"><table class="ttip"><tr><td class="ttip-11 png"><div></div></td><td class="ttip-12 pngscale"><div></div></td><td class="ttip-13 png"><div></div></td></tr><tr><td class="ttip-21 pngscale"><div></div></td><td class="ttip-22"><div id="ttip_content"></div></td><td class="ttip-23 pngscale"><div></div></td></tr><tr><td class="ttip-31 png"><div></div></td><td class="ttip-32 pngscale"><div></div></td><td class="ttip-33 png"><div></div></td></tr></table><div class="ttip-spacer png"></div><iframe class="tooltip"></iframe></div>');
		} else {
			$('#tooltip').css({ display:'block' });
		}
		
		var o = this.gebi('tooltip');
		var content = this.gebi('ttip_content');
		var source = this.gebi(_this.id + '_content');
		
		if (source && source.style.width) {
			content.style.width = source.style.width;
		} else {
			content.style.width = 170 + 'px';
		}
		
		$(o).css({ left: 0, top: 0 });
		
		this.gebi('ttip_content').innerHTML = source ? source.innerHTML : txt;
		
		var oheight = o.offsetHeight + 8;
		var owidth = o.offsetWidth + 5;
		
		if (((offset.top - oheight) < 0) && (screen > owidth)) {
			o.className = 'ttip ttip-se';
			offset.top = offset.top + _this.offsetHeight + 5;
		} else if (screen > owidth) {
			o.className = 'ttip ttip-ne';
			offset.top = offset.top - oheight;
		} else if ((top - oheight) < 0) {
			o.className = 'ttip ttip-sw';
			offset.left = offset.left - owidth + _this.offsetWidth;
			offset.top = offset.top + _this.offsetHeight + 8;
		} else {
			o.className = 'ttip ttip-nw';
			offset.left = offset.left - owidth + _this.offsetWidth;
			offset.top = offset.top - oheight;
		}

		$(o).css({
			left: offset.left + 'px',
			top: offset.top + 'px',
			visibility: 'visible'
		});
		
		$('div.ttip iframe.tooltip').css({
			height: o.offsetHeight + 'px',
			width: o.offsetWidth + 'px'
		});
	},
	
	hide : function () {
		this.timer = setTimeout('tooltip.hiding()', 500);
	},
	
	hiding : function () {
		$('#tooltip').css({ display:'none' });
	},
		
	gebi : function (n) {
		if(!n) return false;
		if(!document.getElementById(n)) return false;
		return document.getElementById(n);
	}
}

