﻿function OnBackgroundImageDownLoadProgressChanged(sender, args) {
    try {
        if (sender.DownloadProgress >= 1) {
            var qsf = document.getElementById("SilverlightObject");
            if (document.body.SplashScreenAnimationStarted == undefined) {
                var overlays = qsf.content.findName("overlays");
                if (overlays != null) {
                    overlays.opacity = 1;
                    document.body.SplashScreenAnimationStarted = true;
                }
            }
        }
    } catch (e) {
    }
}

function onSourceDownloadProgressChanged(sender, eventArgs) 
{
    try
    {
        var progress = eventArgs.progress;
        var totalWidth = document.body.clientWidth;
        var totalHeight = document.body.clientHeight;

        var layoutRoot = sender.getHost().content.findName("LayoutRoot");
        if (layoutRoot != null)
        {
            layoutRoot.Width = totalWidth;
            layoutRoot.Height = totalHeight;
            var progressBar = sender.getHost().content.findName("ProgressBar");
            if (progressBar != null) 
            {
                progressBar.width = progress * 201;

                //Set the opacity of the text blocks accordingly:
                var textBlockCount = 4;
                var visibleRange = 1 / textBlockCount;
                for (var i = 1; i <= textBlockCount; i++) {

                    var textBlock = sender.getHost().content.findName("text" + i.toString());
                    if (textBlock != null) 
                    {
                        if (progress > (i - 1) * visibleRange && (progress < i * visibleRange || (progress == 1 && i == textBlockCount))) {
                            textBlock.opacity = Math.max(1 - (i - 1) * visibleRange / progress, 0.9);
                        }
                        else {
                            textBlock.opacity = 0;
                        }
                    }
                }
            }
        }
    }
    catch(e)
    {
    }
}


