/**
 * Custom TwitterFeeds Class
 * @author 58062 Florian Collot
 * 
 * 
 */

var TwitterFeeds = new Class ({
	Implements: [Events, Options],
	options : {
		'closeElement' : null,
		'position' : 'bottom'
	},
	
	initialize:function(element, mainWrapper, options){
		this.setOptions(options);
		
		if (!$chk(element))
			return;
		this.element = element;
		
		if (!$chk(mainWrapper))
			return;
		this.mainWrapper = mainWrapper;
		this.nativePadding = (this.options.position == 'top') ? parseInt(this.mainWrapper.getStyle('padding-top').split("px")[0]) : parseInt(this.mainWrapper.getStyle('padding-bottom').split("px")[0]); 
		
		if (this.element.getStyle('display') == 'none') {
			this.show.delay(1000, this);
		}
		
		if (this.options.closeElement != null)
			this.options.closeElement.addEvent('click', function(e){
				this.hide();
				e.stop();
			}.bindWithEvent(this));
		
	},
	
	show : function() {
		if (Browser.Engine.trident && Browser.Engine.version == 4)
			return;
		if (!Browser.Engine.trident) {
			this.element.setStyles({
				'opacity' : 0
			});
		}
		this.element.setStyles({
			'display' : 'block'
		});
		var height = this.element.getSize();
		if (this.options.position == 'top') 
			this.mainWrapper.setStyle('padding-top', (this.nativePadding+height['y']).toString()+"px");
		else
			this.mainWrapper.setStyle('padding-bottom', (this.nativePadding+height['y']).toString()+"px");
		if (!Browser.Engine.trident) {
			new Fx.Morph(this.element, {
				'duration' : 1000,
				onComplete : function(){
					this.fireEvent('show');
				}.bind(this)
			}).start({
				'opacity' : 1
			});
		}
		
		
	},
		
	hide : function() {
		new Fx.Morph(this.element, {
			'duration' : 'long',
			onComplete : function(){
				this.fireEvent('hide');
				this.element.setStyles({
					'display' : 'none'
				});
				
				if (this.options.position == 'top') 
					this.mainWrapper.setStyle('padding-top', (this.nativePadding).toString()+"px");
				else
					this.mainWrapper.setStyle('padding-bottom', (this.nativePadding).toString()+"px");
				
			}.bind(this)
		}).start({
			'opacity' : 0
		});
	}
});

