function move_box(an, box)
{
    var cleft = 0;
    var ctop = 0;
    var obj = an;

    while (obj.offsetParent)
    {
        cleft += obj.offsetLeft;
        ctop += obj.offsetTop;
        obj = obj.offsetParent;
    }

    box.style.left = cleft + 'px';

    ctop += an.offsetHeight + 8;

    if (document.body.currentStyle &&
        document.body.currentStyle['marginTop'])
    {
        ctop += parseInt(
            document.body.currentStyle['marginTop']);
    }

    box.style.top = ctop + 'px';
}

function PokZdj(an, href, img)
{
    var boxdiv = document.getElementById(href);   

    if (boxdiv != null)
    {
        if (boxdiv.style.display=='none')
        {
            move_box(an, boxdiv);
            boxdiv.style.display='block';
            bringToFront(boxdiv);
        }
        else
            boxdiv.style.display='none';
        return false;
    }
	
	var c = href.charAt(1);
	
	if ( c == '1' )
	  c = 'j'
	else
	  c = 'i';  
	
	var zdjecie = '/z'+href.charAt(0)+'/'+href.substr(href.length-2,2)+c+'/'+href.substr(2,href.length-2)+'_1.jpg';
	
    boxdiv = document.createElement('div');

    boxdiv.setAttribute('id', href);
    boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.width = '200px';
    boxdiv.style.height = '200px';
    boxdiv.style.border = 'none';
	boxdiv.style.background = 'url('+zdjecie+') top left no-repeat';

    document.body.appendChild(boxdiv);

	move_box(an, boxdiv);
    bringToFront(boxdiv);
	return false;
}

function getAbsoluteDivs()
{
    var arr = new Array();
    var all_divs = document.body.getElementsByTagName("DIV");
    var j = 0;

    for (i = 0; i < all_divs.length; i++)
        if (all_divs.item(i).style.position=='absolute')
        {
            arr[j] = all_divs.item(i);
            j++;
        }

    return arr;
}

function bringToFront(obj)
{
    if (!document.getElementsByTagName)
        return;

    var divs = getAbsoluteDivs();
    var max_index = 0;
    var cur_index;

    for (i = 0; i < divs.length; i++)
    {
        var item = divs[i];
        if (item == obj ||
            item.style.zIndex == '')
            continue;

        cur_index = parseInt(item.style.zIndex);
        if (max_index < cur_index)
        {
            max_index = cur_index;
        }
    }

    obj.style.zIndex = max_index + 1;
}

