var offX,offY,startX,startY=0;
var move=false;

function BigShow(pict,w,h){
	//alert(w+" "+h);
	/*if (new_pict != 0) {RemoveBigShow();}
	new_pict = document.createElement("img");
	var page_height = document.body.clientHeight-40;
	new_pict.style.position = "absolute";
	new_pict.style.top = document.body.scrollTop+20;
	new_pict.style.left = 20;
	if (h > page_height){
		new_pict.style.height = page_height;
		new_pict.style.width = page_height*w/h;
	}
	else{
		new_pict.style.height = h;
		new_pict.style.width = w;
	}
	new_pict.style.zIndex = "1";
	new_pict.setAttribute("src",pict.getAttribute("src"));
	new_pict.setAttribute("border","1");
	new_pict.id = "big_pict";
	new_pict.addEventListener("click",RemoveBigShow,true);
	//new_pict.attachEvent("onclick",RemoveBigShow);
	//new_pict.removeAttribute("onclick");
	//new_pict.onclick = "RemoveBigShow(this);";
	//new_pict.setAttribute("onclick","RemoveBigShow(this);");
	
	document.body.appendChild(new_pict);*/
	
	RemoveBigShow(0);
	pict.id="small_pict";
	pict.style.visibility="hidden";
	var page_height = document.body.clientHeight-40;
	var new_w, new_h = 0;
	if (h > page_height){
		new_h = page_height;
		new_w = page_height*w/h;
	}
	else{
		new_h = h;
		new_w = w;
	}
	var new_left = document.body.scrollLeft+Math.floor((document.body.clientWidth-new_w)/2);
	var new_top = document.body.scrollTop+Math.floor((document.body.clientHeight-new_h)/2);
	document.body.innerHTML += "<img id='big_pict' src='"+pict.getAttribute("src")+"' style='cursor: url(\"./img/zoom_out.cur\"), pointer; position:absolute; top:"+new_top+";height:"+new_h+"; width:"+new_w+"; left:"+new_left+"; z-index:1;' border='1' onclick='RemoveBigShow(event);' onmousemove='return false;' onmousedown='return onBeginDrag(this,event);' onmouseup='onDrop();' >";
	//alert(pict.style.visibility);
}

function RemoveBigShow(b){
	if ((b!=0 && b.clientX==startX && b.clientY==startY) || (b==0)) {
		var small_pict=document.getElementById("small_pict");
		if (small_pict) {
			small_pict.style.visibility="visible";
			small_pict.id="";
		}	
		var new_pict=document.getElementById("big_pict");
		if (new_pict) document.body.removeChild(new_pict);
	}	
}

function onDrag(a,b){
	//if (b) {alert(b.clientX);}
	if (move){
		var new_pict=document.getElementById("big_pict");
		if (new_pict){
			//alert(document.body.scrollLeft+"\n"+b.clientX+"\n"+offX);
			new_pict.style.left=document.body.scrollLeft+b.clientX-offX;
			new_pict.style.top=document.body.scrollTop+b.clientY-offY;
		}	
	}	
	return false;
}

function onBeginDrag(a,b){
	offX=document.body.scrollLeft+b.clientX-a.offsetLeft;
	offY=document.body.scrollTop+b.clientY-a.offsetTop;
	startX=b.clientX;
	startY=b.clientY;
	move=true;
	return false;
}

function onDrop(){
	move=false;
}