
String.prototype.toInt=function(){return parseInt(this.substring(0,this.length-2),10);}
function getmouse(ev){
	if(ev.pageX||ev.pageY)
	{return{x:ev.pageX,y:ev.pageY}}
	else
	{return{x:ev.clientX+document.body.scrollLeft,y:ev.clientY+document.body.scrollTop}}
}
function addEvent(o,evtType,func){
	if(document.all)
	{o.attachEvent("on"+evtType,func);}
	else
	{o.addEventListener(evtType,func,false);}
}
function removeEvent(o,evtType,func){
	if(document.all)
	{o.detachEvent("on"+evtType,func);}
	else
	{o.removeEventListener(evtType,func,false);}
}
var newImg_width  = 0;
var newImg_height = 0;
var InitalWidth = 0;

var active_width = document.body.clientWidth;
var active_height = document.body.clientHeight;

var dragOBj = document.getElementById("ImageDIV");

var newImg=new Image();
newImg.onload = function(){InitImage("1");}
var nnurl=location.search.replace("?","").split("&image=");
var nnbak=nnurl[0].split("=");
if(nnbak[1]=="no")
{document.getElementById("backimg").style.display='none';}
newImg.src=theIMG;
newImg.style.display="none";
if (navigator.appName.toLowerCase().indexOf("netscape") == -1){
newImg.onreadystatechange = function(){if ( this.readyState == "complete") {document.getElementById("DivLoading").style.display="none";this.style.display="";}} 
}
//alert(unescape(nnurl[1]));
//window.location.href.split("=")[1];
ImageDIV.appendChild(newImg);
var self_mark=0;
//mouse wheel zoomin and zoomout author by ywx
window.onload = function(){
	dragOBj.onmousewheel = function(e){
		if(newImg.width==0)return;
		e=e || window.event;
		delta = 0;
		if(e.wheelDelta){//IE/Opera/Chrome   
			delta=e.wheelDelta;   
		}else if(e.detail){//Firefox   
			delta=e.detail;   
		}
		if(delta >0){
			ZoomIn()
		}
		else if(delta < 0){
			ZoomOut()
		}
		return false;
	}
}
dragOBj.onmouseup =  function(){
	if(this.__EnableDrag){
		if(document.all)
		{this.releaseCapture();}
		this.__EnableDrag = false;
	}
}
dragOBj.onmousedown =  function(ev){
	ev=ev||window.event;
	if(document.all)
	{this.setCapture();}
	else
	{ev.preventDefault();}
	this.ofsetx = getmouse(ev).x-this.offsetLeft;
	this.ofsety = getmouse(ev).y-this.offsetTop;
	this.__EnableDrag = true;
}

dragOBj.onmousemove =  function(ev){
	ev=ev||window.event;
	if(this.__EnableDrag)	{	
		this._x1 = getmouse(ev).x;
		this._y1 = getmouse(ev).y;
		var left =  this._x1-this.ofsetx;
		var right = this._y1-this.ofsety;
		//if(maxOffX>0 && left <-maxOffX) left = -maxOffX;
		//if(maxOffY>0 && right <-maxOffY) right = -maxOffY;
		//if(maxOffX>0 && left >0) left = 0;

		//if(maxOffY>0 && right >0) right = 0;
		this.style.left = left+"px";
		this.style.top  =  right+"px";
	}
}

function ZoomIn(){
	if(document.all){
		if(newImg.style.pixelWidth>5000) return;//if(newImg.style.pixelWidth>10000) return;
		newImg.style.pixelWidth *= 2;
		newImg.style.pixelHeight *= 2;
		ImageDIV.style.pixelLeft -= newImg.style.pixelWidth / 4;
		ImageDIV.style.pixelTop -= newImg.style.pixelHeight / 4;
	}
	else{
		if(newImg.style.width.toInt()>5000) return;//if(newImg.style.width.toInt()>10000) return;
		newImg.style.width = (newImg.style.width.toInt()*2)+"px";
		newImg.style.height = (newImg.style.height.toInt()*2)+"px";
		ImageDIV.style.left = (ImageDIV.style.left.toInt()-Math.floor(newImg.style.width.toInt()/4))+"px";
		ImageDIV.style.top = (ImageDIV.style.top.toInt()-Math.floor(newImg.style.height.toInt()/4))+"px";
	}
}

function ZoomOut(){
	if(document.all){
		if(newImg.style.pixelWidth<=300) return;//if(newImg.style.pixelWidth<=InitalWidth) return;
		newImg.style.pixelWidth /= 2;
		newImg.style.pixelHeight /= 2;
		ImageDIV.style.pixelLeft += newImg.style.pixelWidth / 2;
		ImageDIV.style.pixelTop += newImg.style.pixelHeight / 2;
	}
	else{
		if(newImg.style.width.toInt()<=300) return;//if(newImg.style.width.toInt()<=InitalWidth) return;
		newImg.style.width = (newImg.style.width.toInt()/2)+"px";
		newImg.style.height =(newImg.style.height.toInt()/2)+"px";
		ImageDIV.style.left = (ImageDIV.style.left.toInt()+Math.floor(newImg.style.width.toInt() / 2))+"px";
		ImageDIV.style.top = (ImageDIV.style.top.toInt()+Math.floor(newImg.style.height.toInt() / 2))+"px";
	}
}

function Reset(){
    if(newImg_width ==0){
	    newImg_width  = newImg.width;
        newImg_height = newImg.height;
    }
	if(document.all){
		newImg.style.pixelWidth = newImg_width;
		newImg.style.pixelHeight = newImg_height;
		ImageDIV.style.pixelLeft = (active_width - newImg_width)/2;
		ImageDIV.style.pixelTop = (active_height - newImg_height)/2;
	}
	else{
		newImg.style.width = newImg_width+"px";
		newImg.style.height = newImg_height+"px";
		ImageDIV.style.left = Math.floor((active_width - newImg_width)/2)+"px";
		ImageDIV.style.top = Math.floor((active_height - newImg_height)/2)+"px";
	}
	self_mark=1;
}

function goback(){
	history.back();
}
function InitImage(thePar1){
if(thePar1=="1"){
if(newImg.complete == true){document.getElementById("DivLoading").style.display="none";newImg.style.display="";}
}
	if(newImg_width ==0){
	    newImg_width  = newImg.width;
        newImg_height = newImg.height;
    }
    if (newImg_width / newImg_height < active_width / active_height){
		if(document.all)
		{
			newImg.style.pixelWidth = newImg_width * active_height/newImg_height;
			newImg.style.pixelHeight = active_height;
			ImageDIV.style.pixelLeft = (active_width - newImg.style.pixelWidth)/2;
			ImageDIV.style.pixelTop  = 0;
		}
		else{
			newImg.style.width = (newImg_width * active_height/newImg_height)+"px";
			newImg.style.height = active_height+"px";
			ImageDIV.style.left = Math.floor((active_width - newImg.style.width.toInt())/2)+"px";
			ImageDIV.style.top  = 0+"px";
		}
	}
	else{
		if(document.all){
			newImg.style.pixelHeight = newImg_height * active_width / newImg_width;
			newImg.style.pixelWidth = active_width;
			ImageDIV.style.pixelLeft = 0;
			ImageDIV.style.pixelTop = (active_height - newImg.style.height.toInt())/2;
		}
		else{
			newImg.style.height = (newImg_height * active_width / newImg_width)+"px";
			newImg.style.width = active_width+"px";
			ImageDIV.style.left = 0+"px";
			ImageDIV.style.top = Math.floor((active_height - newImg.style.pixelHeight)/2)+"px";
		}
	}
	if(document.all)
	{InitalWidth = newImg.style.pixelWidth;}
	else
	{InitalWidth = parseInt(newImg.style.width.toInt(),10);}	
}

function self_fun1(){
if(self_mark==0){
Reset();
//if(document.all){ImageDIV.style.pixelTop =0;ImageDIV.style.pixelLeft =0;}else{ImageDIV.style.top = 0+"px";ImageDIV.style.left = 0+"px";}
}
}

//setInterval(self_fun1,500); 



document.onkeydown = function chang_page(e){
var theEvent=window.event||e;var keyNum=theEvent.keyCode||theEvent.which;
if (keyNum== 36||keyNum== 37)location=document.getElementById("HyperLink1").href;else if (keyNum== 35||keyNum== 32||keyNum== 39)location=document.getElementById("HyperLink2").href;
else if (keyNum== 38)ImageDIV.style.pixelTop = ImageDIV.style.pixelTop-50;else if (keyNum== 40)ImageDIV.style.pixelTop =ImageDIV.style.pixelTop+50;
else if (keyNum== 33)ImageDIV.style.pixelTop =0;else if (keyNum== 34)ImageDIV.style.pixelTop =(document.body.clientHeight-newImg.style.pixelHeight);
else if (keyNum== 96)InitImage("1");else if (keyNum== 13||keyNum== 17||keyNum== 18||keyNum== 27||keyNum== 9)Reset();
else if (keyNum== 107)ZoomIn();else if (keyNum== 109)ZoomOut();
//else if (keyNum== 37)ImageDIV.style.pixelLeft = ImageDIV.style.pixelLeft-50;else if (keyNum== 39)ImageDIV.style.pixelLeft =ImageDIV.style.pixelLeft+50;
}