GoldmanSachs.ToolTip = new Class({
	initialize: function(el) {
		this.trigger = el;
		this.trigger_container = el.getParent();
		this.tooltip = $E('.gs_tooltip', this.trigger_container);
		
		if ($defined($('gs_tooltip_container'))) {
			this.container = $('gs_tooltip_container');
		} else {
			this.container = new Element('div', {'id': 'gs_tooltip_container'}).inject(document.body);
		}
		this.trigger.addEvent('mouseenter', this.show.bind(this));
		this.trigger.addEvent('mouseleave', this.hide.bind(this));
		this.container.addEvent('mouseleave', this.hide.bind(this));
		this.trigger.onclick = function (event) { var evt = new Event(event);evt.preventDefault();}
	},
	show: function(event) {
		var event = new Event(event);
		var position = this.trigger_container.getCoordinates();
		if ($E('.gs_tooltip', this.container)) {
			$E('.gs_tooltip', this.container).remove();
		}		
		this.container.removeAttribute('style');
		this.tooltip.clone().injectTop(this.container);
		var toolPosition = $E('.gs_tooltip', this.container).getCoordinates();
		if (position.left + toolPosition.width + 20 < $('gs_doc').getSize().size.x) {
			this.container.setStyles({
				'left': position.left + 0,
				'top': position.top + 20
			});
		} else {
			this.container.setStyles({
				'left': position.left - 600,
				'top': position.top + 20
			});
		}
		this.container.addClass('active');
	},
	hide: function(e) {
		if (!this.container.hasChild(e.relatedTarget) && !this.trigger_container.hasChild(e.relatedTarget)) {
			this.container.removeClass('active');
		if ($E('.gs_tooltip', this.container)) {
			$E('.gs_tooltip', this.container).remove();
		}		
		this.container.removeAttribute('style');
		}
	}
})