function lbf2wp_getWindowSize(wWindow)
{
    var windowWidth = 0;
    var windowHeight = 0;
    if (!wWindow) wWindow = window;
    try
    {
        windowWidth = wWindow.document.body.clientWidth;
        windowHeight = wWindow.document.body.clientHeight;
        if (0 == windowWidth * windowHeight) throw 'Window size problem.';
    }
    catch (ex)
    {
        try {
            windowWidth = wWindow.document.documentElement.clientWidth;
            windowHeight = wWindow.document.documentElement.clientHeight;
            if (0 == windowWidth * windowHeight) throw 'Window size problem.';
        }
        catch (ex)
        {
            try
            {
                windowWidth = wWindow.innerWidth;
                windowHeight = wWindow.innerHeight;
                if (0==windowWidth*windowHeight) throw 'Window size problem.';
            }
            catch (ex)
            {
                return false;
            }
        }
    }
    return {
        width : windowWidth,
        height : windowHeight
    };
}

function lbf2wp_getImageRelSize(imgObj)
{
    var w = imgObj.width;
    var h = imgObj.height;
    var ws = lbf2wp_getWindowSize();
    ws.width *= 0.85;
    ws.height *= 0.85;
    ws.height -= 32;
    if (w > ws.width)
    {
        var ow = w ? w : 1;
        w = ws.width;
        h *= w / ow;
    }
    if (h > ws.height)
    {
        var oh = h ? h : 1;
        h = ws.height;
        w *= h / oh;
    }
    return { width : Math.floor(w), height : Math.floor(h) };
}

Object.extend(Element, {
    setSrc: function(element, src, newSize)
    {
        element = $(element);
        element.src = src;
        if (newSize)
        {
            element.style.width = newSize.width + 'px';
            element.style.height = newSize.height + 'px';
        }
    }
});

Lightbox.prototype.changeImage = function(imageNum) {
    activeImage = imageNum;
    if(animate){ Element.show('loading');}
    Element.hide('lightboxImage');
    Element.hide('hoverNav');
    Element.hide('prevLink');
    Element.hide('nextLink');
    Element.hide('imageDataContainer');
    Element.hide('numberDisplay');
    imgPreloader = new Image();
    imgPreloader.onload=function(){
        var size = lbf2wp_getImageRelSize(imgPreloader);
        Element.setSrc('lightboxImage', imageArray[activeImage][0], size);
        myLightbox.resizeImageContainer(size.width, size.height);
        imgPreloader.onload=function(){};
    }
    imgPreloader.src = imageArray[activeImage][0];
};

Lightbox.prototype.updateDetails = function() {
    if(imageArray[activeImage][1]){
        Element.show('caption');
        if (imageArray[activeImage][2]){
            Element.setInnerHTML( 'caption', '<a href="'+imageArray[activeImage][2]+'" target="_blank"><span class="tcol">'+imageArray[activeImage][1]+'</span></a>');
        }
        else{
            Element.setInnerHTML( 'caption', imageArray[activeImage][1]);
        }
    }
    if(imageArray.length > 1){
        Element.show('numberDisplay');
        Element.setInnerHTML( 'numberDisplay', eval(activeImage + 1) + ". kép, összesen: " + imageArray.length);
    }
    new Effect.Parallel(
        [ new Effect.SlideDown( 'imageDataContainer', { sync: true, duration: resizeDuration, from: 0.0, to: 1.0 }),
          new Effect.Appear('imageDataContainer', { sync: true, duration: resizeDuration }) ],
        { duration: resizeDuration, afterFinish: function() {
            var arrayPageSize = getPageSize();
            Element.setHeight('overlay', arrayPageSize[1]);
            myLightbox.updateNav();
            }
        }
    );
}

