/**
 * author: 440606@gmail.com
 * ver 1.2
 */

var pbox;
var img;
var phalfleft;


function picturebox(picturesrc)
{
    pbox = document.getElementById('picturebox')
    pbox.style.display = 'block';
    pboxload = document.getElementById('picturebox-load');
   
    if (navigator.appName == "Microsoft Internet Explorer")
    {
        pwidth = window.document.body.offsetWidth;
        pheight = window.document.body.offsetHeight;
        scrollTop = document.documentElement.scrollTop;
        scrollLeft = document.documentElement.scrollLeft;
        pheighthalf = pheight / 2;
    } else {
        pwidth = window.innerWidth;
        pheight = window.innerHeight;
        scrollTop = window.pageYOffset;
        scrollLeft = window.pageXOffset;
        pheighthalf = pheight / 2;
    }
    
    pbox.style.top = scrollTop+20+'px';
    
    phalfleft = pwidth / 2;
    var left = phalfleft - 40;
    pbox.style.left = left +'px';
    pbox.innerHTML = '<img src="images/ajax-loader.gif" border="0" onclick="closePicturebox();" />';
        
    img = new Image();
    img.src = 'http://www.grandestar.com/'+picturesrc;
    pboxload.innerHTML = '<img src="'+img.src+'" />';
    
    pictureboxTick();
}


function pictureboxTick()
{   
    if (img.complete) {
        var imgheight;
        var imgwidth;
        var maxheight = pheight - 80;
        if (img.height > maxheight) {
            imgheight = maxheight;
            imgwidth  = img.width * (imgheight / img.height);
        } else {
            imgheight = img.height;
            imgwidth  = img.width;
        }

        var left = phalfleft - (imgwidth / 2);
        pbox.style.left = left+'px';
        
        pbox.innerHTML = '<img src="'+img.src+'" border="0" onclick="closePicturebox();" title="Bezár" width="'+imgwidth+'" height="'+imgheight+'" />';
        return;
    }
    window.setTimeout("pictureboxTick()", 100);
}


function closePicturebox()
{
    pbox.innerHTML = '';
    pbox.style.display = 'none';
}
