TipsStateNewslines = new Class({
	Extends: Tips,
	options: {
		'url': 'href'
	},
	initialize: function(elements, options) {
		this.parent(elements, options);
	},
	attach: function(elements){
		$$(elements).each(function(element){
			var title = element.get(this.options.title),
				text = element.get(this.options.text),
				url =  element.get(this.options.url);
		
			element.erase('title').store('tip:native', title).retrieve('tip:title', title);
			element.store('tip:url', url);
			element.retrieve('tip:text', text);
			this.fireEvent('attach', [element]);
			
			var events = ['enter', 'leave'];
			if (!this.options.fixed) events.push('move');
			
			events.each(function(value){
				var event = element.retrieve('tip:' + value);
				if (!event) event = this['element' + value.capitalize()].bindWithEvent(this, element);
				
				element.store('tip:' + value, event).addEvent('mouse' + value, event);
			}, this);
		}, this);

		return this;
	},

	toElement: function(){
		if (this.tip) return this.tip;

		this.tip = new Element('div', {
			'class': this.options.className,
			styles: {
				position: 'absolute',
				top: 0,
				left: 0
			}
		}).adopt(
			new Element('img', {'src': '/explore/images/close_x.png',
				styles: {
					position: 'absolute',
					top: -8,
					right: -8
				}
			}).addEvent('click', function() {
				this.getParent().setStyle('display', 'none');
			})
		).adopt(
			new Element('div', {'class': 'tip-top'}),
			this.container,
			new Element('div', {'class': 'tip-bottom'})
		).inject(document.body).store('url', this.container.retrieve('url', ''));
		return this.tip;	
	},

	elementEnter: function(event, element){
		this.container.empty();
		this.container.store('url', element.retrieve('tip:url', ''));	
		['title', 'text'].each(function(value){
			var content = element.retrieve('tip:' + value);
			if (content) this.fill(new Element('div', {'class': 'tip-' + value}).inject(this.container), content);
		}, this);
		
		$clear(this.timer);
		this.timer = (function(){
			this.show(this, element);
			this.position((this.options.fixed) ? {page: element.getPosition()} : event);
		}).delay(this.options.showDelay, this);
	}
});

