function startLytebox(href,title)
{
    var objLink = document.createElement('a');
    objLink.setAttribute('href',href);
    objLink.setAttribute('rel','lytebox');
    objLink.setAttribute('title',title);

    myLytebox.start(objLink);
}

function addPopups()
{
    var hrefs = document.getElementById('textcontainer').getElementsByTagName('a');
    
    for (i=0; i < hrefs.length; i++)
    {
        var href = hrefs[i].href;
        var extLocation = href.lastIndexOf('.');
        var ext = href.substring(extLocation, href.length);

        if (ext == '.jpg' || ext == '.jpeg' || ext == '.gif' || ext == '.png' || ext == '.bmp')
        {
            // Normale event-handling
            if (hrefs[i].addEventListener)
            {
                hrefs[i].addEventListener(
                    "click",
                    function(e) {
                        openImgPopup(this);
                        // Href niet meer uitvoeren verder
                        e.stopPropagation();
                        e.preventDefault();
                    },
                    false
                );
            }
            // Ondersteuning voor internet explorer, IE ondersteund geen addEventListener
            else if (hrefs[i].attachEvent)
            {
                hrefs[i].attachEvent(
                    'onclick',
                    function(e) {
                        openImgPopup(e.srcElement);
                        return false;
                    }
                );
            }
        }
    }
}

function openImgPopup(eventCaller)
{
    var url = '/popup?cms[image]=' + eventCaller;
    var imgPopup = window.open(url,'name','height = 50, width = 50, resizeable = 0, status = 0, screenX = 0, screenY = 0, left = 0, top = 0');
	if (window.focus) {
        imgPopup.focus();
    }
}

function doResizeAndCenter(image)
{
    var imageWidth = image.width + 40;
    var imageHeight = image.height + 26;

    var containerWidth = imageWidth;
    var containerHeight = imageHeight + 15;

    var windowWidth = containerWidth + 100;
    var windowHeight = containerHeight + 200;

    var imgContainer = document.getElementById('popupImageContainer');
    imgContainer.style.position = 'absolute';
    imgContainer.style.width = containerWidth + 'px';
    imgContainer.style.height = containerHeight + 'px';
    imgContainer.style.top = '50%';
    imgContainer.style.left = '50%';
    imgContainer.style.marginLeft = '-' + containerWidth/2 + 'px';
    imgContainer.style.marginTop = '-' + containerHeight/2 + 'px';
    imgContainer.style.textAlign = 'center';

    window.resizeTo(windowWidth, windowHeight);
}