// popup.js

var WaitImageSource = "images/spinner-32x32.gif";
var NodeElement = 1;
var NodeAttribute = 2;
var NodeText = 3;
var NodeComment = 8;
var NodeDocument = 9;
var BigPic, BigPicImage, BigPicCaption;
onload = InitPic;

function InitPic() {

	BigPic = document.getElementById ('BigPic');
	BigPicImage = document.getElementById ('BigPicImage');
	BigPicCaption = document.getElementById ('BigPicCaption');
	BigPic.onclick = HideBigPic;
	BigPic.title = BigPic.alt = BigPicImage.title = BigPicImage.alt = "Click to close";

	with (BigPic.style) {
		position = "absolute";
		top = "0px";
		left = "0px";
		zIndex = "10";
		visibility = "hidden";
	}

}

function ShowBigPic (smallPic) {
	
	var pos = PositionOf (smallPic);
	var posTop = pos.top;
	var posRight = document.body.offsetWidth  - pos.left + 70;

	BigPicImage.src = WaitImageSource;
	BigPic.style.visibility = 'visible';
	BigPic.style.top = posTop + "px";
	BigPic.style.right = posRight + "px"; 
	BigPic.style.bottom = BigPic.style.left = "auto";
	BigPicCaption.innerHTML = "<br />" + smallPic.alt;
	BigPicImage.src = smallPic.src.replace(/-s.jpg/, '-m.jpg'); 

}

function HideBigPic (imgSmall) {

	BigPic.style.visibility = 'hidden';

}

function PositionOf (el) {
	
	var currTop = currLeft = currRight = 0;
	var width = el.offsetWidth;
	var height = el.offsetHeight;
	
	while (el) {
		currTop += el.offsetTop;
		currLeft += el.offsetLeft;
		el = el.offsetParent;
	}
	
	return {top:currTop, left:currLeft, width:width, height:height};
}

