window.addEvent('domready',function() {
	tips = new toolTips({});
});

var toolTips = new Class({
	////////////////////////////////////////
	// Variables and options
	////////////////////////////////////////
	Implements: [Options,Events],
	options: {
		handle: '.tipHandle',
		tips: '.tip',
		background: '#fff'
	},
	

	initialize: function(options) {
		var that = this;
		this.setOptions(options);

		var tipHandles = $$(this.options.handle);
		var tips = $$(this.options.tips);
		tips.fade('hide');

		tipHandles.addEvent('mouseover', function(event) {
			event.target.getNext('.tip').fade('in');
		});
		tipHandles.addEvent('mouseout', function(event){
			try{
				if ( event.target != null && event.relatedTarget != null ) {
					if ( event.target.getParent() !== event.relatedTarget.getParent()) {
						event.target.getNext('.tip').fade('out');
					}
				}
			} catch(e) { tips.fade('out'); }
		});
		tips.addEvent('mouseout',function(event) {
			try {
				if ( event.target != null && event.relatedTarget != null ) {
					if ( event.target.getParent() !== event.relatedTarget.getParent()) {
						event.target.fade('out');
					}
				}
			} catch(e) { tips.fade('out'); }
		})

		tips.each( function(item, index, array) {
			item.getParent().setStyles({'position':'relative'});
			item.setStyles({
				'position':'absolute',
				'right':0,
				'top':30,
				'background':that.options.background,
				'padding':5,
				'font':'normal normal bold 11px arial'
			});
		});

	}
});
