	function Ofte_ImgZoom(width, height, contId)
	{
		this._width = width;
		this._height = height;
		this._contId = contId;
		this._isInit = false;
		this._zoomMode = 0;
		this._items = new Array();

		this.hasItem = function()	{
			var rtnVal = false;
			if (this._item)
			{
				rtnVal = true;
			}
			return true;
		}

		this._initTimerId = window.setInterval(createFunc(this, this._init), 100);
		this._zoomIn = createFunc(this, this.setZoomMode, 1);
		this._zoomOut = createFunc(this, this.setZoomMode, 0);
		this._stopDrag = createFunc(
			this, 
			function(event) {
				document.onmouseup = '';
				document.onmousemove = '';
			}
		);

		this._drag = createFunc(
			this,
			function(event) {
				event = event || window.event;
				var mousePos = this._getMousePos(event);
				var nX = parseInt(this._img.style.left) - (this._mousePos.x - mousePos.x);
				var nY = parseInt(this._img.style.top) - (this._mousePos.y - mousePos.y);
				if (nX < 0 && (-nX + this._width) < this._img.width)
				{
					this._img.style.left = nX + 'px';
				}
				if (nY < 0 && (-nY + this._height) < this._img.height)
				{
					this._img.style.top = nY + 'px';
				}
				this._mousePos = mousePos;
				return false;
			}
		);

		this._startDrag = createFunc(
			this, 
			function (event) {
				event = event || window.event;
				this._mousePos = this._getMousePos(event);
				document.onmouseup = this._stopDrag;
				document.onmousemove = this._drag;
				event.cancelBubble = true;
				event.returnValue = false;
				return false;
			}
		);
	}

	Ofte_ImgZoom.prototype._getMousePos = function(e) {
		return {
				x:e.clientX/* + document.body.scrollLeft - document.body.clientLeft*/,
				y:e.clientY/* + document.body.scrollTop - document.body.clientTop*/
		};
	}

	Ofte_ImgZoom.prototype.showImage = function(imgSets) {
		var img = this._img;
		if (img.complete && this._initImgTimerId)
		{
			window.clearInterval(this._initImgTimerId);
			var nLeft = 0;
			var nTop = 0;
			this._mainContainer.style.width = imgSets.width + 'px';
			this._mainContainer.style.height = imgSets.height + 'px';
			img.width = imgSets.width;
			img.height = imgSets.height;
			/*
			if (this._width < imgSets.width)
			{
				nLeft = - parseInt((imgSets.width-this._width)/2) + 'px';
				if (nLeft > 0)
				{
					nLeft = 0;
				}
			}
			img.style.left = nLeft;
			if (this._height < imgSets.height)
			{
				nTop = - parseInt((imgSets.height-this._height)/2) + 'px';
				if (nTop > 0)
				{
					nTop = 0;
				}
			}
			img.style.top = nTop;
			if (this._zoomMode == 0)
			{
				if (imgSets.width/this._width > imgSets.height/this._height)
				{
					img.width = parseInt((this._height/imgSets.height) * imgSets.width);
					img.height = this._height;
				} else {
					img.height = parseInt((this._width/imgSets.width) * imgSets.height);
					img.width = this._width;
				}
			} else {
				img.width = imgSets.width;
				img.height = imgSets.height;
			}
			*/
			this._waitDiv.style.display = 'none';
			this._waitDiv.parentNode.removeChild(this._waitDiv);
			img.style.display = '';
			this.onZoomed = function() {};
		}
	}

	Ofte_ImgZoom.prototype.setItem = function (Item) {
		this._item = Item;
		this.setZoomMode(0);
	}

	Ofte_ImgZoom.prototype.setZoomMode = function (nZoomMode) {
		if (Ofte_ImgZoom.prototype.onZoomed)
		{
			Ofte_ImgZoom.prototype.onZoomed();
		}
		this.onZoomed();
		if (this.hasItem())
		{
			this._img.style.display = 'none';
			var imgSets;
			this._zoomMode = nZoomMode;
			if (nZoomMode == 0)
			{
				imgSets = this._item.getMiddleSrc();
			} else {
				imgSets = this._item.getBigSrc();
			}

			if (this._img.src != imgSets.src)
			{
				var imgParent = this._img.parentNode;
				this._waitDiv = document.createElement('DIV');
				this._waitDiv.style.width = this._width + 'px';
				this._waitDiv.style.height = this._height + 'px';
				this._waitDiv.style.textAlign = 'center';
				this._waitDiv.style.backgroundColor = '#FFFFFF';
				this._waitDiv.style.paddingTop = parseInt(this._height/2 - 15) + 'px';
				imgParent.insertBefore(this._waitDiv, this._img);
				var imgWait = document.createElement('IMG');
				imgWait.src = 'mainsite_images/loading.gif';
				this._waitDiv.appendChild(imgWait);
				var img = document.createElement('IMG');
				img.style.position = 'relative';
				img.style.cursor = 'pointer';
				imgParent.replaceChild(img, this._img);
				this._img = img;
				this._img.style.display = 'none';
				this._img.src = imgSets.src;
				this._initImgTimerId = window.setInterval(createFunc(this, this.showImage, imgSets), 100);
			} else {
				this._img.style.display = '';
			}
			if (nZoomMode == 0)
			{
//				this._img.onclick = this._zoomIn;
				this._img.onmousedown = '';
			} else {
				this._img.onclick = '';
//				this._img.onmousedown = this._startDrag;
			}
		}
	}

	Ofte_ImgZoom.prototype._init = function() {
		var mContainer = document.getElementById(this._contId);
		if (!this._isInit && mContainer && this._initTimerId)
		{
			this._isInit = true;
			window.clearInterval(this._initTimerId);
			this._mainContainer = mContainer;
			if (this._mainContainer.childNodes[0])
			{
				var Child = this._mainContainer.childNodes[0];
			} else {
				var Child = document.createElement('img');
			}
			Child.style.position = 'relative';
			Child.style.cursor = 'pointer';
			Child.style.top = 0;
			Child.style.left = 0;
			this._img = Child;
			this._mainContainer.appendChild(this._img);

			this._mainContainer.style.overflow = 'hidden';
			this._mainContainer.style.width = this._width + 'px';
			this._mainContainer.style.height = this._height + 'px';
			this.setItem(this._items[0]);
		}
	}

	Ofte_ImgZoom.prototype.setZoomIn = function(elId) {
		var el = document.getElementById(elId);
		if (el)
		{
			el.onclick = this._zoomIn;
			el.style.cursor = 'pointer';
		}
	}

	Ofte_ImgZoom.prototype.setZoomOut = function(elId) {
		var el = document.getElementById(elId);
		if (el)
		{
			el.onclick = this._zoomOut;
			el.style.cursor = 'pointer';
		}
	}

	Ofte_ImgZoom.prototype.addItem = function(oizItem) {
		oizItem.setClickEvent(this);
		this._items.push(oizItem);
	}

	function Ofte_ImgZoom_Item(itemId, mImgSrc, bImgSrc)
	{
		this._itemId = itemId;
		this._mImgSrc = mImgSrc;
		this._bImgSrc = bImgSrc;
	}

	Ofte_ImgZoom_Item.prototype.setClickEvent = function(oiZoom) {
		var evSource = document.getElementById(this._itemId);
		if (evSource)
		{
			evSource.onclick = createFunc(this, this.show, oiZoom);
		}
	}
	Ofte_ImgZoom_Item.prototype.show = function (oiZoom) {
		oiZoom.setItem(this);
	}
	Ofte_ImgZoom_Item.prototype.getMiddleSrc = function () {
		return this._mImgSrc;
	}
	Ofte_ImgZoom_Item.prototype.getBigSrc = function () {
		return this._bImgSrc;
	}
