/**
 * @author Sergey Chikuyonok (gonarch@design.ru)
 * @copyright Art.Lebedev Studio (http://www.artlebedev.ru)
 */
var Door = {
	init: function(){
		/** @type {Tween} */
		this.tween = null;

		this.ptr = $('#door .decoration');
		this.bg = $('#reducer');
		this.content = $('#content');
		this.to_show = $('#page-body .open-door');
		this.to_hide = $('#restricted-access');

		this.to_hide.find('.pseudo-href').click(function(){ Door.open(); });
		this.to_show.find('.pseudo-href').click(function(){ Door.close(); });
	},

	/**
	 * Открыть дверь отделения
	 */
	open: function(){
		if(this.tween)
			this.tween.stop();
		this.tween = new Tween(this, '', EEQ.Cubic.easeInOut, 0, 1, 30);
		this.tween.onMotionChanged = this._anim;
	},

	/**
	 * Закрыть дверь отделения
	 */
	close: function(){
		if(this.tween)
			this.tween.stop();
		this.tween = new Tween(this, '', EEQ.Cubic.easeInOut, 1, 0, 30);
		this.tween.onMotionChanged = this._anim;
	},

	/**
	 * Анимация
	 * @memberOf {Tween}
	 */
	_anim: function(){
		var p = this.position;
		Door.bg.css({backgroundPosition: (80 * (1 - p)) + '%  0px'});
		Door.ptr.css({left: p * 480});
		Door.content.css({left: (-300 * (1 - p)) + '%'});
		Door.to_show.css({left: (100 - 300 * (1 - p)) + '%'});
		Door.to_hide.css({left: (100 + 300 * p) + '%'});
	}
};

$(function(){
	Door.init();
})
