 IE4 = (document.all) ? 1 : 0;
 NS4 = (document.layers) ? 1 : 0;
 DOM = (navigator.userAgent.indexOf('Gecko') > 0) ? 1 : 0;
//DOM = (document.getElementById) ? 1 : 0;
ver4 = (IE4 || NS4 || DOM) ? 1 : 0;

var el, css;

if (ver4) {
	whichIm = null;
	zoomed = false;
	gotIt = false;

	scale = 6.0;

	allPics = false;
	noLinks = true;
	justGIFs = false;
	justJPGs = false;
	byName = true;

	useName = "zoom";

	if (NS4) { 
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown = findIt;
	} 
	else { document.onclick = findIt }
    
}

function findIt(e) {
	if (DOM) {
		el = document.getElementById('elZoom');
		css = el.style;
	}
	else if (IE4) {
		el = elZoom;
		css = document.elZoom;
	}
	else {
		el = document.elZoom;
		css = el;
	}

	if (zoomed) {
		zoomIn(); 
		return false;
	}

	if (IE4) {
		isImage = (event.srcElement.tagName == "IMG") ? 1 : 0;
		if (!isImage) { return true }
		whichIm = event.srcElement;
		isAnchor = (noLinks && event.srcElement.parentElement.tagName == "A") ? 1 : 0;
		isLink = (isAnchor && event.srcElement.parentElement.href) ? 1 : 0;
	}
	else {
		if (e.target=="[object Image]" || e.target=="[object HTMLImageElement]") {
			whichIm = e.target;
			isLink = false;
			gotIt = true;
		}
		else {
			isLink = true;             
			l = e.pageX; t = e.pageY;
			gotIt = getImage(l,t)
		}
		if (!gotIt) { return true };
		isImage = true;
	}

	isGIF = (justGIFs && whichIm.src.indexOf(".gif") != -1) ? 1 : 0;
	isJPG = ((justJPGs && whichIm.src.indexOf(".jpg") != -1) || (justJPGs && whichIm.src.indexOf(".jpeg")!=-1)) ? 1 : 0;
	isName = (byName && whichIm.name && whichIm.name.indexOf(useName) != -1) ? 1 : 0;
	isOK = (allPics) ? 1 : 0;

	if (justGIFs) { isOK = (isGIF) ? 1 : 0 };
	if (justJPGs) { isOK = (isJPG) ? 1 : 0 };
	if (justGIFs && justJPGs) { isOK = (isGIF || isJPG) ? 1 : 0 };
	if (noLinks) { isOK = (!isLink) ? 1 : 0 };
	if (byName) { isOK = (isName) ? 1 : 0 };

	if (isOK) {
		zoomOutInEl();
		return false 
	}
	return true
}

function getImage(l,t) {
    for (i=0; i<document.images.length; i++) {
        imX1 = document.images[i].x;
        imX2 = imX1 + document.images[i].width;
        imY1 = document.images[i].y;
        imY2 = imY1 + document.images[i].height;
        if ((l >= imX1 && l <= imX2) && (t >= imY1 && t<= imY2)) {
            whichIm = document.images[i];
            gotIt = true; break;
        } 
    } 
return gotIt    
}

function zoomOutInEl(){
	newWidth  = whichIm.width * scale;
	newHeight = whichIm.height * scale;
    
	bigImStr = "<IMG NAME='imBig' SRC=\"" + whichIm.src + "\" WIDTH=" + newWidth + " HEIGHT=" + newHeight + " BORDER=0>";
   
	if (DOM || IE4) {
		el.innerHTML = bigImStr;
	}
	else if (NS4) {
		with (el.document) {
			open();
			write(bigImStr);
			close();
		}
	}

	if (DOM) {
		css.left = getXpos(whichIm);
		css.top = getYpos(whichIm);
		winPosL = parseInt(css.left) - document.defaultView.pageXOffset;
		winPosT = parseInt(css.top) - document.defaultView.pageYOffset;
		winWidth = document.defaultView.innerWidth;
		winHeight = document.defaultView.innerHeight;
	}
	else if (NS4) {
		el.moveTo(whichIm.x,whichIm.y);
		winPosL = css.left - pageXOffset;
		winPosT = css.top - pageYOffset;
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
	}
	else {
		css.left = getXpos(whichIm) + whichIm.hspace;
		css.top = getYpos(whichIm);
		winPosL = getXpos(whichIm) - document.body.scrollLeft;
		winPosT = getYpos(whichIm) - document.body.scrollTop;
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight;
	}

   if (winPosL + newWidth > winWidth) {
        newPosL = (winWidth - (winPosL + newWidth) - 30);
        l = parseInt(css.left) + newPosL;
        if (DOM) l += 'px';
        css.left = l;
    }

    if (winPosT + newHeight > winHeight) {
        newPosT = (winHeight - (winPosT + newHeight) - 10);
        t = parseInt(css.top) + newPosT;
        if (DOM) t += 'px';
        css.top = t;
    }
    css.visibility = 'visible';
    zoomed = true;
}

function zoomIn() {
	css.visibility = 'hidden';
	gotIt = false;
	zoomed = false;
}

function getXpos(el) {
  return el.offsetLeft + (el.offsetParent ? getXpos(el.offsetParent) : 0);
}

function getYpos(el) {
  return el.offsetTop + (el.offsetParent ? getYpos(el.offsetParent) : 0);
}