

var LoaderGui = new Class({
	bbgMod: '',
	bgMod: '',
	mod: '',
	initialize: function(){},
	start: function(tekst, toonSluitKnop) {
		var mWidth = 400;
		var mHeight = 100;
		
		if(tekst == '') {
			tekst = 'Bezig met laden...';
		}
		
		var body = $$('body')[0];
		
		this.bgMod = new Element('div', {
			'html': '',
			'styles': {
				'display': 'block',
				'float': 'left',
				'width': body.getScrollSize().x + 'px',
				'height': body.getScrollSize().y + 'px',
				'background-color': 'rgb(0, 0, 0)',
				'filter': 'alpha(opacity=50)',
				'opacity': .5,
				'-moz-opacity': .5,
				'z-index': '998',
				'position': 'absolute',
				'top': '0px',
				'left':'0px'
			}
		});

		this.mod = new Element('div', {
			'html': '<table border="0" style="width: 100%; height: 100%"><tr><td>'
					+(toonSluitKnop ? '<a href="javascript: void(0);" style="position: absolute; top:0; right: 5px; color: #444;" id="loaderGuiClose">Sluiten</a>' : '')
					+'<img src="res/images/ajax-loader.gif"><br /><br />' + tekst + '</td></tr></table>',
			'styles': {
				'display': 'block',
				'float': 'left',
				'width': mWidth + 'px',
				'height': mHeight + 'px',
				'text-align': 'center',
				'z-index': '999',
				'background-color': 'rgb(0, 0, 0)',
				'color': 'rgb(255, 255, 255)',
				'border': '1px solid black',
				'position': 'absolute',
				'top': Math.round((body.getSize().y - mHeight)/2) + body.getScroll().y + 'px',
				'left': Math.round((body.getSize().x - mWidth)/2) + body.getScroll().x + 'px'
			}
		});
		body.grab(this.bgMod);
		body.grab(this.mod);
		
		this.bgMod.setStyle('opacity', .5);

		this.bgMod.addEvent('click', function(ev) {
			ev.stop();
			lg.toggleBbg();
			lg.stop();
		});
		
		if (toonSluitKnop)
		{
			$('loaderGuiClose').addEvent('click', function(ev) {
				ev.stop();
				lg.toggleBbg();
				lg.stop();
			});	
		}
	},
	stop: function() {
		this.bgMod.dispose();
		this.bgMod = '';
		this.mod.dispose();
		this.mod = '';
	},
	
	startBbg: function() {
		var body = $$('body')[0];
		
		this.bbgMod = new Element('div', {
			'html': '',
			'styles': {
				'display': 'block',
				'float': 'left',
				'width': body.getScrollSize().x + 'px',
				'height': body.getScrollSize().y + 'px',
				'z-index': '950',
				'position': 'absolute',
				'top': '0px',
				'left':'0px', 
				'background-color': 'rgb(0, 0, 0)',
				'filter': 'alpha(opacity=50)',
				'opacity': .5,
				'-moz-opacity': .5
			}
		});
		
		body.grab(this.bbgMod, 'top');
		
		this.bbgMod.setStyle('opacity', .5);
	},
	stopBbg: function() {
		this.bbgMod.dispose();
		this.bbgMod = '';
	},
	toggleBbg: function() {
		if(this.bbgMod == '') {
			this.startBbg();
		} else {
			this.stopBbg();
		}
	}
});

lg = new LoaderGui();