Of.Windows.Elastic = new Class({
	name: 'Elastic',
	namespace: 'Of.Windows',
	type: 'Window',
	Extends: Of.Windows.Simple,
	options: {
		/* 0 - closed, 1 - opened, 2 - working */
		state: 0,
		working: false,
		/* 0 - closed, 1 - opened */
		toState: 0,
		newState: 0
	},
	onBeforePropSet: function()
	{
		this.setLocal('position', this.getPosition());
		this.setLocal('size', this.getSize());
		
		$('description-more').addEvent('click', function(){
			if (this.options.state == 0)
				this._open();
			else
				this._close();
		}.bind(this));
	},
	_onComplete: function()
	{
		this.options.state = this.options.newState;
		this.options.working = false;
		return;
		if (this.options.state != this.options.toState)
		{
			if (this.options.toState == 0)
				this._close();
			else
				this._open();
		}
	},
	_open: function()
	{
		this.options.working = true;
		this.options.newState = 1;
		
		this.set('morph', {duration: 'long', transition: 'back:out', onComplete: this._onComplete.bind(this)});
		this.setStyle('position', 'absolute');
		this.setStyles({top: this.getLocal('position').y, left: this.getLocal('position').x});
		this.morph('.descriptionLarge');
	},
	_close: function()
	{
		this.options.working = true;
		this.options.newState = 0;
		
		new Fx.Morph(this, {duration: 1000, transition: Fx.Transitions.Back.easeOut}).start({
			top: this.getLocal('position').y, 
			left: this.getLocal('position').x,
			height: this.getLocal('size').y,
			onComplete: this._onComplete.bind(this)
		});
		
		this.morph('.description');
		this.setStyle.delay(1000, this, 'position', 'relative');
	}
});

document.addEvent('domready', function(){
	$('language-selector').addEvent('mouseenter', function(){
		$('language-bar').morph({height: 30});
		this.opened = 1;
	});
	
	$('language-bar').addEvent('mouseleave', function(){
		$('language-bar').morph({height: 0});
		this.opened = 0;
	});

	Of.Life.Engine.alive($('contact-form-popup'), Of.Windows.ContactWindow);
	
	$('contact-form').addEvent('click', function(){
		if ($('contact-form-popup').isClosed())
			$('contact-form-popup').open();
		else
			$('contact-form-popup').close();
	});
	
	Of.Life.Engine.alive($('description'), Of.Windows.Elastic);
});
