var ajaxLoader = {
	init: function(){
		this.panel = new Element('div', {'id': 'ajaxLoading_panel','styles': {'display': 'none','position':'fixed','left':'50%','top': '50%','z-index':'999','text-align':'center','opacity': '0','width': 'auto'}}).inject(document.body);
		this.panel.set('tween', {duration: 'long'});
		this.content = new Element('div', {'styles': {'border': '1px solid #808080','vertical-align': 'middle'}}).inject(this.panel);
		this.header = new Element('div', {'id': 'ajaxLoading_header','styles': {'white-space': 'nowrap','background': 'url(/images/background_silver.jpg)','padding': '0 5px','color': '#000','font-size':'9pt','font-weight': 'bold','font-family': 'arial','line-height': '1.9'}}).inject(this.content);
		this.body = new Element('div', {'id': 'ajaxLoading_body','styles': {'background-color': '#fff','z-index':'999'}}).inject(this.header, 'after');
		this.loadingimg = new Element('img', {'src': '/images/AJAX_LoadingBar.gif'}).inject(this.body);
		this.overlay = new Element('div', {'id': 'ajaxLoading_wrapper','styles':{'position':'absolute','left':'0','width': Window.getWidth()+'px','height': Window.getHeight()+'px','display': 'none','background-color': '#D9E6F4','z-index':'9'}}).inject(document.body);
		this.eventPosition = this.position.bind(this);
	},
	show: function(msg){
		this.position();
		this.setup(true);
		this.overlay.setStyles({'display': 'block'});
		this.overlay.tween('opacity', [0,.8]);
		this.panel.setStyles({'display': ''});
		this.panel.tween('opacity', [0,1]);
		this.header.set('text', msg);
	},
	position: function(){
		this.overlay.setStyles({top: window.getScrollTop()+'px'});
	},
	setup: function(open){
		var toggleThese = $A($$('object'));
		toggleThese.extend($$(window.ActiveXObject ? 'select' : 'embed'));
		toggleThese.each(function(el){el.style.visibility = open ? 'hidden' : '';});
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
	},
	hide: function(){
		this.setup(false);
		this.panel.tween('opacity', 0);
		this.panel.setStyles({'display': 'none'});
		this.header.set('text', '');
		this.body.set('html', '<img src="/images/AJAX_LoadingBar.gif">');
		this.overlay.tween('opacity', [0]);
		this.overlay.setStyles({'display': 'none'});
	}
};
window.addEvent('domready', ajaxLoader.init.bind(ajaxLoader));