﻿var LightBox = {
    OverlayDiv : null,
    LightBoxDiv : null,
    ImageElement : null,
    MaxWidth : 1000,
    Init : function()
        {
            this.OverlayDiv = $('#Overlay');
            this.LightBoxDiv = $('#LightBox');
            this.ImageElement = $('#LightBox img');
        },
    Open : function (imagePath)
        {
            var img = new Image();
            img.src = imagePath;
            
            if (img.width > 0)
            {
                this.ImageElement.attr('src', imagePath);
                this.LightBoxDiv.find('div:first').css('width', img.width + "px");
                this.OverlayDiv.css('display', 'block');
                this.LightBoxDiv.css('display', 'block');
            }                
            else // Wait for it to load
            {
                img.onload = CreateDelegate(this, function() 
                    {
                        this.ImageElement.attr('src', imagePath);
                        this.LightBoxDiv.find('div:first').css('width', img.width + "px");
                        this.OverlayDiv.css('display', 'block');
                        this.LightBoxDiv.css('display', 'block');
                    });
            }
        },
    Close : function()
        {
            this.LightBoxDiv.css('display', 'none');
            this.OverlayDiv.css('display', 'none');
        }
};

