ImagesBlock = Class.create(BasicControl, {
	initialize: function($super, config) {
		Object.extend(this, {
			config: {
				cntr: null
			},

			cntr: null,
			links: [],
			currPage: 0
		});

		$super('images_block', config);
	},

	onReady: function() {
		if ((this.cntr = $(this.config.cntr)) && this.cntr.down('.bottom .page-nav'))
		{
			this.cntr.select('.bottom .inner ul li').each(function(item) {
				this.addAction(item, 'click', this.goTo.bind(this, this.links.push(item) - 1), true);
			}.bind(this));

			this.addAction(this.cntr.down('.bottom li.previous'), 'click', function() {
				this.goTo(((0 <= (this.currPage - 1)) ? this.currPage : this.links.length) - 1);
			}.bind(this), true);

			this.addAction(this.cntr.down('.bottom li.next'), 'click', function() {
				this.goTo((this.links.length > (this.currPage + 1)) ? this.currPage + 1 : 0);
			}.bind(this), true);
		}
	},

	goTo: function(page) {
		if (this.currPage != page)
		{
			this.links.each(function(link) {
				link.removeClassName('cur');
			});

			this.links[page].addClassName('cur');

			this.moveTo($('row-' + page), this.cntr.down('.top'));

			this.currPage = page;
		}
	},

	moveTo: function(element, container){
		Position.prepare();

		var co = Position.cumulativeOffset(container), eo = Position.cumulativeOffset(element);

		new Effect.SmoothScroll(container, {
			duration: 0.2, x: (eo[0] - co[0]), y: (eo[1] - co[1])
		});
	}
});