var OutilContainer = new Class({
	
	Implements: [Options, Events],
	options:{
		bkg:null
	},
	
	initialize:function(options) {
		this.setOptions(options);
		debug('OutilsContainer:initialize');
		
		this.container = this.options.bkg.getFirst('div');
		
		this.bkg_fx =  new Fxable({
			target:this.options.bkg,
			type: 'opacity',
			src: 0,
			dest: 1,
			duration:300
		});
		
		this.outil_fx =  new Fxable({
			target:this.container,
			type: 'opacity',
			src: 0,
			dest: 1,
			duration:300
		});
		
		this.bound_resize = this.onResize.bind(this);
		this.bound_open_complete = this.openComplete.bind(this);
		this.bound_close_complete = this.closeComplete.bind(this);
		
	},
	
	onResize:function() {
		var win = window.getSize();

		this.options.bkg.setStyles({
			'width': win.x,
			'height': win.y,
			'top': window.getScroll().y
		});
		
		if(this.container.getFirst('.outil')) {
			var outil = this.container.getFirst('.outil').getSize();
			
			var cont_height = outil.y > win.y ? win.y - 60 : outil.y + 20;
			var cont_width = outil.x > win.x ? win.x - 60 : outil.x + 20;
						
			var top = (win.y - cont_height)/2;
			var left = (win.x - cont_width)/2;
			//debug(" outil.y = "+outil.y+" win.y = "+win.y+"cont_height = "+cont_height+" top = "+top);
			
			this.container.setStyles({
				'left': left,
				'right': left,
				'top': top,
				'bottom': top
			});
		}
	},
	
	open:function() {
		this.options.bkg.setStyle('display', 'block');
		this.bkg_fx.setClose();
		this.outil_fx.setClose();
		$$('.type_page')[0].setStyle('overflow', 'hidden');
		window.addEvent('resize', this.bound_resize);
		this.onResize();
		this.bkg_fx.open();
	},
	
	openOutil:function() {
		this.onResize();
		this.outil_fx.fx.addEvent('complete', this.bound_open_complete);
		this.outil_fx.open();
	},
	
	openComplete:function() {
		this.outil_fx.fx.removeEvent('complete', this.bound_open_complete);
		this.onResize();
	},
	
	close:function() {
		window.removeEvent('resize', this.bound_resize);
		this.bkg_fx.fx.addEvent('complete', this.bound_close_complete);
		this.bkg_fx.close();
	},
	
	closeComplete:function() {
		this.options.bkg.setStyle('display', 'none');
		this.bkg_fx.fx.removeEvent('complete', this.bound_close_complete);
		$$('.type_page')[0].setStyle('overflow', 'auto');
	}
	
});
