var Loading = {
	
	// init the MOOloading
	init: function (options) {
		
		// init default options
		this.options = Object.extend({
		initialHeight:'100',
		initialWidth:'100'
		}, options || {});
		

		this.eventPosition = this.position.bind(this);
		
		// init the HTML elements
		// the overlay (clickable to close)
		this.overlay = new Element('div').setProperty('id', 'mo_overlay').injectInside(document.body);
		// the center element
		this.center = new Element('div').setProperty('id', 'mo_center').setStyles({width: this.options.initialWidth+'px', height: this.options.initialHeight+'px', marginLeft: '-'+(this.options.initialWidth/2)+'px', display: 'none'}).injectInside(document.body);
		
		// init the effects
		this.fx = {
			overlay: 	this.overlay.effect('opacity', { duration: 500 }).hide(),
			center: 	this.center.effect('opacity', { duration: 500 }).hide()
		};
	},

	open: function() {
		$clear(this.timer);
		this.position();
		//this.setup(true);
		this.top = Window.getScrollTop() + (Window.getHeight() / 2);
		this.left = Window.getScrollLeft() + (Window.getWidth() / 2);
		this.fx.overlay.custom(0.2);
		this.center.setStyles({top: this.top+'px',left: this.left+'px', display: ''});
		this.fx.center.custom(1);
		// fermeture au bout d'un certain temps	
		this.timer = this.close.delay(8000, this);
	},

	position: function() {
		this.overlay.setStyles({top: Window.getScrollTop()+'px', height: Window.getHeight()+'px'});
	},

	close: function() {
		$clear(this.timer);
		for(var f in this.fx) this.fx[f].clearTimer();
		this.center.style.display = 'none';
		this.center.className = 'mo_loading';
		this.fx.overlay.custom(0);
		this.fx.center.custom(0);
		return false;
	}
		
};

// startup
Window.onDomReady(Loading.init.bind(Loading));