function getElement(id){  return document.getElementById(id)}
function getThumbImageId(id) {	return "thumb" + id}
function getBigImageId(id) {	return "full" + id;}

function showBigImage(id, left, offset)
{
	var obj = document.images[getThumbImageId(id)];
	var coords = null;
	
	coords = getCoords(obj);
	coords.y = coords.y + 30;
	
	var bigImage = getElement('full_img_' + id)
	var bigImageHeight = 0
	
	if (bigImage) {
		bigImageHeight = bigImage.height
		
		if (0 == bigImageHeight || isNaN(bigImageHeight)) {
			bigImageHeight = parseInt(bigImage.style.height)
		}

		if (0 == bigImageHeight || isNaN(bigImageHeight)) {
			bigImageHeight = 120
		}
	}
	
	var distanceFromWindowBottom = 0
	var distanceFromWindowTop    = 0
	
	var showLow = 1
	
	distanceFromWindowBottom = document.body.clientHeight + document.body.scrollTop - coords.y
	distanceFromWindowTop    = coords.y - document.body.scrollTop
	
	if (distanceFromWindowBottom < bigImageHeight + 20 && distanceFromWindowTop + 20 > distanceFromWindowBottom) {
		coords.y = coords.y - bigImageHeight
		showLow = 0
	}
	
	showPopupFilm(id, coords, showLow, left)
}

function hideBigImage(id){	hidePopup(id);}

function showPopup(id, coords, showLow)
{
	var popup = getElement(getBigImageId(id));
	var popupImage = getElement('full_img_' + id);

	if(popup && popupImage)
  {
		var imageWidth  = popupImage.width;
		var imageHeight = popupImage.height;
		
		if(isNaN(imageWidth) || 0 == imageWidth || isNaN(imageHeight) || 0 == imageHeight)
		{
			imageWidth  = parseInt(popupImage.style.width);
			imageHeight = parseInt(popupImage.style.height);
		}
		
		if(isNaN(imageWidth) || 0 == imageWidth || isNaN(imageHeight) || 0 == imageHeight)
		{
			imageWidth = 190;
			imageHeight = 0;
		}

		coords.x -= imageWidth;
		
		var popup = getElement(getBigImageId(id));
		var popupImage = getElement('full_img_' + id);
		var ifr = getElement('ifr' + id);
		
		if(popup && popup.style.display == "none")
		{
			popup.style.zIndex = 100;
			popup.style.left = coords.x + "px";
			popup.style.top = coords.y + "px";
			popup.style.display = "block";
		} 
	}
}

function showPopupFilm(id, coords, showLow)
{
	var trUpperRight = getElement('arrow1_' + id);
	var trLowerRight = getElement('arrow2_' + id);

	if(trLowerRight && trUpperRight)
	{
		if(1 == showLow)
		{
			trUpperRight.style.visibility = "visible";
			trLowerRight.style.display = 'none';
		}
		else
		{
			trUpperRight.style.visibility = "hidden";
			trLowerRight.style.display = 'block';
		}
	}

	coords.x = coords.x - 122;
	showPopup(id, coords, showLow);
}

function hidePopup(id)
{
	var popup = getElement(getBigImageId(id));
	
	if(popup)
  {
		popup.style.zIndex = 1;
		popup.style.top = 0;
		popup.style.left = 0;
		popup.style.width = 1 + 'px';
		popup.style.height = 1 + 'px';
		popup.style.display = "none";
	} 
}

function getCoords(obj)
{
	var coords = new Object;
  coords.x = obj.offsetWidth;
  coords.y = 0;
	for (null; obj != null; coords.x += obj.offsetLeft, coords.y += obj.offsetTop, obj = obj.offsetParent) {}
	return coords;
}

function filmOver(id, left){	showBigImage(id, left);}
function filmOut(id){	hideBigImage(id);}
