var currentBackgroundOpacityPercent;
var currentContentOpacityPercent;
var modalBackground;
var modalContent;
var modal;
var modalContentClose;
var opacityAdder = 10;
var milliseconds = 1;
var maxBackgroundOpacityPercent = 80;
var maxContentOpacitypercent = 100;

function CloseModal()
{
	modal = document.getElementById("ModalFrame");
	modalBackground = document.getElementById("ModalBackground");
	modalContent = document.getElementById("ModalContentFrame");
	modalContentClose = document.getElementById("ModalContentClose");
	currentBackgroundOpacityPercent = maxBackgroundOpacityPercent;
	currentContentOpacityPercent = maxContentOpacitypercent;
	FadeOutContent();
}

function OpenModal()
{
	modal = document.getElementById("ModalFrame");
	modalBackground = document.getElementById("ModalBackground");
	modalContent = document.getElementById("ModalContentFrame");
	modalContentClose = document.getElementById("ModalContentClose");
	modalContentClose.style.display = "none";
	SetOpacity(modalBackground, 0);
	SetOpacity(modalContent, 0);
	currentBackgroundOpacityPercent = 0;
	modalContent.style.display = "none";
	currentContentOpacityPercent = 0;
	
	if(document.getElementById("FlashFrame"))
	{
		document.getElementById("FlashFrame").style.display = "none";
	}
	
	FadeInBackground();
}

function SetOpacity(item, opacityPercent)
{
	item.style.opacity = opacityPercent/100;
	item.style.MozOpacity = opacityPercent/100;
	item.style.filter = 'alpha(opacity=' + opacityPercent + ')';
	item.style.filter.opacity = opacityPercent;
}

function FadeInBackground()
{
	if(currentBackgroundOpacityPercent < maxBackgroundOpacityPercent)
	{
        if(currentBackgroundOpacityPercent == 0)
        {
			modal.style.display = "block";
        }

        currentBackgroundOpacityPercent += opacityAdder;
        SetOpacity(modalBackground, currentBackgroundOpacityPercent);
        setTimeout('FadeInBackground()', milliseconds);

        if(currentBackgroundOpacityPercent == maxBackgroundOpacityPercent)
        {
			modalContent.style.display = "block";
			FadeInContent();
        }
    }
}

function FadeInContent()
{
	if(currentContentOpacityPercent < maxContentOpacitypercent)
	{
        currentContentOpacityPercent += opacityAdder;
        SetOpacity(modalContent, currentContentOpacityPercent);
        setTimeout('FadeInContent()', milliseconds);
        
        if(currentContentOpacityPercent == maxContentOpacitypercent)
        {
			modalContentClose.style.display = "block";
        }
    }
}

function FadeOutContent()
{
	if(currentContentOpacityPercent > 0)
	{
        currentContentOpacityPercent -= opacityAdder;
        SetOpacity(modalContent, currentContentOpacityPercent);
        setTimeout('FadeOutContent()', milliseconds);

        if(currentContentOpacityPercent == 0)
        {
			if(document.getElementById("FlashFrame"))
			{
				document.getElementById("FlashFrame").style.display = "block";
			}
			
			FadeOutBackground();
			modalContent.style.display = "none";
        }
    }
}

function FadeOutBackground()
{
	if(currentBackgroundOpacityPercent > 0)
	{
        currentBackgroundOpacityPercent -= opacityAdder;
        SetOpacity(modalBackground, currentBackgroundOpacityPercent);
        setTimeout('FadeOutBackground()', milliseconds);

        if(currentBackgroundOpacityPercent == 0)
        {
			modal.style.display = "none";
        }
    }
}

