var maxsize = 150; //Maximum Size
var minsize = 60; //Minimum Size
var speed=1; //1: Fastest
var obj,myzoom;
var orgThumbImg=new Array(); //Array to hold the original size of image

function getCSSValue(object, strCSS)
{
	var varValue;

	//  Falls der Brower die Methode "getComputedStyle" kennt (W3C-DOM)
	if(window.getComputedStyle)
	{
		varValue = window.getComputedStyle(object, null)[strCSS];
	}
	//  Falls der Browser die Methode "currentStyle" kennt (neuere IEs)
	else if(object.currentStyle)
	{
		varValue = object.currentStyle[strCSS];
	}

	return varValue;
}

function zoomMyImages()
{
	var isIe = navigator.userAgent.search(/msie/i);
	var e = document.getElementsByTagName("img")
	for (var i=0; i < e.length; i++)
	{
		if (e[i].getAttribute('rel')=="zoomimage")
		{
//			e[i].setAttribute('onmouseover','zoom(this)');
//			e[i].setAttribute('onmouseout','unzoom(this)');
			e[i].onmouseover=function() {zoom(this);}
			e[i].onmouseout=function() {unzoom(this);}
			e[i].style.position='relative';
			e[i].style.marginTop=0+'px';
			org_width=e[i].width;
			org_height=e[i].height;
			if (org_height > maxsize)
			{
				if (org_width > org_height)
				{
					n=org_width/maxsize;
					org_height=org_height/n;
					org_width=maxsize;
				}
				else
				{
					n=org_height/maxsize;
					org_width=org_width/n;
					org_height=maxsize;
				}
			}
			if (e[i].width > e[i].height)
			{
				n=e[i].width/minsize;
				e[i].style.height=e[i].height/n+'px';
				e[i].style.width=minsize+'px';
			}
			else
			{
				n=e[i].height/minsize;
				e[i].style.width=e[i].width/n+'px';
				e[i].style.height=minsize+'px';
			}
			e[i].style.visibility = "visible";
			if(isIe != -1)
			{
				frame = 0;
				//frame = atol(getCSSValue(e[i], 'padding'));
				//alert("Frame = '"+frame+"'");
				orgThumbImg[orgThumbImg.length] = new Array(e[i],0,org_width,org_height,e[i].width-frame,e[i].height-frame); //store reference to target image
			}
			else
				orgThumbImg[orgThumbImg.length] = new Array(e[i],0,org_width,org_height,e[i].width,e[i].height); //store reference to target image
		}
	}
}

function zoom(obj) {
	for (var i=0; i < orgThumbImg.length; i++)	{
		if (orgThumbImg[i][0]==obj)	{
			e=orgThumbImg[i];
			clearTimeout(e[7]);
//			obj.style.zIndex = '80';
			c=e[1];
			max_w=e[2];
			max_h=e[3];
			min_w=e[4];
			min_h=e[5];
			if(c>100) return;
			if(c<1) c=1;
			dw = max_w - min_w;
			dh = max_h - min_h;
			stp_w = dw * c / 100;
			stp_h = dh * c / 100;
			obj.style.marginTop=-stp_h+'px';
			obj.style.width=stp_w+min_w+'px';
			obj.style.height=stp_h+min_h+'px';
			obj.style.top=stp_h/2+'px';
			if (c < 20)
				c+=5;
			else
				c+=c/5;
			if (c > 101)
				c=100;
			e[1]=c;
			e[6]=setTimeout(function(){zoom(obj)},speed);
		}
	}
}

function unzoom(obj) {
	for (var i=0; i < orgThumbImg.length; i++)	{
		if (orgThumbImg[i][0]==obj)	{
			e=orgThumbImg[i];
			clearTimeout(e[6]);
//			obj.style.zIndex = '75';
			c=e[1];
			max_w=e[2];
			max_h=e[3];
			min_w=e[4];
			min_h=e[5];
			if(c<0)
			{
//				obj.style.zIndex = '70';
				return;
			}
			if(c>100) c=100;
			dw = max_w - min_w;
			dh = max_h - min_h;
			stp_w = dw * c / 100;
			stp_h = dh * c / 100;
			obj.style.marginTop=-stp_h+'px';
			obj.style.width=stp_w+min_w+'px';
			obj.style.height=stp_h+min_h+'px';
			obj.style.top=stp_h/2+'px';
			if (c <= 1)
				c--;
			else
				c-=c/4;
			if (c < -1)
				c=0;
			e[1]=c;
			e[7]=setTimeout(function(){unzoom(obj)},speed);
		}
	}
}

window.onload=zoomMyImages;
