function ImageGallery(list, pointer_prev, pointer_next, pointer_first, pointer_last, full, scrollToImage) {
	var thisCopy = this;

	this.listObj = list;
	this.pointerPrevObj = pointer_prev;
	this.pointerNextObj = pointer_next;
	this.pointerFirstObj = pointer_first;
	this.pointerLastObj = pointer_last;
	this.fullObj = full;
	this.startScrollToImage = scrollToImage;

	this.pointerPrevActive = '/i/image_pointer_prev_active.gif';
	this.pointerPrevInactive = '/i/image_pointer_prev_inactive.gif';
	this.pointerNextActive = '/i/image_pointer_next_active.gif';
	this.pointerNextInactive = '/i/image_pointer_next_inactive.gif';
	this.pointerFirstActive = '/i/image_pointer_first_active.gif';
	this.pointerFirstInactive = '/i/image_pointer_first_inactive.gif';
	this.pointerLastActive = '/i/image_pointer_last_active.gif';
	this.pointerLastInactive = '/i/image_pointer_last_inactive.gif';

	this.imageList = new Array();
	this.minScroll = null;
	this.maxScroll = null;
	this.currentScroll = 0;
	this.scrollStep = 15;

	this.__intervalPrev = null;
	this.__intervalNext = null;
	this.__intervalFrameInit = null;
	this.__prevMouseDown = false;
	this.__prevMouseUp = true;
	this.__nextMouseDown = false;
	this.__nextMouseUp = true;

	// register events
	register_event(this.pointerPrevObj, 'mousedown', function() {return thisCopy.onPointerPrevMouseDown()});
	register_event(this.pointerPrevObj, 'mouseup', function() {return thisCopy.onPointerPrevMouseUp()});
	register_event(this.pointerNextObj, 'mousedown', function() {return thisCopy.onPointerNextMouseDown()});
	register_event(this.pointerNextObj, 'mouseup', function() {return thisCopy.onPointerNextMouseUp()});
	register_event(this.pointerFirstObj, 'click', function() {return thisCopy.onPointerFirstClick()});
	register_event(this.pointerLastObj, 'click', function() {return thisCopy.onPointerLastClick()});
	// end register events

	this.initPointerImages();
	this.init();

	return this;
}
ImageGallery.prototype = {
	onPointerPrevMouseDown: function() {
		this.startScrollPrev();
	},

	onPointerPrevMouseUp: function() {
		this.stopScrollPrev();
	},

	onPointerNextMouseDown: function() {
		this.startScrollNext();
	},

	onPointerNextMouseUp: function() {
		this.stopScrollNext();
	},

	onPointerFirstClick: function() {
		this.scrollFirst();
	},

	onPointerLastClick: function() {
		this.scrollLast();
	},

	scrollFirst: function() {
		this.getFrameWindow().scrollTo(this.minScroll, 0);
		this.currentScroll = this.minScroll;
		this.checkPointerNextStatus();
		this.checkPointerPrevStatus();
		this.checkPointerFirstStatus();
		this.checkPointerLastStatus();
	},

	scrollLast: function() {
		this.getFrameWindow().scrollTo(this.maxScroll, 0);
		this.currentScroll = this.maxScroll;
		this.checkPointerNextStatus();
		this.checkPointerPrevStatus();
		this.checkPointerFirstStatus();
		this.checkPointerLastStatus();
	},

	getFrameWindow: function() {
		if (null != this.listObj.contentWindow) return this.listObj.contentWindow;
		else return this.listObj;
	},

	startScrollPrev: function() {
		var thisCopy = this;
		this.__prevMouseDown = true;
		this.__prevMouseUp = false;
		this.__intervalPrev = setInterval(function() {return thisCopy.processScrollPrev()}, 30);
	},

	startScrollNext: function() {
		var thisCopy = this;
		this.__nextMouseDown = true;
		this.__nextMouseUp = false;
		this.__intervalNext = setInterval(function() {return thisCopy.processScrollNext()}, 30);
	},

	processScrollPrev: function() {
		if ((true == this.__prevMouseDown) && (false == this.__prevMouseUp) && (false == this.__nextMouseDown) && (true == this.__nextMouseUp)) this.scrollPrev();
		if ((false == this.__prevMouseDown) && (true == this.__prevMouseUp) && (true == this.__nextMouseDown) && (false == this.__nextMouseUp)) this.stopScrollPrev();
	},

	processScrollNext: function() {
		if ((true == this.__nextMouseDown) && (false == this.__nextMouseUp) && (false == this.__prevMouseDown) && (true == this.__prevMouseUp)) this.scrollNext();
		if ((false == this.__nextMouseDown) && (true == this.__nextMouseUp) && (true == this.__prevMouseDown) && (false == this.__prevMouseUp)) this.stopScrollNext();
	},

	stopScrollPrev: function() {
		this.__prevMouseDown = false;
		this.__prevMouseUp = true;
		clearInterval(this.__intervalPrev);
	},

	stopScrollNext: function() {
		this.__nextMouseDown = false;
		this.__nextMouseUp = true;
		clearInterval(this.__intervalNext);
	},

	scrollPrev: function(step) {
		step = (step) ? step : this.scrollStep;
		this.getFrameWindow().scrollBy(-step, 0);
		this.currentScroll = (this.minScroll > (this.currentScroll - step)) ? this.minScroll : (this.currentScroll - step);
		if (this.minScroll == this.currentScroll) this.stopScrollPrev();
		this.checkPointerNextStatus();
		this.checkPointerPrevStatus();
		this.checkPointerFirstStatus();
		this.checkPointerLastStatus();
	},

	scrollNext: function(step) {
		step = (step) ? step : this.scrollStep;
		this.getFrameWindow().scrollBy(step, 0);
		this.currentScroll = (this.maxScroll < (this.currentScroll + step)) ? this.maxScroll : (this.currentScroll + step);
		if (this.maxScroll == this.currentScroll) this.stopScrollNext();
		this.checkPointerNextStatus();
		this.checkPointerPrevStatus();
		this.checkPointerFirstStatus();
		this.checkPointerLastStatus();
	},

	initPointerImages: function() {
		var pointerPrevActive = new Image();
		var pointerPrevInactive = new Image();
		var pointerNextActive = new Image();
		var pointerNextInactive = new Image();

		pointerPrevActive.src = this.pointerPrevActive;
		pointerPrevInactive.src = this.pointerPrevInactive;
		pointerNextActive.src = this.pointerNextActive;
		pointerNextInactive.src = this.pointerNextInactive;
	},

	init: function() {
		this.startInit();
	},

	startInit: function() {
		var thisCopy = this;
		this.__intervalFrameInit = setInterval(function() {thisCopy.processInit()}, 30);
	},

	endInit: function() {
		clearInterval(this.__intervalFrameInit);
	},

	processInit: function() {
		if (null != this.getFrameWindow().document.getElementById('frameBlock')) {
			this.endInit();
			this.initImages();
			this.initFrame();
			this.initScrollInterval();
			this.scrollToImage(this.startScrollToImage);
			this.selectImage(this.startScrollToImage);
			this.checkPointerPrevStatus();
			this.checkPointerNextStatus();
			this.checkPointerFirstStatus();
			this.checkPointerLastStatus();
		}
	},

	initImages: function() {
		for (var i = 0; i < this.imageList.length; i++) {
			this.imageList[i].parent = this;
			this.imageList[i].thumbSource = this.getFrameWindow();
		}
	},

	initFrame: function() {
		var obj = this.getFrameWindow().document.getElementById('frameBlock');
		var h = '';
		h += '<table class="gallery_image_list" id="innerTable" onselectstart="return false;"><tr>'
		for (var i = 0; i < this.imageList.length; i++) {
			h += '<td' + ((i == (this.imageList.length - 1)) ? ' class="last"' : '') + '>';
			h += this.imageList[i].thumbHtml();
			h += '</td>';
		}
		h += '</tr></table>';
		obj.innerHTML = h;

		for (var i = 0; i < this.imageList.length; i++) {
			this.imageList[i].thumbRegister();
		}
	},

	initScrollInterval: function() {
		var obj = this.getFrameWindow().document.getElementById('innerTable');
		this.minScroll = 0;
		this.maxScroll = obj.offsetWidth - this.listObj.offsetWidth;
	},

	checkPointerPrevStatus: function() {
		if (true == this.canScrollPrev()) {
			if ('active' != this.pointerPrevObj.className) {
				this.pointerPrevObj.src = this.pointerPrevActive;
				this.pointerPrevObj.className = 'active';
			}
		} else {
			if ('' != this.pointerPrevObj.className) {
				this.pointerPrevObj.src = this.pointerPrevInactive;
				this.pointerPrevObj.className = '';
			}
		}
	},

	checkPointerNextStatus: function() {
		if (true == this.canScrollNext()) {
			if ('active' != this.pointerNextObj.className) {
				this.pointerNextObj.src = this.pointerNextActive;
				this.pointerNextObj.className = 'active';
			}
		} else {
			if ('' != this.pointerNextObj.className) {
				this.pointerNextObj.src = this.pointerNextInactive;
				this.pointerNextObj.className = '';
			}
		}
	},

	checkPointerFirstStatus: function() {
		if (true == this.canScrollFirst()) {
			if ('active' != this.pointerFirstObj.className) {
				this.pointerFirstObj.src = this.pointerFirstActive;
				this.pointerFirstObj.className = 'active';
			}
		} else {
			if ('' != this.pointerFirstObj.className) {
				this.pointerFirstObj.src = this.pointerFirstInactive;
				this.pointerFirstObj.className = '';
			}
		}
	},

	checkPointerLastStatus: function() {
		if (true == this.canScrollLast()) {
			if ('active' != this.pointerLastObj.className) {
				this.pointerLastObj.src = this.pointerLastActive;
				this.pointerLastObj.className = 'active';
			}
		} else {
			if ('' != this.pointerLastObj.className) {
				this.pointerLastObj.src = this.pointerLastInactive;
				this.pointerLastObj.className = '';
			}
		}
	},

	canScrollPrev: function() {
		return (this.currentScroll > this.minScroll);
	},

	canScrollNext: function() {
		return (this.currentScroll < this.maxScroll);
	},

	canScrollFirst: function() {
		return (this.minScroll < this.currentScroll);
	},

	canScrollLast: function() {
		return (this.maxScroll > this.currentScroll);
	},

	clearThumbSelection: function() {
		for (var i = 0; i < this.imageList.length; i++) {
			this.imageList[i].clearSelection();
		}
	},

	showFull: function(id) {
		var i = 0;
		var found = false;
		while ((i < this.imageList.length) && (false == found)) {
			if (id == this.imageList[i].imageID) {
				this.fullObj.innerHTML = this.imageList[i].previewHtml();
				found = true;
			}
			i++;
		}
	},

	scrollToImage: function(id) {
		if (undefined == id) {
			id = this.imageList[0].imageID;
		}
		var i = 0;
		var found = false;
		var scrollX = 0;
		while ((i < this.imageList.length) && (false == found)) {
			scrollX += this.imageList[i].thumbWidth + 7;
			if (id == this.imageList[i].imageID) {
				if (0 < (scrollX - this.listObj.offsetWidth)) {
					this.getFrameWindow().scrollTo((scrollX - this.listObj.offsetWidth), 0);
					this.currentScroll = parseInt((scrollX - this.listObj.offsetWidth));
					this.checkPointerPrevStatus();
					this.checkPointerNextStatus();
				}
				found = true;
			}
			i++;
		}
	},

	selectImage: function(id) {
		if (undefined == id) {
			id = this.imageList[0].imageID;
		}
		var i = 0;
		var found = false;
		while ((i < this.imageList.length) && (false == found)) {
			if (id == this.imageList[i].imageID) {
				this.imageList[i].select();
				found = true;
			}
			i++;
		}
		if (false == found) {
			this.imageList[0].select();
		}
	},

	checkThumbVisibility: function(id) {
		var i = 0;
		var found = false;
		var scrollBefore = 4;
		var scrollAfter = 0;
		var image = null;
		while ((i < this.imageList.length) && (false == found)) {
			if (id == this.imageList[i].imageID) {
				image = this.imageList[i];
				found = true;
			} else {
				scrollBefore += this.imageList[i].thumbWidth + 7;
			}
			i++;
		}

		var leftOver = 0;
		var rightOver = 0;
		rightOver = scrollBefore + image.thumbWidth - this.currentScroll - this.listObj.offsetWidth;
		leftOver = image.thumbWidth - (scrollBefore + image.thumbWidth - this.currentScroll);

		if (0 < leftOver) {
			this.scrollPrev(leftOver + 4);
		} else if (0 < rightOver) {
			this.scrollNext(rightOver);
		}
	}
}

function ImageGalleryItem(id, thumb_src, thumb_width, thumb_height, middle_src, middle_width, middle_height, large_src, large_width, large_height) {
	this.imageID = id;

	this.thumbSrc = thumb_src;
	this.thumbWidth = thumb_width;
	this.thumbHeight = thumb_height;
	this.middleSrc = middle_src;
	this.middleWidth = middle_width;
	this.middleHeight = middle_height;
	this.largeSrc = large_src;
	this.largeWidth = large_width;
	this.largeHeight = large_height;

	this.parent = null;
	this.thumbSource = null;
	this.selected = false;
	this.thumbObj = null;
}
ImageGalleryItem.prototype = {
	thumbHtml: function() {
		var h = '<img src="' + this.thumbSrc + '" width="' + this.thumbWidth + '" height="' + this.thumbHeight + '" vspace="0" hspace="0" border="0" alt="" id="thumb' + this.imageID + '" />';
		return h;
	},

	thumbRegister: function() {
		var thisCopy = this;
		this.thumbObj = this.thumbSource.document.getElementById('thumb' + this.imageID);
		register_event(this.thumbObj, 'click', function() {return thisCopy.onThumbClick()});
		register_event(this.thumbObj, 'mouseover', function() {return thisCopy.onThumbMouseOver()});
		register_event(this.thumbObj, 'mouseout', function() {return thisCopy.onThumbMouseOut()});
	},

	previewHtml: function() {
		var h = '';
		if (this.largeSrc) {
			h += '<a href="' + this.largeSrc + '" onclick="popup_img(this.href, ' + this.largeWidth + ', ' + this.largeHeight + ', \'Русский Рукопашный Бой\'); return false;">';
		}
		h += '<img src="' + this.middleSrc + '" width="' + this.middleWidth + '" height="' + this.middleHeight + '" vspace="0" hspace="0" border="0" alt="" />';
		if (this.largeSrc) {
			h += '</a>';
		}
		return h;
	},

	onThumbClick: function() {
		this.select();
	},

	onThumbMouseOver: function() {
		if (false == this.selected) this.thumbObj.className = 'over';
	},

	onThumbMouseOut: function() {
		if (false == this.selected) this.thumbObj.className = '';
	},

	select: function() {
		if (false == this.selected) {
			this.parent.clearThumbSelection();
			this.parent.showFull(this.imageID);
			this.parent.checkThumbVisibility(this.imageID);
			this.selected = true;
			this.thumbObj.className = 'selected';
		}
	},

	clearSelection: function() {
		this.selected = false;
		this.thumbObj.className = '';
	}
}