﻿var FullScreenImage;
var FullScreenPage;

/*
    This function will initialize a fullscreen image
*/
function ShowFullScreenImage(InfoScreenImageLocation, FullScreenImageLocation)
{
    var loadingScreen = new ModalInformationScreen('load_screen',1000, "Please wait, loading image");
    loadingScreen.Show(); 
    
    var img = new Image();
    img.onload =    function()
                    {
                        FullScreenImage = new ModalImage("myImage", 1000, this);
                        loadingScreen.Hide();
                        FullScreenImage.Show();
                        
                        //determine the position for the close button
                        if(FullScreenImage.AddBorder)
                        {
                            ShowButton('FullScreenCloseButton', FullScreenImage.BorderPosition.x, FullScreenImage.BorderPosition.y - 30, 1004, 'Close', function(){ FullScreenImage.Hide(); RemoveButton('FullScreenCloseButton');});
                        }
                        else
                        {
                            ShowButton('FullScreenCloseButton', FullScreenImage.ImagePosition.x, FullScreenImage.ImagePosition.y - 30, 1004, 'Close', function(){ FullScreenImage.Hide(); RemoveButton('FullScreenCloseButton');});
                        }
                    }
    
    img.src = FullScreenImageLocation;   
    
}

//This function creates a close button just above the Image
function ShowButton(id, left, top, zIndex, value, callback)
{
    var Button = document.createElement('a');
    Button.setAttribute('id', id);
    Button.onclick = callback;
    Button.setAttribute('href','#');
    Button.style.position = 'absolute';
        
    Button.style.left = left + 'px';
    Button.style.top = top + 'px';
    
    Button.style.zIndex = zIndex;
    Button.className = 'Button';
    Button.innerHTML = value;
    
    document.body.appendChild(Button);    
}

function RemoveButton(id)
{
    $(id).remove();
}

/*
    this function will display a modal page dialog and add buttons to it.
*/
function ShowModalPage(url)
{
    FullScreenPage = new ModalPage('MyModalPage', 1000, url);
    FullScreenPage.Show();
    ShowButton('closeButton', 60,30, 1004,'Close', function(){FullScreenPage.Hide();RemoveButton('closeButton');RemoveButton('showInNewWindow');});
    ShowButton('showInNewWindow', 115, 30, 1004, 'Open as popup', function(){FullScreenPage.Hide();RemoveButton('closeButton');RemoveButton('showInNewWindow');OpenPageInNewWindow(FullScreenPage.URL)});
}

//This function will open a page into a new window.
function OpenPageInNewWindow(url)
{
    var screenHeight = document.viewport.getHeight() - 100;
    var screenWidth = document.viewport.getWidth() - 100;
    window.open(url, 'Website', 'width=' + screenWidth + 'px,height=' + screenHeight + 'px,scrollbars=yes,toolbar=yes,location=yes,resizable=yes','false');
}
