function posters(ajaxPath) {
	var ZOOMS = [{
		left: 0,
		top: 0,
		zoom: 1
	}, {
		left: 153,
		top: 75,
		zoom: 0.635
	} , {
		left: 255,
		top: 120,
		zoom: 0.4
	}];
	var PREV_ZOOM = {
		left: -153,
		top: -50,
		zoom: 1.3
	};
	var NEXT_ZOOM = {
		left: 330,
		top: 150,
		zoom: 0.2
	};
	var ANIMATE_DURATION = 400;
	var MIN_NEXT = 5;

	var _ajaxPath = ajaxPath;

	var _rootEl = $('.posters_container');
	/**
	 * Очередь следующих элементов.
	 */
	var _nextHiddenItemEls = [];

	var _prevHiddenItemEls = [];

	var _isAnimating = false;

	var _isAjax = false;

	var _ajaxPage = 1;

	var _lastPage = false;

	init();

	function init() {
		_rootEl.find('.item').each(function() {
			saveWidth(this);
		});

		_rootEl.find('.item').eq(ZOOMS.length - 1).nextAll('.item')
			.each(function() {
				_nextHiddenItemEls.push($(this));
			})
			.detach();

		var visibleItemEls = _rootEl.find('.item');

		visibleItemEls.each(function(index) {
			var el = $(this);

			if (index) {
				var curZoom = ZOOMS[index];

				el.css({
					left: curZoom.left - Math.round(el.data('width') * curZoom.zoom / 2),
					marginLeft: '50%',
					top: curZoom.top,
					width: el.data('width') * curZoom.zoom,
					zIndex: ZOOMS.length - index
				});
			} else {
				el.css({
						zIndex: ZOOMS.length - index
					})
					.addClass('selected');
			}
		});

		$('.preview', _rootEl[0]).live('click', next);
		$('.wrap img', _rootEl[0]).live('click', next);
		checkNext();
	}

	function saveWidth(el) {
		var el = $(el);
		var imgEl = el.find('.preview img');

		el.data('width', imgEl.width());
		imgEl.css({
			height: 'auto',
			width: '100%'
		});
	}

	function next() {
		if (_isAnimating) {
			return;
		}

		_isAnimating = true;

		var visibleItemEls = _rootEl.find('.item');

		var animateCount = visibleItemEls.length;

		var checkAnimate = function() {
			animateCount--;

			if (!animateCount) {
				var visibleItemEls = _rootEl.find('.item');

				visibleItemEls.each(function(index) {
					$(this).css('zIndex', ZOOMS.length - index);
				});

				_isAnimating = false;
			}
		};

		visibleItemEls.each(function(index) {
			var el = $(this);

			if (index) {
				var prevZoom = ZOOMS[index - 1];

				el.animate({
					left: prevZoom.left - Math.round(el.data('width') * prevZoom.zoom / 2),
					top: prevZoom.top,
					width: Math.round(prevZoom.zoom * el.data('width'))
				}, {
					duration: ANIMATE_DURATION,
					easing: 'easeOutCubic',
					complete: function() {
						if (1 == index) {
							el
								.css({
									left: '',
									marginLeft: '',
									top: '',
									width: ''
								})
								.addClass('selected');
						}

						checkAnimate();
					}
				});
			} else {
				var curZoom = ZOOMS[0];

				el
					.removeClass('selected')
					.css({
						left: curZoom.left - Math.round(el.data('width') * curZoom.zoom / 2),
						marginLeft: '50%',
						top: curZoom.top,
						width: el.data('width') * curZoom.zoom
					})
					.animate({
						left: PREV_ZOOM.left - Math.round(el.data('width') * PREV_ZOOM.zoom / 2),
						opacity: 0,
						top: PREV_ZOOM.top,
						width: Math.round(PREV_ZOOM.zoom * el.data('width'))
					}, {
						duration: ANIMATE_DURATION,
						easing: 'easeOutCubic',
						complete: function() {
							_prevHiddenItemEls.push(el.detach());

							checkAnimate();
						}
					});
			}
		});

		if (!_nextHiddenItemEls.length) {
			return;
		}

		// Достаем из очереди новый элемент.

		animateCount++;

		var el = _nextHiddenItemEls.shift();
		var curZoom = ZOOMS[ZOOMS.length - 1];

		el
			.css({
				opacity: 0,
				left: NEXT_ZOOM.left - Math.round(el.data('width') * NEXT_ZOOM.zoom / 2),
				marginLeft: '50%',
				top: NEXT_ZOOM.top,
				width: el.data('width') * NEXT_ZOOM.zoom
			})
			.appendTo(_rootEl)
			.animate({
				opacity: 1,
				left: curZoom.left - Math.round(el.data('width') * curZoom.zoom / 2),
				top: curZoom.top,
				width: Math.round(curZoom.zoom * el.data('width'))
			}, {
				duration: ANIMATE_DURATION,
				easing: 'easeOutCubic',
				complete: function() {
					el.css('opacity', '');

					checkAnimate();
				}
			});

		checkNext();
	}

	function load() {
		if (_isAjax) {
			return;
		}

		_isAjax = true;

		$.ajax({
			url: _ajaxPath,
			dataType: 'html',
			data: {
				page: ++_ajaxPage
			},
			success: function(data) {
				var containerEl = $(data)
					.css({
						'left': -10000,
						'position': 'absolute',
						'top': -10000,
						'visibility': 'hidden'
					})
					.appendTo('body');

				var itemEls = containerEl.find('.item');

				if (!itemEls.length || !containerEl.find('a').length) {
// 					_lastPage = true;
                    _ajaxPage = 0;
				}

				itemEls
					.each(function() {
						saveWidth(this);
						_nextHiddenItemEls.push($(this));
					})
					.detach();
				containerEl.remove();
			},
			complete: function() {
				_isAjax = false;

				checkNext();
			}
		});
	}

	function checkNext() {
		if (_lastPage) {
			return;
		}

		if (MIN_NEXT > _nextHiddenItemEls.length) {
			load();
		}
	}
}

