var infobox = new Class({
	Implements: Options,
	
	options: {
		width: 	200,
		height: 25,
		position: 'fixed',
		bottom: 0,
		right: 185,
		timer: null,
		delay: 3000 // wann soll es wieder zugehen - bei 0 nie
	},
	
	box: null,

	initialize: function(fn, opt) {		
		if(opt) { this.setOptions(opt); }
		
		if($('js_infobox')) {
			this.box = $('js_infobox');
		}
		else {
			this.box = new Element('a', {
				'href': '#',
				'id': 'js_infobox',
				'class': 'js_infobox',
				'styles': {
					'width': this.options.width,
					'position': this.options.position,
					'bottom': this.options.bottom,
					'right': this.options.right
				},
				'events': {
					'click': function() { fn.run(); return false; }
				}
			});	
		}
	},
	
	show: function(text) {
		this.box.set('text', text);
		this.draw.delay(500, this);
	},
	
	draw: function() {
		if($('js_infobox')) {		 
			return false;
		}
		this.box.inject(document.getElement('body'), 'bottom');
		this.box = $('js_infobox'); // WTF
		
		var img = new Element('img', {
			'src': '/app/1/img/new_layout/icon/action_new_chat.png',
			'styles': {'float': 'left',
					   'margin': '0 4px 0 0'}
		});
		
		this.box.appendChild(img, 'before');
		
		var tr = new Fx.Transition(Fx.Transitions.Expo, 1);
		fx = new Fx.Tween(this.box, {	transition: tr.easeOut});
		
		fx.start('height', '0px', this.options.height);
		
		if(this.options.delay > 0) {
			this.options.timer = this.close.delay(this.options.delay, this);
		}
		
		this.box.addEvent('mouseover', this.clearTimer.bind(this));
		this.box.addEvent('mouseout', this.delayClose.bind(this));
	},
	
	clearTimer: function() {
		$clear(this.options.timer);
	},
	
	delayClose: function() {
		if(this.options.delay > 0) {
			this.options.timer = this.close.delay(this.options.delay, this);
		}
	},
	
	close: function() {
		var tr = new Fx.Transition(Fx.Transitions.Bounce, 1);
		fx = new Fx.Tween(this.box, {	transition: tr.easeOut, 
										duration: 'long'});
		
		fx.start('height', this.options.height, '0px');	
		this.box.fade.delay(500, this.box, ['out']);
		this.box.dispose.delay(1000, this.box);
	}	
});
