
/*
*******************************
Document magnifying script
Written by Christian Patzer
cpatzer@hotmail.com
VERSION 2.0
  Revamped GUI
  Added resize functionality
  Added zoomFactor adjustability
  Added baseDir var for centralized distribution of files
  Added handle for A tag occurences within the magnifier
For this script and more, visit http://www.dynamicdrive.com
*******************************
*/



if(window.createPopup){
	ie55 = true;
}
else {
	ie55 = false;
}

if(ie55){
	document.write(zoomBoxHTML);	
}


function activateResize(){
	objToResize = document.getElementById('magContainer');
	document.getElementById('resizeObj').attachEvent('onmousemove',resizeMag);
	zoomIframe = document.getElementById('zoom');
	rX=event.clientX;
	rY=event.clientY;
	tempW = parseInt(objToResize.width);
	tempH = parseInt(objToResize.height);
	resizeInitialized=true;
}

function resizeMag(){
	if(resizeInitialized){
		doWidth = (event.clientX-rX)+parseInt(tempW);
		doHeight = (event.clientY-rY)+parseInt(tempH);
		if(doWidth>0)objToResize.width=doWidth;
		if(doWidth>0)zoomIframe.width=doWidth;
		if(doHeight>0)objToResize.height=doHeight;
		if(doHeight>0)zoomIframe.height=doHeight;
		return false;
	}
}

function moveZoomBox(){
	if(initialized==true){
		zoomBox.style.pixelLeft=tempX+event.clientX-X;
		zoomBox.style.pixelTop=tempY+event.clientY-Y;
		document.frames.zoom.scrollTo(tempX+event.clientX-X,tempY+event.clientY-Y);
		return false;
	}
}

function  initXY(){
	X=event.clientX;
	Y=event.clientY;
        document.body.onselectstart=new Function("return false")
	tempX=zoomBox.style.pixelLeft;
	tempY=zoomBox.style.pixelTop;
	initialized=true;
	document.onmousemove=moveZoomBox;	
}

function resize(){
	if(ie55){
		zoomBox.style.pixelLeft=0;
		zoomBox.style.pixelTop=0;
		document.frames.zoom.scrollTo(0,0);
		//document.frames.zoom.document.all.tags("TABLE")[1].width=document.body.offsetWidth - 25;
	}
}

function init(){
	if(ie55) {
		var HTMLtoGrab = document.all.tags("HTML")[0].innerHTML;
		var HTMLtoWrite = HTMLtoGrab;
		var HTMLtoWrite = "<HTML>"+HTMLtoWrite+"</HTML>";
		zoomBox=document.getElementById('zoomBox');
		//zoomBox.style.visibility = "visible";
		zoomBox.style.visibility = "hidden";
		document.frames.zoom.document.getElementById('writeToMe').outerHTML = HTMLtoWrite;
		document.frames.zoom.document.getElementById('zoomBox').style.visibility="hidden";
		document.frames.zoom.document.body.scroll='no';
		zoomObjStyle = document.frames.zoom.document.body.style;
		zoomObjStyle.zoom=startZoom;
		document.frames.zoom.scrollTo(0,0);
		document.frames.zoom.document.body.mergeAttributes(document.body);
		for(var i=0; i<document.frames.zoom.document.all.tags("A").length; i++){
			document.frames.zoom.document.all.tags("A")[i].target="_top";
		}
		resize();	
	}
}

function zoomIn(){
	if(ie55) {
		zoomObjStyle.zoom=parseInt(zoomObjStyle.zoom)+zoomFactor+'%';	
	}
}

function zoomOut(){
	if(ie55) {
		if(parseInt(zoomObjStyle.zoom) <= zoomFactor)return false;
		zoomObjStyle.zoom=parseInt(zoomObjStyle.zoom)-zoomFactor+'%';
	}
}

function hideZoomBox(){
	if(ie55) {
		zoomBox.style.visibility="hidden";
	}
}

function showZoomBox(){
	if(ie55) {
		zoomBox.style.visibility="visible";
	}
}

function disable(){
	if(ie55) {
	    document.body.onselectstart=new Function("return true")
		initialized=false;
		document.getElementById('resizeObj').detachEvent('onmousemove',resizeMag);
		resizeInitialized=false;
	}
}

window.onload=init;
window.onresize=resize;
document.onmouseup=disable;