var MOOdalBox = {
	init: function()
	{
		this.overlay = new Element('div').addClass('overlay').setStyles({top: Window.getScrollTop() + 'px', height: Window.getHeight() + 'px'}).inject(document.body);
		this.overlay2 = new Element('div').addClass('overlay2').setStyles({top: Window.getScrollTop() + 'px', height: Window.getHeight() + 'px'}).inject(document.body);
		this.center = new Element('div').addClass('cont').inject(this.overlay);
		
		this.top = new Element('a').setProperty('href', '#').addClass('close').addClass('top').inject(this.center);
		this.br = new Element('br').addClass('cl').inject(this.center);
		this.content = new Element('div').addClass('block_p').inject(this.center);
		//this.content = new Element('div').setStyles({padding: '43px 73px 90px 73px'}).inject(this.content1);
		this.bottom = new Element('a').setProperty('href', '#').addClass('close').addClass('bottom').inject(this.center);
		
		new Element('img').setProperty('src', '/img/close.gif').inject(this.top);
		//new Element('img').setProperty('src', '/img/close.jpg').inject(this.bottom);
		
		this.center.setStyles({
			top: 100,
			left: (Window.getWidth() - 918) / 2,
			height: this.height + 'px'
		});
		this.content.setStyle('height', (this.height - ( 2 * 42 ) - 200 - this.br.getSize().y ) + 'px');
		
		this.eventPosition = this.position.bind(this);
		this.top.onclick = this.bottom.onclick = this.close.bind(this);
	},
	
	open: function(sLinkHref) {
		this.href = sLinkHref;
		this.height = Window.getHeight();
		
		this.init();		
		this.position();
		this.setup(true);
		this.loadContents();
	},

	position: function() {
		this.overlay.setStyles({top: Window.getScrollTop() + 'px', height: Window.getHeight() + 'px'});
		this.overlay2.setStyles({top: Window.getScrollTop() + 'px', height: Window.getHeight() + 'px'});
	},

	setup: function(open) {
		var elements = $A($$('object'));
		elements.extend($$(window.ActiveXObject ? 'select' : 'embed'));
		elements.each(function(el){ el.style.visibility = open ? 'hidden' : ''; });
		
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
	},
	
	loadContents: function() {		
		this.content.addClass('loading');
		
		new Request.HTML( { 
			"url" : this.href,
			"onSuccess" : this.onSuccess.bind(this),
			"onFailure" : this.onFailure.bind(this)
		} ).send();
	},
	
	close: function() {
		this.setup(false);
		this.overlay.dispose();
		this.overlay2.dispose();
		return false;
	},
	
	onSuccess : function(data)
	{
		this.content.removeClass('loading');
		this.content.adopt( data );
	},
	
	onFailure : function()
	{
		this.content.removeClass('loading');
		this.content.set('html', 'Ошибка загрузки данных.');
	}
};