var imageDetail = {	

	addImage : function (id, isIm, picname, ocko, boxSizeX, boxSizeY, stPosX, stPosY) {
		var x 		= dom.gI(id);
		if ((typeof(x) != "undefined") && (x.nodeName.toLowerCase() == "img")) {

			if (typeof(x.lastZIndex) == "undefined")		x.lastZIndex = 50;
			else							x.lastZIndex++;
			if (navigator.userAgent.indexOf('MSIE 5') == -1) 	x.fixBM = 0;		else x.fixBM = 2;
			
			imageDetail._makeImgHolder(x);
			c = imageDetail._makeImageDiv(x, isIm, picname, ocko, boxSizeX, boxSizeY, stPosX, stPosY);
			
			return false;
		}
	},
	
	_makeImgHolder : function (x) {
		if (!x.holder) {
			var holder = dom.cE('div');			x.holder = holder;
			holder.style.position	= 'relative';		holder.style.backgroundColor	= '#fff';		
			holder.style.width	= x.width + 'px';	holder.style.height		= x.height + 'px'; 	
			dom.aC(x.parentNode, holder);
			dom.aC(holder, x);
		}
	},
	
	_makeImageDiv : function (x, isIm, picname, ocko, boxSizeX, boxSizeY, stPosX, stPosY) {
		var c		= dom.cE('div');	c.imageObject	= x; 		c.boxId		= x.lastZIndex;	
		c.boxSizeX	= boxSizeX;		c.boxSizeY	= boxSizeY;	c.picname	= picname;	c.isIm = isIm;	
		
		c.posX	= stPosX - boxSizeX;		c.posY		= stPosY - boxSizeY;
		c.width	= 2 * boxSizeX;			c.height	= 2 * boxSizeY;
		
		if (c.posX < 0) c.posX = 0;		if (c.posY < 0) c.posY = 0;
		if (c.posX + c.width > x.width) 	c.posX = x.width - c.width;
		if (c.posY + c.height > x.height) 	c.posY = x.height - c.height;
		
		c.tmpNewH = c.height;	c.tmpNewW = c.width;		c.tmpPosX = c.posX;	c.tmpPosY = c.posY;
		
		c.className	= 'cropBox';				c.style.position	= 'absolute';
		c.style.cursor	= 'pointer';				c.id			= x.id + "_detail_" + c.boxId;
		c.style.width	= c.width + (x.fixBM) + 'px';		c.style.height		= c.height + (x.fixBM) + 'px';
		c.style.background = 'transparent url(' + ocko + ') no-repeat';
		
		c.style.left	= c.posX + 'px';			c.style.top		= c.posY + 'px';
		c.style.border	= '0px';				c.style.overflow	= 'visible';
		c.style.zIndex	= x.lastZIndex;				c.offX = 0;		c.offY = 0;
		if (c.isIm == 1) {
			c.onmouseover	= function() {
					var d  = document;
					var im = dom.cE('img');			im.id = "detailImage";
					im.src = picname;			im.style.zIndex = 150;
					im.style.position = 'absolute';		im.style.border = 'solid 2px #aaa';
					var mainImW = c.imageObject.width;	var mainImH = c.imageObject.height;
					
					var detailH	= d.MM_p[c.boxId - 50].height;
					var detailW	= d.MM_p[c.boxId - 50].width;
					var imT		= c.posY + (c.height / 2) - Math.floor(detailH / 2);
					var imL		= c.posX + c.width + 10;
					
					if (imT < 0)				imT = 0;
					if ((imT + detailH) > mainImH)		imT = mainImH - detailH;
					if ((imL + detailW) > (mainImW + 90))	imL = c.posX - detailW - 10;				
					im.style.top	= imT + 'px';
					im.style.left	= imL + 'px';
					
					dom.aC(c.imageObject.parentNode, im);
				}
		} else {
			c.onmouseover	= function() {
					var d  = document;
					var im = dom.cE('div');			im.id = "detailImage";
					var ihtmstr	= picname.replace("((", "<b>");
					ihtmstr		= ihtmstr.replace("))", "</b>");
					ihtmstr		= ihtmstr.replace("**", "<br>");
					im.innerHTML = ihtmstr;			im.style.zIndex = 150;
					im.style.position = 'absolute';		im.style.border = 'solid 2px #aaa';
					im.style.font = "normal 10px arial";	im.style.background = "#fff";
					im.style.padding = "5px";		im.align = "left";
					
					//im.style.height = detailH + "px";	im.style.width	= detailW + "px";
					
					var mainImW = c.imageObject.width;	var mainImH = c.imageObject.height;
					dom.aC(c.imageObject.parentNode, im);
					
					var detailH	= vyskaObj(im);			var detailW	= sirkaObj(im);
					if (detailH > 120) {	detailH = 120;		im.style.height = detailH + "px";	}
					if (detailW > 200) {	detailW = 200;		im.style.width	= detailW + "px";	}
					
					var imT		= c.posY + (c.height / 2) - Math.floor(detailH / 2);
					var imL		= c.posX + c.width + 10;
					//alert(vyskaObj(im) + " x " + sirkaObj(im));
					if (imT < 0)				imT = 0;
					if ((imT + detailH) > mainImH)		imT = mainImH - detailH;
					if ((imL + detailW) > (mainImW + 90))	imL = c.posX - detailW - 20;				
					im.style.top	= imT + 'px';
					im.style.left	= imL + 'px';
					
					//dom.aC(c.imageObject.parentNode, im);
				}
		}
		c.onmouseout	= function() { 
					if(dom.gI('detailImage') != null) 	dom.rC(dom.gI('detailImage'), c.imageObject.parentNode);
				}
		dom.aC(x.parentNode,c);
		
		return c;
	}
}
