/**
 * 	File:
 * 		MediaTips.js
 * 	Author:
 * 		Nicholas Blackwell BSc. UBCO - Jon Corbett Phd. UBCO
 * 	License:
 * 		Open Source MIT Licence
 *	Description:
 *		defines a simple class, MediaTip, which acts as a wrapper for Mootools tool-tips
 *		and provides some ensurance against 'sticky tips'
 *	Date: September 23 2009
 */

var MediaTip=new Class({
	activeTip:null,
	options:
	{
	className:"media",
	offsets:{'x': 32, 'y': 32}
	},
	initialize:function(options)
	{
		var me=this;
		me.setOptions(options);
		//nothing to do really.
	},

	make:function(els, options){
		var me=this;
		var config=$merge(me.options,options);
		var tip=new Tips(els,config);

		/*
		 * sometimes tips wont leave so upon display, 
		 * this will:
		 *		clear the last tip if it is active.
		 *		set itself as active tip
		 *		clear self on exit unless it gets stuck,
		 *			 - otherwise next tip will clear it.
		 */
		tip.addEvent("onShow",function(){
			//alert('show');
			if(me.activeTip)
			{
				if(me.activeTip!=tip)
				{
					me.activeTip.end();
				}
			}
			me.activeTip=tip;
		});
		tip.addEvent("onHide",function(){if(me.activeTip==tip)me.activeTip=null;});
		return tip;
	}
});
MediaTip.implement(new Options());
