function test(oThumb)
{
	this.oThumb = oThumb;
	var tst;
	var cw = document.body.clientWidth;
	var ch = document.body.clientHeight;
	var cx = document.body.scrollLeft + cw / 2;
	var cy = document.body.scrollTop + ch / 2;

tst = 'this.oThumb.offsetLeft = '+ this.oThumb.offsetLeft + ' this.oThumb.offsetTop = '+ this.oThumb.offsetTop;
//tst += '<br>this.oThumb.x = ' +this.oThumb.Left + ' this.oThumb.y = ' + this.oThumb.y;
tst += '<br>this.oThumb.clientWidth = ' +this.oThumb.clientWidth + ' this.oThumb.clientHeight = ' + this.oThumb.clientHeight;
tst += '<br>this.oThumb.offsetWidth = ' +this.oThumb.offsetWidth + ' this.oThumb.offsetHeight = ' + this.oThumb.offsetHeight;
//tst += '<br>this.offsetParent Left: ' + this.oThumb.offsetParent.offsetParent.offsetLeft;
//tst += '<br>this.offsetParent Top: ' + this.oThumb.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
tst += '<br>document.body.clientWidth: ' + cw;
tst += '<br>document.body.clientHeight: ' + ch;
	var gallery = document.getElementById("gallery");
	gallery.innerHTML = tst;
}
function Zoomer(oThumb, sImgSrc)
{
	this.oThumb = oThumb;
	this.oThumb.expander = this;
	this.oThumb.onclick = function() { this.expander.expand(); }
	this.smallWidth = oThumb.offsetWidth;
	this.smallHeight = oThumb.offsetHeight;	
	this.bExpand = true;
	this.bTicks = false;
	if ( !window.aZoomers )
	{
		window.aZoomers = new Array();
	}
	window.aZoomers.push(this);
	this.oImg = new Image();
	this.oImg.expander = this;
	this.oImg.onload = function(){this.expander.onload();}
	this.oImg.src = sImgSrc;
}

Zoomer.prototype.onload = function()
{
	this.oDiv = document.createElement("div");
	var gallery = document.getElementById("gallery");
	if (gallery == null) var gallery = document.getElementById("decol");
	gallery.appendChild(this.oDiv);
	//document.body.appendChild(this.oDiv);
	this.oDiv.appendChild(this.oImg);
	this.oDiv.style.position = "absolute";
	this.oDiv.expander = this;
	this.oDiv.onclick = function() {this.expander.toggle();};
	this.oImg.title = "Нажмите для уменьшения";
	this.bigWidth = this.oImg.width;
	this.bigHeight = this.oImg.height;
	
	if ( this.bExpand )
	{
		this.expand();
	}
	else
	{
		this.oDiv.style.visibility = "hidden";
		this.oImg.style.visibility = "hidden";
	}
}
Zoomer.prototype.toggle = function()
{
	this.bExpand = !this.bExpand;
	if ( this.bExpand )
	{
		for ( var i in window.aZoomers )
			if ( window.aZoomers[i] !== this )
				window.aZoomers[i].reduce();
	}
}
Zoomer.prototype.expand = function()
{
	this.bExpand = true;
	for ( var i in window.aZoomers )
		if ( window.aZoomers[i] !== this )
			window.aZoomers[i].reduce();
	if ( !this.oDiv ) return;
	this.oThumb.style.visibility = "hidden";
	this.x = this.oThumb.offsetLeft;// + 218;
	this.y = this.oThumb.offsetTop;// + 342;
	this.w = this.oThumb.clientWidth;
	this.h = this.oThumb.clientHeight;
	
	this.oDiv.style.left = this.x + "px";
	this.oDiv.style.top = this.y + "px";
	this.oImg.style.width = this.w + "px";
	this.oImg.style.height = this.h + "px";
	this.oDiv.style.visibility = "visible";
	this.oImg.style.visibility = "visible";
	if ( !this.bTicks )
	{
		this.bTicks = true;
		var pThis = this;
		window.setTimeout(function(){pThis.tick();},25);	
	}
}
Zoomer.prototype.reduce = function()
{
	this.bExpand = false;
}
Zoomer.prototype.tick = function()
{
	var cw = document.body.clientWidth-300;
	var ch = document.body.clientHeight-250;
	var cx = document.body.scrollLeft + cw / 2;
	var cy = document.body.scrollTop + ch / 2;
	var tw,th,tx,ty;
	if ( this.bExpand )
	{
		tw = this.bigWidth;
		th = this.bigHeight;
		if ( tw > cw )
		{
			th *= cw / tw;
			tw = cw;
		}	
		if ( th > ch )
		{
			tw *= ch / th;
			th = ch;
		}
		tx = cx - tw / 2;
		ty = cy - th / 2; 
	}
	else
	{
		tw = this.smallWidth;
		th = this.smallHeight;
		tx = this.oThumb.offsetLeft;// + 218;
		ty = this.oThumb.offsetTop;// + 342;
	}	
	var nHit = 0;
	var fMove = function(n,tn) 
	{
		var dn = tn - n;
		if ( Math.abs(dn) < 3 )
		{
			nHit++;
			return tn;
		}
		else
		{
			return n + dn / 10;
		}
	}
	this.x = fMove(this.x, tx);
	this.y = fMove(this.y, ty);
	this.w = fMove(this.w, tw);
	this.h = fMove(this.h, th);
	
	this.oDiv.style.left = this.x + "px";
	this.oDiv.style.top = this.y + "px";
	this.oImg.style.width = this.w + "px";
	this.oImg.style.height = this.h + "px";
	if ( !this.bExpand && (nHit == 4) )
	{
		this.oImg.style.visibility = "hidden";
		this.oDiv.style.visibility = "hidden";
		this.oThumb.style.visibility = "visible";

		this.bTicks = false;
	}
	if ( this.bTicks )
	{
		var pThis = this;
		window.setTimeout(function(){pThis.tick();},25);
	}
}
