var CozTips = Tips.extend({
	options: {
		onShow: function(tip){
			tip.setStyle('visibility', 'visible');
		},
		onHide: function(tip){
			tip.setStyle('visibility', 'hidden');
		},
		maxTitleChars: 30,
		showDelay: 100,
		hideDelay: 100,
		className: 'tool',
		offsets: {'x': 16, 'y': 16},
		fixed: false,
		useHref: true,
		useRel: true,
		title: false,
		text: false
	},

	build: function(el){
		el.$tmp.myTitle = this.options.title || ((this.options.useHref && el.href && el.getTag() == 'a') ? el.href.replace('http://', '') : (this.options.useRel && el.rel) ? el.rel : false);
		if (el.title){
			var dual = el.title.split('::');
			if (dual.length > 1) {
				el.$tmp.myTitle = dual[0].trim();
				el.$tmp.myText = dual[1].trim();
			} else {
				el.$tmp.myText = el.title;
			}
			el.removeAttribute('title');
		} else {
			el.$tmp.myText = el.rel == 'lightbox' ? 'View Full Size Image' : (this.options.text || false);
		}
		if (el.$tmp.myTitle && el.$tmp.myTitle.length > this.options.maxTitleChars) el.$tmp.myTitle = el.$tmp.myTitle.substr(0, this.options.maxTitleChars - 1) + "&hellip;";
		el.addEvent('mouseenter', function(event){
			this.start(el);
			if (!this.options.fixed) this.locate(event);
			else this.position(el);
		}.bind(this));
		if (!this.options.fixed) el.addEvent('mousemove', this.locate.bindWithEvent(this));
		var end = this.end.bind(this);
		el.addEvent('mouseleave', end);
		el.addEvent('trash', end);
	}
});

CozTips.init = function(parent) {
	new CozTips($ES('a[title],div[title],span[title],a[rel=lightbox]',parent), {
		maxTitleChars: 1000,
		useHref: false,
		useRel: false,
		showDelay: 500
	});
};

window.addEvent('domready',CozTips.init);
