﻿//var maxWidth = 450;
//var maxHeight = 500;

function showPopup(popup)
{
    var maxWidth = getElementSize(popup).width;
    var maxHeight = getElementSize(popup).height;
    
    fadeScreenToBlack();	        
    popup.style.position = 'absolute';
    popup.style.top = '50%';
    popup.style.left = '50%';
    popup.style.marginLeft = 0 - (maxWidth / 2);
    popup.style.marginTop = 0 - (maxHeight / 2);
    popup.style.display = '';
}    

function hidePopup(popup)
{
    fadeScreenToNormal();
    popup.style.display = 'none';
} 

function fadeScreenToBlack()
{
    var fade = document.getElementById('fade');
    if (fade == null)
    {
        document.body.innerHTML = "<div id=\"fade\" class=\"black_overlay_1\"></div>" + document.body.innerHTML;
        fade = document.getElementById('fade');
    }
    
    var num = parseInt(fade.className.replace('black_overlay_',''));
    fade.style.display = '';
    
    if (num == 1)
    {
        var pageSize = getPageSize();
        var pagewidth = pageSize[0];
        var pageheight = pageSize[1];
	    
        fade.style.width = pagewidth;
        fade.style.height = pageheight;             
    }
    
    if (num < 6)
    {
        num++;
        fade.className = 'black_overlay_'+num;
        setTimeout('fadeScreenToBlack();', 25);
    }
}   

function fadeScreenToNormal()
{
    var fade = document.getElementById('fade');
    var num = parseInt(fade.className.replace('black_overlay_',''));
    num--;    
        
    if (num > 0)
    {
        fade.className = 'black_overlay_'+num;
        setTimeout('fadeScreenToNormal();', 25);
    }
    else
    {
        fade.style.display = 'none';       
    }
}     

function getPageSize()
{
    if (window.innerHeight && window.scrollMaxY)
    {
        // Firefox
        yWithScroll = window.innerHeight + window.scrollMaxY;
        xWithScroll = window.innerWidth + window.scrollMaxX;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight)
    {
        // all but Explorer Mac
        yWithScroll = document.body.scrollHeight;
        xWithScroll = document.body.scrollWidth;
    }
    else 
    { 
        // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        yWithScroll = document.body.offsetHeight;
        xWithScroll = document.body.offsetWidth;
    }
    
    arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
    return arrayPageSizeWithScroll;
}   