var zoomSize = 0.1;
var baseSice = 0.1;
var step = 0.2;
var swappedObj = null;
var w2 = 1;
var h2 = 1;
var baseHeight = 500;
var baseWidth = 700;
var commandmenu = '<form name="command1"><table width="100%" cellpadding="4" cellspacing="0" class="bo01"><tr><td valign="top">'+
					'<strong>Zoom</strong></td>'+
					'<td> - point and double click to zoom in<br> - press CTRL and double click to zoom out</td>'+
					'<td align="right" rowspan="2">' +
					'<input type="button" name="reset" value="Original Size" onclick="stopZoom()" class="bo01"></td><tr>' +
				   '<tr><td><strong>Scroll</strong></td>'+
					'<td> - press & hold left button then move your mouse to scroll</td>'+
				  '</tr></table></form>';


function setSize(oObj, flMultiplier){
    oObj.filters.item(0).M11 = flMultiplier;
    //oObj.filters.item(0).M12 = flMultiplier;
   // oObj.filters.item(0).M21 = flMultiplier;
    oObj.filters.item(0).M22 = flMultiplier;
}
function setNSSize(oObj,layerObj, flMultiplier,width){
    oObj.width = orgWidth* flMultiplier;
    if(oObj.width<window.screen.availWidth)layerObj.style.width = oObj.width;
    if(oObj.height<window.screen.availHeight)layerObj.style.height = oObj.height;
    //oObj.filters.item(0).M12 = flMultiplier;
   // oObj.filters.item(0).M21 = flMultiplier;
    //oObj.height *= flMultiplier;
}

function stopZoom(t) {
	zoomSize=baseSize;
        var zi = document.getElementById("zoomImg");
        var zl = document.getElementById("zoomLy");
	//if(IE) setSize(zi,baseSize);
        //else
	setNSSize(zi,zl,baseSize);
	zl.scrollLeft = zl.scrollTop = 0;
	//swappedObj.swapNode(t);
	//hideDiv(t);
}

//detect browser
var IE4a = 0;
var NS4a = 0;
var NS6a = 0;
function detectbrowser() {
 // alert(navigator.appVersion);
 IE = navigator.appName=='Microsoft Internet Explorer'?1:0;
 NS = navigator.appName=='Netscape'?1:0;
 OP = navigator.appName=='Opera'?1:0;
var VS = parseInt(navigator.appVersion);
if( !(IE|NS|OP) )alert('This browser:\n'+navigator.appName+' '+navigator.appVersion+'\may not be compitable');
if(IE&&(VS>=4)) { IE4a = 1; }
else if(NS&&(VS>=5)) { NS6a = 1; }
else if(NS&&(VS>=4)) { NS4a = 1; }
}

function startZoom() {
  	detectbrowser();
	var zi = document.getElementById("zoomImg");
        var zl = document.getElementById("zoomLy");
        var zm = document.getElementById("zoomMsg");
	var h = zi.clientHeight;
	var w = zi.clientWidth;

	if(h>w) {
		baseSize = baseHeight/h;

		if(baseSize < 1) {
			zl.style.height = baseHeight;
			zl.style.width = parseInt(baseHeight*w/h);
		}
	} else {
		baseSize = baseWidth/w;

		if(baseSize <= 1) {
                  //alert(zl.style.width);
			zl.style.width = baseWidth;
                        //alert(zl.style.pixelWidth);
			zl.style.height = parseInt(baseWidth*h/w);
		}
	}

	if(baseSize <= 1) {

		w2 = parseInt(zl.style.width)/2;
		h2 = parseInt(zl.style.height)/2;
               // alert(w2);
              /* if(!NS) {
		baseSize = Number(baseSize.toFixed(1));
                setNSSize(zi,zl,baseSize);
               } else{*/
                 orgWidth=zi.width;
                 setNSSize(zi,zl,baseSize);
               //}
               zoomSize = baseSize;
		zm.innerHTML = commandmenu;//"- point and click to zoom in<br>- press <CTRL> and click to zoom out";
		xBase = w2;
		yBase = h2;
	}
	else {
          	zl.style.overflow = 'visible';
		zi.onmouseup = null;
		zi.onmousedown = null;
		zl.ondblclick = null;
		zm.innerHTML = "";
	}
	zl.style.visibility = "visible";
        if (!IE) {
          document.captureEvents(Event.DBLCLICK);
	  w2 = document.width/2;
          h2 = document.height/2;
        }

        zl.ondblclick = zoom;
}

function zoom(e) {
  	var zi = document.getElementById("zoomImg");
        var zl = document.getElementById("zoomLy");
        if(IE) {
	  var x = event.x+zoomLy.scrollLeft;
	  var y = event.y+zoomLy.scrollTop;

	  if(!event.ctrlKey) {
		zoomSize += step;
		setNSSize(zi,zl,zoomSize);
		zl.scrollLeft = x*zoomSize/(zoomSize-step)-w2;
		zl.scrollTop = y*zoomSize/(zoomSize-step)-h2;
	  } else if(zoomSize>=baseSize+step){
		zoomSize -= step;
		setSize(zi,zoomSize);
		zl.scrollLeft = x*zoomSize/(zoomSize+step)-w2;
		zl.scrollTop = y*zoomSize/(zoomSize+step)-h2;
	  }
        }else {
          var x = e.pageX+zl.scrollLeft;
	  var y = e.pageY+zl.scrollTop;

	  if(!e.ctrlKey) {
		zoomSize += step;
		setNSSize(zi,zl,zoomSize);
		zl.scrollLeft = x*zoomSize/(zoomSize-step)-w2;
		zl.scrollTop = y*zoomSize/(zoomSize-step)-h2;
	  } else if(zoomSize>=baseSize+step){
		zoomSize -= step;
		setNSSize(zi,zl,zoomSize);
		//zl.scrollLeft = x*zoomSize/(zoomSize+step)-w2;
		//zl.scrollTop = y*zoomSize/(zoomSize+step)-h2;
	  }
        }

}

function capture(t) {
	//alert('aa');
	//if(event.bubbles) return;
        if (!IE) {
          document.captureEvents(Event.MOUSEMOVE);
        }
	else {
	  if(event.bubbles) return;
          t.setCapture();//event.capture();
	}
	//window.onmousemove = move;
	t.onmousemove = move;
}

function move(e) {
  	var zi = document.getElementById("zoomImg");
        var zl = document.getElementById("zoomLy");
  	if(IE) {
	if(event.srcElement != zoomImg) return;
	  if(xBase != null && yBase != null) {
		var x = xBase-event.x;
		var y = yBase-event.y;
		zl.scrollLeft +=x;
		zl.scrollTop +=y;
	  }
	  xBase = event.x;
	  yBase = event.y;
        }
        else {
	  if(xBase != null && yBase != null) {
		var x = xBase-e.pageX;
		var y = yBase-e.pageY;
                //alert(x);
		zl.scrollLeft +=x;
		zl.scrollTop +=y;
	  }
	  xBase = e.pageX;
	  yBase = e.pageY;
        }
	zi.style.cursor = "move";
}

function release(t) {
	xBase = null;
	yBase = null;
	t.style.cursor = "default";
        if (!IE) document.releaseEvents(Event.MOUSEMOVE);
	else t.releaseCapture();//event.capture();
	//window.onmousemove = null;
	//mouse.release();
	t.onmousemove = null;
}


