﻿var silverlightObjectWidth = 0;
var silverlightObjectHeight = 0;

function createLightBox(htmlItemContainer, imageSource, imageCaption)
{     
    
    var imageBoxContainer = document.createElement('div');
    imageBoxContainer.setAttribute('class', 'imageContainer');

    var image = document.createElement('img');
    image.setAttribute('src', imageSource);
    image.setAttribute('onclick', 'javascript:hideLightBox();');
    
    var caption = document.createElement('div');
    caption.setAttribute('class', 'lightBoxCaption');
    caption.innerHTML = imageCaption;

    imageBoxContainer.style.width = image.width + 10;
        
    imageBoxContainer.appendChild(image);
    imageBoxContainer.appendChild(caption);

    document.getElementById(htmlItemContainer).appendChild(imageBoxContainer);
}

function pippo(imageSource, imageCaption) {

    /* if (document.getElementById('LightBoxMask').childNodes.length != 0) 
    {
    document.getElementById('LightBoxMask').removeChild(document.getElementById('LightBoxMask').childNodes[0]);
    createLightBox('LightBoxMask', imageSource, imageCaption);
    }
    else
    createLightBox('LightBoxMask', imageSource, imageCaption);
    document.getElementById('LightBoxMask').style.display = 'block';*/
    var objLink = document.createElement('a');
    objLink.setAttribute('href', imageSource);
    objLink.setAttribute('rel', 'lightbox');
    objLink.setAttribute('title', imageCaption);
    Lightbox.prototype.start(objLink);

    silverlightObjectHeight = document.getElementById('silverlightObject').height;
    silverlightObjectWidth = document.getElementById('silverlightObject').width;

    document.getElementById('silverlightObject').setAttribute('width', '0');
    document.getElementById('silverlightObject').setAttribute('height', '0');

}

function hideLightBox() {
    document.getElementById('LightBoxMask').removeChild(document.getElementById('LightBoxMask').childNodes[0]);
    document.getElementById('LightBoxMask').style.display = 'none';
    document.getElementById('silverlightObject').setAttribute('width', silverlightObjectWidth);
    document.getElementById('silverlightObject').setAttribute('height', silverlightObjectHeight);
}
