var LoadingIndicator = new Class({

	Implements: [Options, Events],
	
	initialize: function(options){
    	this.setOptions(options);
    	var container = this.container = this.options.container || $(document.body),
    		pos = (container.getStyle('position') == 'static') ? container.getPosition() : {x:0, y:0},
    		size = container.getSize();    	
    	
    	if(container.get('tag') == 'img') this.container = container.getParent();    
    	
    	var position = this.calc(pos, size);
    	this.id = "id" + (Math.floor(Math.random() * 10000000));
    	this.loader = this.createLoader(position);    			
    },
    
    calc: function(p, s){
    	return {x: ( Math.floor( Math.floor(s.x - this.options.size.x) / 2) + p.x),	y: ( Math.floor( Math.floor(s.y - this.options.size.y) / 2) + p.y)};
    },
    
    createLoader: function(pos){
    	return loader = new Element('div',{
    		'class': this.options.className,
    		'id': this.id,
    		'styles': {
				'width': this.options.size.x,
				'height': this.options.size.y,
				'top': pos.y,
				'left': pos.x
		    }
    	});
    },
    
    show: function(){
    	var loader = this.loader;
    	loader.inject(this.container);
    },
    
    hide: function(){
    	$(this.id).dispose();
    },	
	
	options: {
		className: 'loading-indicator',
		container: null,
		size: {	x: 100, y: 19 }
	}
});