// pDiv is the id of the div to be positioned as a String
// pPlaceHolder is the id of the placeholder of the div as a String
function adjustDiv(pDiv, pPlaceHolder, pLeftAdj, pTopAdj)
{
	var par = (pPlaceHolder.tagName ? pPlaceHolder : document.getElementById(pPlaceHolder));
	var left=par.offsetLeft;
	var top=par.offsetTop;
	var div=(pPlaceHolder.tagName ? pDiv : document.getElementById(pDiv));

	while (par.tagName!=div.offsetParent.tagName)
	{
		par=par.offsetParent;
		left+=par.offsetLeft;
		top+=par.offsetTop;
	}
	div.style.left=left+pLeftAdj;
	div.style.top=top+pTopAdj;
}
DIV={

	/**
	 *	Positions a floating div by a placeholder element
	 */
	adjust:function(pDiv, pPlaceHolder, pLeftAdj, pTopAdj) {
		var par=pPlaceHolder;
		var left=pPlaceHolder.offsetLeft;
		var top=pPlaceHolder.offsetTop;
		var div=pDiv;

		while (par.tagName!=pDiv.offsetParent.tagName) {
			par=par.offsetParent;
			left+=par.offsetLeft;
			top+=par.offsetTop;
		}
		div.style.left=left+pLeftAdj;
		div.style.top=top+pTopAdj;
	}
};

DIV.Zoomer=function(pInstance,pMaxSize,pPosTop,pPosLeft,pPixelWidth,pPixelHeight) {
	if (!pMaxSize) {
		pMaxSize=150;
	}
	if (!pPosTop) {
		pPosTop=2;
	}
	if (!pPosLeft) {
		pPosLeft=2;
	}
	if (!pPixelWidth) {
		pPixelWidth=4;
	}
	if (!pPixelHeight) {
		pPixelHeight=4;
	}
	
	this.timeout=0;
	this.scale=function(pImg,pDiv) {
		if (pImg.style.pixelWidth<pMaxSize) {
			pDiv.style.posTop -= pPosTop;
			pDiv.style.posLeft -= pPosLeft;
			pImg.style.pixelWidth += pPixelWidth;
			pImg.style.pixelHeight += pPixelHeight;
			this.timeout=window.setTimeout(pInstance+".scale(document.getElementById('"+pImg.id+"'),document.getElementById('"+pDiv.id+"'));", 1);
		}else {
			if (this.timeout) {
				clearTimeout(this.timeout);
				this.timeout=0;
			}
		}
	}

	this.oculta=function(pImg,pDiv) {
		if (this.timeout) {
			clearTimeout(this.timeout);
			this.timeout=0;
		}
		pDiv.style.display="none";

	}

	this.mostraDiv=function(pImg,pDiv) {
		pDiv.innerHTML='<img id="DIVZoomerImagem" src="'+pImg.src+'" style="width:'+pImg.width+'px;height:'+pImg.height+'px;"'
						+' onMouseOver="'+pInstance+'.scale(this,this.parentNode);"'
						+' onMouseOut="'+pInstance+'.oculta(this,this.parentNode);"'
						+'">';
		DIV.adjust(pDiv, pImg, 0, 0);
		pDiv.style.display="block";
	}

}

