var dzth_hostPrefix = "";
var dzth_environment = "";

var silverlightInstallHtml = "<img src='http://photobooth.cmafest.com/Scripts/photobooth_install.jpg' alt='Get Microsoft Silverlight' style='border-style: none' onclick='onSilverlightInstallClick();'/>"
var silverlightInstallingHtml = "<img src='http://photobooth.cmafest.com/Scripts/photobooth_setup_working.jpg' alt='Installing Microsoft Silverlight 2 ...' style='border-style: none' />";
var silverlightRestartHtml = "<img src='http://photobooth.cmafest.com/Scripts/photobooth_reboot.jpg' alt='Microsoft Silverlight 2 is installed.  Please reboot.' style='border-style: none' />";
var silverlightVersion = "2.0";


function initPhotoBooth(environment) {

    dzth_hostPrefix = "http://photobooth.cmafest.com";
    dzth_environment = environment;
}

function onSourceDownloadProgressChanged(sender, eventArgs) {
    sender.findName("progressBar").Width = eventArgs.progress * sender.findName("progressBarBackground").Width;
}
function onSilverlightInstallClick() {
    window.location = "http://go2.microsoft.com/fwlink/?linkid=124807";
    document.getElementById("photoBoothHost").innerHTML = silverlightInstallingHtml;
}

function injectPhotoBooth(isNewSilverlightInstall) {

    var newInstallValue = "false";
    if (isNewSilverlightInstall && isNewSilverlightInstall == true) {
        newInstallValue = "true";
    }
    var params = "environment=" + dzth_environment + ",isNewInstall=" + newInstallValue;
    Silverlight.createObjectEx(
            {
                source: dzth_hostPrefix + "/ClientBin/CMAPhotoBooth.xap",
                id: "photoBoothObject",
                parentElement: document.getElementById("photoBoothHost"),
                properties: {
                version: silverlightVersion,
                    background: "#000",
                    width: "900px",
                    height: "600px",
                    autoUpgrade: "false",
                    enableHtmlAccess: "true",
					isWindowless: "true",
                    splashscreensource: dzth_hostPrefix + "/ClientBin/splashscreen.xaml"
                },
                initParams: params,
                events: {
                    onSourceDownloadProgressChanged: "onSourceDownloadProgressChanged"
                }
            }
            )
}

function dzth_OnSilverlightInstalled() {
    injectPhotoBooth(true);
}

function scavengerHuntLoad() {
    Silverlight.onSilverlightInstalled = dzth_OnSilverlightInstalled;
    if (Silverlight.isRestartRequired) {
        document.getElementById("photoBoothHost").innerHTML = silverlightRestartHtml;
        return;
    }
    if (Silverlight.isInstalled(silverlightVersion)) {
        injectPhotoBooth(false);
    }
    else {

        document.getElementById("photoBoothHost").innerHTML = silverlightInstallHtml;

    }

}

if (window.addEventListener) {
    window.addEventListener('load', scavengerHuntLoad, false);
}
else {
    window.attachEvent('onload', scavengerHuntLoad);
}
   