﻿var popupWindowWrap;
var popupWindow;
var popupWindowHeight;
var popupDirectionDown = false;
var currentPopupBottom;
var popupInterval;
var startHeight;
var started = false;

function startPopup()
{
    if (currentPopupBottom == -1 * popupWindowHeight)
    {
        if (popupInterval != undefined)
            clearInterval(popupInterval);
            
        popupDirectionDown = false;
        popupInterval = setInterval("slidePopupPanel(1, " + startHeight + ")", 20);
        started = true;
    }
}
function hidePopup()
{
    if (started && currentPopupBottom > -1 * popupWindowHeight )
    {
        if (popupInterval != undefined)
            clearInterval(popupInterval);
            
        popupDirectionDown = true;
        popupInterval = setInterval("slidePopupPanel(-1, 0)", 20);
        started = false;
    }
}
function togglePopup()
{
    started = false;
    if (popupInterval != undefined)
        clearInterval(popupInterval);

    popupWindowWrap.style.display = "block";
    if (popupDirectionDown)
    {
        popupInterval = setInterval("slidePopupPanel(-1, 0)", 20);
        popupDirectionDown = false;
    }
    else
    {
        //openLink.className = "infoLink openPanel";
        
        popupInterval = setInterval("slidePopupPanel(1, 0)", 20);
        slidePopupPanel(1);
        popupDirectionDown = true;
    }
}
function slidePopupPanel(direction, maxValue)
{
    var distance = 4;
    currentPopupBottom += direction * distance;
    
    popupWindow.style.bottom = currentPopupBottom + "px";

    if (currentPopupBottom <= popupWindowHeight * -1 || currentPopupBottom >= maxValue)
    {
        if (currentPopupBottom >= maxValue)
        {
            popupWindow.style.bottom = maxValue + "px";
            currentPopupBottom = maxValue;
        }
        else if (currentPopupBottom <= popupWindowHeight * -1)
        {
            popupWindow.style.bottom = (popupWindowHeight * -1) + "px";
            currentPopupBottom = popupWindowHeight * -1;
            popupWindowWrap.style.display = "none";
        }
        clearInterval(popupInterval);
    }
}
