var acc_stay = 0, cur_popup_id = 0;

function accounts_popup_request(id) {
	accounts_popup_hide();
	Root.XMLHTTP.exec({path:"xmlhttp.accounts.popup", id:id});
}

function accounts_popup_show(id) {
	cur_popup_id = id;
	accounts_popup_move();
}

function accounts_popup_move() {
	var elems = [], img;
	Root.findElements(elems, $("accounts:photo:"+cur_popup_id), "tagName", /^div$/i);
	img = elems[0];
	var a = Root.getElementInfo(img, "container");
	var a1 = Root.getElementInfo($("container"));
	var c = $("accounts:popup:container");
	var cw = c.offsetWidth ? c.offsetWidth : 300;
	var w = getWindowInfo();
	c.style.left = Math.min(a1.right-cw, a.left-7)+"px"; 
	c.style.top = Math.min(w.pageH+w.scrollY-c.offsetHeight-a1.top, a.top-7)+"px";
	c.style.display = '';
}

function accounts_popup_hide() {
	$("accounts:popup:container").style.display = 'none';
}

function accounts_popup_stay() {
	acc_stay = 1;
}

document.onmousedown = function() {
	if (!acc_stay) accounts_popup_hide(); else acc_stay = 0;
}

window.onresize = function() {
	var c = $("accounts:popup:container");
	if (c.style.display!='none') accounts_popup_move();
}

function getWindowInfo() {
	if (self.innerWidth) { // all except Explorer
		w = self.innerWidth;
		h = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth) { // Explorer 6 Strict
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	} else if (document.body) { // all other Explorers
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}

	if (self.pageYOffset) { // all except Explorer
		x = self.pageXOffset;
		y = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	} else if (document.body) { // all other Explorers
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}

	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight
	if (test1 > test2) { // all but Explorer Mac
		pw = document.body.scrollWidth;
		ph = document.body.scrollHeight;
	} else { // Explorer Mac; would also work in Explorer 6 Strict, Mozilla and Safari
		pw = document.body.offsetWidth;
		ph = document.body.offsetHeight;
	}
	return {pageW:w, pageH:h, scrollX:x, scrollY:y, bodyW:pw, bodyH:ph};
}

