/*
	Progress
*/

var Progress = {

	init: function(options){
		this.options = $extend(options || {});
		this.eventPosition = this.position.bind(this);

		this.overlay = new Element('div', {'id': 'prOverlay'}).injectInside(document.body);
		this.centerContainer = new Element('div', {'id': 'prCenterContainer', 'styles': {'display': 'none'}}).injectInside(document.body);
		this.center = new Element('div', {'id': 'prCenter'}).injectInside(this.centerContainer);
		this.progress = new Element('div', {'id': 'prProgress'}).injectInside(this.center);

		new Element('div', {'styles': {'clear': 'both'}}).injectInside(this.center);

		this.fx = {
			overlay: this.overlay.effect('opacity', {duration: 500}).hide()
		};
	},

	start: function(){
		this.position();
		this.setup(true);
		this.top = window.getScrollTop() + (window.getHeight() / 4);
		this.centerContainer.setStyles({top: this.top, display: ''});
		this.fx.overlay.start(0.8);
		return false;
	},

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

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(window.ie ? 'select' : 'embed'));
		elements.extend(document.getElementsByTagName('iframe'));
		elements.each(function(el){
			if (open) el.lbBackupStyle = el.style.visibility;
			el.style.visibility = open ? 'hidden' : el.lbBackupStyle;
		});
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
	},

	close: function(){
		for (var f in this.fx) this.fx[f].stop();
		this.centerContainer.style.display = 'none';
		this.fx.overlay.chain(this.setup.pass(false, this)).start(0);
		return false;
	}
};

window.addEvent('domready', Progress.init.bind(Progress));
