/* This object serves as a wrapper for the YAHOO.widget.Overlay object.
Making it easier to create many of the tooltips that are used consistantly 
across the site */

function tooltip() {

	if (typeof tooltip._initialized == "undefined") {

		this.tip;
		this.object; // element of event
		
		tooltip.prototype.build = function () {

			this.tip = new YAHOO.widget.Overlay(
				"tooltip",
				{
					visible:false,
					width:"220px"
				}
			);
		}

		// show a tooltip
		tooltip.prototype.create = function( body, object ) {

			this.object = object;
			this.tip.setBody( '<div class="error_message">' + body + '</div>' );
			this.tip.render( document.body );
			this.tip.show();
			this.tip.cfg.setProperty( "context", [object, "tl", "bl"]);
			this.tip.bringToTop();

			// add listeners to the object
			YAHOO.util.Event.addListener( object, "click", this.remove, this );
			YAHOO.util.Event.addListener( object, "keypress", this.remove, this );
			YAHOO.util.Event.addListener( object, "blur", this.remove, this );
		};

		// remove the listeners
		tooltip.prototype.remove = function( e, obj ) {
			YAHOO.util.Event.removeListener( obj.object, "click", obj.remove );
			YAHOO.util.Event.removeListener( obj.object, "keypress", obj.remove );
			YAHOO.util.Event.removeListener( obj.object, "blur", obj.remove );
			obj.tip.hide( obj ); // then hide
		};

		tooltip.prototype.hide = function( obj ) {
			if ( typeof( obj )  == "undefined" ) {
				this.tip.hide(); // if called externally
			} else {
				obj.tip.hide(); // if called through the event listener
			}
		}

		this.build();
		tooltip._initialized = true;

	} // end if initialized 
} // end tooltip 
