function showPopupPage(page, width, height, callback){
	
	element("photo-content").innerHTML = "loading content...";
	if(loadDoc(page, createDelegate(this, setPopupContent, callback))){
		resizePopup(width, height);
		showElements("photo-popup");
		movePopupOnScroll();
		return false;
	}
	return true
}
function setPopupContent(callback, doc){
	setHtmlTo('photo-content', doc.responseText);
	if(callback) callback();
}
function movePopupOnScroll(){
	if(isVisible("photo-popup")){
		var xOffset = getXOffset();
		var yOffset = getYOffset();
		var width = styleToNum(getStyle("photo-popup", "width"));
		var height = styleToNum(getStyle("photo-popup", "height"));
		var margin = Math.floor(yOffset-height/2)+"px 0 0 "+Math.floor(xOffset-width/2)+"px";
		setStyle("photo-popup", "margin", margin);
		//setHtmlTo("photo-content", "time: "+(new Date().getTime())+"<br/>scrollLeft: "+xOffset+"<br/>scrollTop: "+yOffset+"<br/>width: "+width+"<br/>height: "+height+"<br/>margin: "+margin);
	}
}
function resizePopup(width, height){
	var xOffset = getXOffset();
	var yOffset = getYOffset();
	var margin = Math.floor(yOffset-height/2)+"px 0 0 "+Math.floor(xOffset-width/2)+"px";
	setStyles("photo-content", [["width",width+"px"], ["height", height+"px"]]);
	setStyles("photo-popup", [["width",width+"px"], ["height", height+"px"], ["margin", margin]]);
}

//=============================== POPUP OPENER ==========================
function openBrWindow(theURL, Name, popW, popH, scrollbars) {
	if (!(theURL.length>0))
		return false;
	var winleft = (screen.width - popW) / 2;
	var wintop = (screen.height - popH) / 2;
	popFullH = popH + 60;
	popFullW = popW + 24;
	winProp = 'width='+popFullH+',height='+popFullW+',left='+winleft+',top='+wintop+',scrollbars='+(scrollbars?1:0)+',status=1,resizable=0';
	Name = window.open(theURL, Name, winProp)
//	if (Number(navigator.appVersion) >= 4) { 
//		Name.window.focus();
//	}
	Name.focus();
}
//=============================== text resizer ==========================

// scroll scruct
var scrollStruct = new Struct();
var popupScrollId = scrollStruct.add(createDelegate(this, movePopupOnScroll));

window.onscroll = function(){
	scrollStruct.dispatch();
}
