function showPhoto(w,h,id,pid) {
	pl = getClientWidth()/2 - w/2 + getBodyScrollLeft();
	pt = getClientHeight()/2 - h/2 + getBodyScrollTop();
	popup = document.getElementById("popupdiv");
	popup.style.left = pl + "px";
	popup.style.top = pt + "px";
	popup.style.width = w + "px";
	popup.style.height = h + "px";
	popup.style.clip = "rect(0, "+ w +"px, "+ h +"px, 0)";
	popup1 = document.getElementById("popupdiv1");
	pl = getClientWidth()/2 - 16 + getBodyScrollLeft();
	pt = getClientHeight()/2 - 16 + getBodyScrollTop();
	popup1.style.left = pl + "px";
	popup1.style.top = pt + "px";
	popup1.style.display = "block";
	var dummy = "&dummy=" + new Date().getTime();
	var url = "showphoto.php?&id=" + id + "&pid=" + pid + dummy + "&w=" + w + "&h=" + h;
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			popup1.style.display = "none";
			popup.innerHTML = response;
			popup.style.display = "block";
			curtainOpen(w,h,0,0,"popupdiv");
		}
	}
	xmlHttp.send(null);
}
function hidePhoto(w,h) {
	curtainClose(0,0,w,h,"popupdiv");
}
function curtainOpen(w,h,c1,c2,div) {
	if (c1<w) c1 = c1 + 10;
	if (c2<h) c2 = c2 + 10;
	if (c1<w || c2<h)	{
		var rect = 'rect(0, '+ c1 +'px, '+ c2 +'px,0)';
		document.getElementById(div).style.clip = rect;
		setTimeout("curtainOpen("+w+","+h+","+c1+","+c2+",'"+div+"')",1);
	} else {
		document.getElementById(div).style.clip = 'rect(auto, auto, auto, auto)';
	}
}
function curtainClose(w,h,c1,c2,div) {
	if (c1>0) c1 = c1 - 10;
	if (c2>0) c2 = c2 - 10;
	if (c1>0 & c2>0) {
		var rect = 'rect(0, '+ c1 +'px, '+ c2 +'px,0)';
		document.getElementById(div).style.clip = rect;
		setTimeout("curtainClose("+w+","+h+","+c1+","+c2+",'"+div+"')",1);
	} else {
		document.getElementById(div).style.display = "none";
	}
}
function getBodyScrollTop() {
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
function getBodyScrollLeft() {
  return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}
function getleft(el) {
	var tmp = el.offsetLeft;
	el = el.offsetParent
	while(el) {
		tmp += el.offsetLeft;
		el = el.offsetParent;
	}
	return tmp;
}
function gettop(el) {
	var tmp = el.offsetTop;
	el = el.offsetParent
	while(el) {
		tmp += el.offsetTop;
		el = el.offsetParent;
	}
	return tmp;
}
function getOffsetSum(elem) {
    var top=0, left=0
    while(elem) {
        top = top + parseFloat(elem.offsetTop)
        left = left + parseFloat(elem.offsetLeft)
        elem = elem.offsetParent       
    }
    return {top: Math.round(top), left: Math.round(left)}
}
function getOffsetRect(elem) {
    var box = elem.getBoundingClientRect()
    var body = document.body
    var docElem = document.documentElement
    var scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop
    var scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft
    var clientTop = docElem.clientTop || body.clientTop || 0
    var clientLeft = docElem.clientLeft || body.clientLeft || 0
    var top  = box.top +  scrollTop - clientTop
    var left = box.left + scrollLeft - clientLeft
    return { top: Math.round(top), left: Math.round(left) }
}
function getOffset(elem) {
    if (elem.getBoundingClientRect) {
        return getOffsetRect(elem)
    } else {
        return getOffsetSum(elem)
    }
}
function getClientWidth() {
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}
function getClientHeight() {
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
