/* mytips.js

Erweiterung der Klasse "Tips" aus dem Mootools-Framework (mootools-release-1.11.js).
Erweitert den Tooltip um zusätzliche Felder "Image", "Weight" und "Price" zur Anzeige eines Bildes und eines weiteren Textfeldes.

*/

var myTips = Tips.extend({
	build: function(el){
		el.$tmp = new Object();
		el.$tmp.myTitle = (el.href && el.getTag() == 'a') ? el.href.replace('http://', '') : (el.rel || false);
		if (el.title){
			var dual = el.title.split('::');
			if (dual.length == 3 ) {
				el.$tmp.myTitle = dual[0].trim();
				el.$tmp.myText = dual[1].trim();
				el.$tmp.myPrice = dual[2].trim();
				el.$tmp.myImage = el.alt;
			} else 	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 = 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);
	},

	start: function(el){
		this.wrapper.empty();
		if (el.$tmp.myImage){
			this.image = new Element('img', {'class': this.options.className + '-image', 'src': el.$tmp.myImage, 'height': '350px', 'width': '350px'}).inject(this.wrapper);
		}
		if (el.$tmp.myTitle){
			this.title = new Element('span').inject(new Element('div', {'class': this.options.className + '-title'}).inject(this.wrapper)).setHTML(el.$tmp.myTitle);
		}
		if (el.$tmp.myText){
			this.text = new Element('span').inject(new Element('div', {'class': this.options.className + '-text'}).inject(this.wrapper)).setHTML(el.$tmp.myText);
		}
		if (el.$tmp.myPrice){
			this.price = new Element('span').inject(new Element('div', {'class': this.options.className + '-price'}).inject(this.wrapper)).setHTML(el.$tmp.myPrice);
		}
		$clear(this.timer);
		this.timer = this.show.delay(this.options.showDelay, this);
	}
});
