App.modules.loading = {
	constructor : function(parent, width) {
		this.init = function(width) {
			this.overlay = $('<div class="overlay" />');
			this.overlay.css({
				position : 	'absolute',
				top : 		'0',
				left : 		'0',
				zIndex : 	'0',
				width :		width == null ? '100%' : width+'px', 
				height : 	this.parent.height() + 'px'
			});
			if(width == null) {
				var width = this.parent.width();
			}
			var height = this.parent.height();
			var size = (width > 100 && height > 100 ? 32 : 16);
		
			this.img = $('<img />');
			this.img.css({
				position :	'absolute',
				left :		Math.round((width - size) / 2) + 'px',
				top : 		Math.round((height - size) / 2) + 'px'
			});
			this.img.attr('src', App.rewrite.image('loading-' + size + '.gif'));
			this.img.appendTo(this.overlay);
			
			if (this.parent.css('position') == 'static') {
				this.parent.css('position', 'relative');
			}
			this.overlay.appendTo(this.parent);
		}
		
		this.setVisible = function(visible) {
			if (visible) {
				this.overlay.css('height', this.parent.height() + 'px');
			}
			this.overlay.css('display', (visible ? '' : 'none'));
		}
		
		this.parent = parent;
		this.init(width);
		return this;
	}
}
