function getCoords(obj)
{
        var o = obj, coords = {x: 0, y: 0}
        while (o && o.tagName != "BODY")
        {
                coords.x += o.offsetLeft;
                coords.y += o.offsetTop;
                o = o.offsetParent;
          }
          return coords;
}

function addEvent(obj, eventName, eventFunction)
{
        if (document.all) obj[eventName] = new Function("",eventFunction);
        else obj.setAttribute(eventName,eventFunction);
}


function ShowBigImage(obj)
{
        obj.blur();
        if (!bigImage.box) initBigImage();

        objNew = document.createElement("A");
        objNew.id = "a-clik-box";
        objNew.href = obj.href;
        objNew.target = "_blank";

        bigImage.image = new Image();
        bigImage.image.src = obj.href;

        bigImage.box.childNodes[0].innerHTML = '';

        obj = obj.childNodes[0];
        var coords = getCoords(obj);
        bigImage.x = coords.x + Math.round(obj.offsetWidth / 2);
        bigImage.y = coords.y + Math.round(obj.offsetHeight / 2);

        if (bigImage.image.width == 0)
        {
                bigImage.box.className = "big-image-progress";
                addEvent(bigImage.image, "onload","placeBigImage()");

                bigImage.box.style.width = obj.offsetWidth + 6 + "px";
                bigImage.box.style.height = obj.offsetHeight + 6 + "px";
                bigImage.box.style.left = coords.x - 3 + "px";
                bigImage.box.style.top = coords.y - 3 + "px";
        }
        else placeBigImage();
        bigImage.box.style.visibility = "visible";
        return false;
}


function placeBigImage()
{
        bigImage.box.childNodes[0].appendChild(bigImage.image);
        bigImage.box.style.width = "";
        bigImage.box.style.height = "";
        bigImage.box.className = "";
        var bigImageX = bigImage.x - Math.round(bigImage.box.offsetWidth/2);

        if (bigImageX < 5) bigImageX = 5;
        var maxleft = document.body.scrollWidth - 5 - bigImage.box.offsetWidth;
        if (bigImageX > maxleft) bigImageX = maxleft;

        bigImage.box.style.left = bigImageX + "px";
        bigImage.box.style.top = bigImage.y - Math.round(bigImage.box.offsetHeight/2) + "px";
}

var bigImage = {box: null, x: 0, y: 0, image: null}
function initBigImage()
{
        var obj = document.createElement("DIV");
        obj.id = "big-image-box";
        obj.innerHTML = '<div onclick="hideBigImage(event)"></div><div id="close-pic-button" onclick="hideBigImage(event)">&nbsp;</div>';
        bigImage.box = document.body.appendChild(obj);
        var hideBigButton = document.getElementById("close-pic-button");
}

function hideBigImage(e)
{
        bigImage.box.style.visibility = "hidden";
        bigImage.box.childNodes[0].innerHTML = "";
        e.cancelBubble = true;
}