IE4 = (document.all) ? 1 : 0;
NS4 = (document.layers) ? 1 : 0;
DOM1 = (!IE4 && document.getElementById) ? 1 : 0;
ver4 = (IE4 || NS4 || DOM1) ? 1 : 0;

if (ver4) {
    whichIm = null;
    zoomed = false;

    scale = 2.0;

    allPics = false;
    noLinks = false;
    justGIFs = false;
    justJPGs = false;
    byName = true;

    inWind = false;

    useName = "zoom";

    if(NS4){ 
        document.captureEvents(Event.MOUSEDOWN);
        document.onmousedown = findIt;
    } 
    else if(IE4){
		document.onclick = findIt;
	}
	else{
		document.addEventListener("click", findIt, false);
	}
}

function findIt(e) {

	old_whichIm = whichIm;
	old_zoomed = zoomed;

    if (zoomed) zoomIn();

	isImage = false;

    if(NS4) {
        if (e.target == "[object Image]") {
            whichIm = e.target;
        	isImage = true;
        }
    }
    else if (IE4) {
        if(event.srcElement.tagName == "IMG"){
        	whichIm = event.srcElement;
			isImage = true;
		}
    }
	else{	
		if(e.target.nodeName == "IMG"){
			whichIm = e.target;
			isImage = true;
		}
	}

	if(!isImage || (old_whichIm == whichIm && old_zoomed == true)) return 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) {
        if (IE4 || DOM1) {
            if (inWind) { zoomOutInEl() }
            else { zoomOutInPage() };
            return false;
        }
        else {
			zoomOutInEl();
			return false;
		}
    }
	return true
}

function zoomOutInPage() {
    whichIm.width = whichIm.width * scale;
    whichIm.height = whichIm.height * scale;
    zoomed = true;
}

function zoomOutInEl(){
    newWidth  = whichIm.width * scale;
    newHeight = whichIm.height * scale;
    bigImStr = "<IMG NAME='imBig' SRC=\"" + whichIm.src + "\" WIDTH=" + newWidth + " HEIGHT=" + newHeight + " BORDER=0>";
    
    if (NS4) {
        with (document.elZoom.document) {
            open();
            write(bigImStr);
            close();
        }
    }
    else { elZoom.innerHTML = bigImStr };

    if (NS4) {
        document.elZoom.moveTo(whichIm.x,whichIm.y);
        winPosL = document.elZoom.left - pageXOffset;
        winPosT = document.elZoom.top - pageYOffset;
    }
    else {
        document.elZoom.left = whichIm.offsetLeft + whichIm.hspace;
        document.elZoom.top = whichIm.offsetTop;
        winPosL = elZoom.offsetLeft - document.body.scrollLeft;
        winPosT = elZoom.offsetTop - document.body.scrollTop;
    }

    winWidth = (NS4) ? window.innerWidth  : document.body.clientWidth;
    winHeight = (NS4) ? window.innerHeight : document.body.clientHeight;

    if (winPosL + newWidth > winWidth) {
        newPosL = (winWidth - (winPosL + newWidth) - 30);
        document.elZoom.left = parseInt(document.elZoom.left) + newPosL;
    }

    if (winPosT + newHeight > winHeight) {
        newPosT = (winHeight - (winPosT + newHeight) - 10);
        document.elZoom.top = parseInt(document.elZoom.top) + newPosT;
    }

    document.elZoom.visibility = "visible";
    zoomed = true;
}

function zoomIn() {
    if ((IE4 || DOM1) && !inWind) {
        whichIm.width = whichIm.width/scale;
        whichIm.height = whichIm.height/scale;
    }
    else { document.elZoom.visibility='hidden' }

    zoomed = false;
}

if (ver4) {
    if(IE4 || NS4) document.write("<DIV ID='elZoom' STYLE='position: absolute; visibility: hidden;'></DIV>");
    if (IE4) { document.elZoom = document.all.elZoom.style }
}

