function findcenterOfWindow(elemID) {
    // 'obj' is the positionable object
  
    // window scroll factors
    var scrollX = 0, scrollY = 0;
    if (document.body && typeof document.body.scrollTop != "undefined") {
        scrollX += document.body.scrollLeft;
        scrollY += document.body.scrollTop;
        if (document.body.parentNode && 
            typeof document.body.parentNode.scrollTop != "undefined") {
            scrollX += document.body.parentNode.scrollLeft;
            scrollY += document.body.parentNode.scrollTop;
        }
    } else if (typeof window.pageXOffset != "undefined") {
        scrollX += window.pageXOffset;
        scrollY += window.pageYOffset;
    }
   cx = Math.round((getInsideWindowWidth( )/2)) + scrollX;
    cy = Math.round((getInsideWindowHeight( )/2))  + scrollY;
   // shiftTo(obj, x, y);
  //  show(obj);
}


var wspeed; //px/second
var hspeed;
var mwspeed; //px/second
var mhspeed;
var secs=500;
var zint;
var zout;
var until;
var image;
var lastleft=0;
var lasttop=0;
var cx;
var cy;
var beforew;
var beforeh;
var times;
var afterw;
var afreth;


function listProperties(obj, objName) {
    var result = "";
    for (var i in obj) {
        result += objName + "." + i + "=" + obj[i] + "\n";
    }
    alert(result);
}

function openWinIm(img,evt,newname){

	document.getElementById('fader').style.display='block';
	if (evt.pageX) {
		lastleft = evt.pageX;
		lasttop = evt.pageY ;
	}else if (typeof evt.clientX != "undefined") {
		lastleft = evt.clientX ;
		lasttop = evt.clientY ;
	}
	
		findcenterOfWindow();
		createcopy(img,newname);
	}
	
function zoomin(){

	image.style.zIndex=20000;

	wspeed=(afterw-beforew+1)/secs*50;
	hspeed=(afterh-beforeh+1)/secs*50;

	var count=(afterw-beforew+1)/wspeed;
	times= secs / count;

	mwspeed=(cx-afterw/2-lastleft)/count;
	mhspeed=(cy-afterh/2-lasttop)/count;

	perform_zoomin();

	return true;
	
}

function zoomout(){
	perform_zoomout();
	return true;
}

function perform_zoomin(){

	clearTimeout(zout);

	image.width+=wspeed;
	image.height+=hspeed;

	shiftBy(image, mwspeed, mhspeed);

		times
	if(image.width < afterw)
		zint=setTimeout('perform_zoomin()',times);
	
}

function perform_zoomout(){
	clearTimeout(zint);
/*	image.width -= wspeed;
	image.height -= hspeed;
	shiftBy(image, -mwspeed, -mhspeed);
	if(image.width > beforew){
		zout = setTimeout('perform_zoomout()',times);
	}else{*/
		document.body.removeChild(image);
		document.getElementById('fader').style.display='none';
//	}
}



function createcopy(img,newname){
	linedn = document.createElement("img");
 
    linedn.src = newname;
	beforew = 0;
	beforeh = 0;
	linedn.style.cursor = 'hand';
	document.body.appendChild(linedn);
	linedn.style.position = "absolute";

	linedn.style.top=lasttop+'px';
	linedn.style.left=lastleft+'px';
	linedn.onclick = zoomout;
	document.getElementById('loading').style.visibility = 'visible';
	shiftTo(document.getElementById('loading'),cx-16,cy-16);
	linedn.style.visibility = 'hidden';

	//
	if(!linedn.complete){
		linedn.onload = function(){
		
			afterw = linedn.width;
			afterh = linedn.height;
			linedn.height = beforeh;
		    linedn.width = beforew;

			
			linedn.style.visibility = 'visible';
			linedn.focus();
			image=linedn;
			document.getElementById('loading').style.visibility = 'hidden';
			zoomin();
		}
		
		linedn.onabort = function(){

			linedn.style.visibility = 'visible';

			document.getElementById('loading').style.visibility = 'hidden';
		
		}
	}else{
	
		afterw = linedn.width;
		afterh = linedn.height;
		linedn.height = beforeh;
	    linedn.width = beforew;
		linedn.style.visibility = 'visible';
		linedn.focus();
		image=linedn;
		
		document.getElementById('loading').style.visibility = 'hidden';
		zoomin();
	}
  // return linedn;
 
}



function showimg(u,wd,hg)
{
    s = window.open('','Pic','toolbar=no,location=no,directoties=no,status=no,scrollbars=no,menubar=no,resizable=yes,top=50,left=120,width='+(wd+16)+',height='+(hg+16));
    s.document.open();
    s.document.writeln('<html><head><title>photo</title></head><body bgcolor=ffffff onload="window.self.focus();return true;" leftMargin="0" topMargin="0" marginheight=0 marginwidth=0><table cellcpacing=0 cellpadding=5 border=0 width=100% height=100%><tr><td align=center><a href=javascript:window.close()><img src=' + u + ' border=0 width=' + wd + ' height="' + hg + '" alt="close"></a></td></tr></table></body></html>');
    s.document.close();
    s.focus();
}

var pscrollx=0;
var pscrolly=0;
document.onscroll=getscroll;
function getscroll() {


if (document.body && typeof document.body.scrollTop != "undefined") {
	pscrollx = document.body.scrollLeft;
	pscrolly = document.body.scrollTop;
	if (document.body.parentNode && 
		typeof document.body.parentNode.scrollTop != "undefined") {
		pscrollx += document.body.parentNode.scrollLeft;
		pscrolly += document.body.parentNode.scrollTop;
	}
} else if (typeof window.pageXOffset != "undefined") {
	pscrollx = window.pageXOffset;
	pscrolly = window.pageYOffset;
}

}
