
// Test browser state.
isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isShowing=false;

isInit = false;



function initZooming() {
	// Add the window for the zoom.
	var bodyElem = document.getElementById('mainbody');
	var zoomBack = document.createElement("div");
	zoomBack.setAttribute('id', "thumbzoomback");
	var zoomWindow = document.createElement("div");
	var zoomWindowIdName = "thumbzoom";
	var zoomImage = document.createElement("img");
	zoomImage.setAttribute('id',"thumbzoomimage");

	zoomBack.setAttribute("onmouseup","hideZoom();");
	zoomBack.onmouseup = hideZoom;

	zoomWindow.appendChild(zoomImage);
	zoomWindow.setAttribute('id', zoomWindowIdName);
	bodyElem.appendChild(zoomWindow);
	bodyElem.appendChild(zoomBack);
}

function showZoom(e, imgref){
	if (isShowing) {
		hideZoom();
		return;
	}
	// Javascript mouse coordinate is highly
	// browser dependent (nice).  This should work across 
	// platforms.
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
	if (!isInit) {
		initZooming();
		isInit = true;
	}
	var zoomWindow = document.getElementById("thumbzoom");
	var zoomImage = document.getElementById("thumbzoomimage");
	
	
	
	zoomImage.setAttribute('src', imgref);
	zoomImage.onmouseup = hideZoom;
	zoomImage.onload = imageLoaded;
	zoomWindow.setAttribute("onmouseup","hideZoom();");
	
	if (posy < 50) {
		posy = 50;
	}
	zoomWindow.style.top= posy-50 + 'px'; 
	zoomWindow.style.left =  '10px'; //posx + 'px';
}

function imageLoaded() {
	var zoomWindow = document.getElementById("thumbzoom");
	var zoomBack = document.getElementById("thumbzoomback");

	zoomBack.style.visibility = "visible";
	zoomWindow.style.visibility = "visible";
	isShowing = true;
}

function hideZoom(e){
	var zoomWindow = document.getElementById("thumbzoom");
	if (zoomWindow != null) {
		var zoomImage = document.getElementById("thumbzoomimage");
		var zoomBack = document.getElementById("thumbzoomback");

		zoomWindow.style.visibility = "hidden";
		zoomBack.style.visibility = "hidden";
		isShowing = false;
	}
}
