var isRunning = false;
var limitHeight = 300;
var natHeight;

function applyResizer(divID,newHeight,flg) {
	var obj = document.getElementById(divID);
	var imgList = obj.getElementsByTagName("IMG");
	for (var i = 0; i < imgList.length; i++) {
		var img = imgList[i];
		img.removeAttribute('width');
		img.removeAttribute('height');
		img.height = newHeight;
		img.onmousemove = function(e) {
			var natHeight	=	getNaturalHeight(this);
			var natWidth	=	getNaturalWidth(this);
			natWidth=Math.round(natWidth/natHeight*200);
			natHeight=200;
			var iPopUp = document.getElementById('imagePopUp');
			iPopUp.innerHTML= '<img src="' + this.src.replace(new RegExp(newHeight,'g'),'200') + '" id="bigPopUpImage">';
			var cursor=getPosition(e);
			cursor={
				x:Math.round(-275+cursor.x-50-natWidth),
				y:Math.round(-280+cursor.y-natHeight/2)
			};
			iPopUp.style.position='absolute';
			iPopUp.style.left=cursor.x+'px';
 			iPopUp.style.top=cursor.y+'px';
			iPopUp.style.display = 'block';
			this.onmouseout = function() {
				hide();//hideEffect(newHeight);
			}
		}
	}
}

function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    }
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX +
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY +
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}

function findPos(obj) {
	var curleft=obj.offsetLeft;
	var curtop=obj.offsetTop;
	if (typeof obj.parentNode!='undefined') {
		if (typeof obj.parentNode.offsetLeft!='undefined') {
			var coord=findPos(obj.parentNode);
			curleft=curleft+coord[0];
			curtop=curtop+coord[1];
		}
	}
	return [curleft,curtop];
}

function showEffect()
{
	isRunning = true;
	var img = document.getElementById('bigPopUpImage');
	if ((img.height < (natHeight + 3)) && (img.height < (limitHeight + 3)))
	{
		img.height += 3;
		setTimeout("showEffect()", 10);
	}
	else
	{
		if (natHeight < limitHeight) img.height = natHeight;
		else img.height = limitHeight;
		isRunning = false;
	}
}

function hideEffect(newHeight)
{
	var img = document.getElementById('bigPopUpImage');
	if (!isRunning)
	{
		if (img.height > newHeight)
		{
			img.height -= 3;
			setTimeout('hideEffect('+newHeight+')', 10);
		}
		else hide();
	}
	else
	{
		hide();
	}
}

function hide()
{
	var iPopUp = document.getElementById('imagePopUp');
	iPopUp.style.display = 'none';
}

function getNaturalHeight(img) {
    if (!img.complete) {
        return false;
    }
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        return false;
    }
    if (img.naturalHeight)
    {
        return img.naturalHeight;
    }
    else
    {
        var lgi = new Image();
        lgi.src = img.src;
        return lgi.height;
    }
}

function getNaturalWidth(img) {
    if (!img.complete) {
        return false;
    }
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        return false;
    }
    if (img.naturalWidth)
    {
        return img.naturalWidth;
    }
    else
    {
        var lgi = new Image();
        lgi.src = img.src;
        return lgi.width;
    }
}