﻿// JScript File
function initPage(divName,appName,accountId)
    {
	    var installExperienceHTML = '';
	    installExperienceHTML += '<div style="position:auto; margin:0; text-align:left; background-repeat:no-repeat; height:400px; width:536px; background-image:url(Install_placeholder.jpg);">'; 
	    installExperienceHTML += '<div style="padding-left:160px; padding-top:100px; width:auto;">';
	    installExperienceHTML += '<div id="InstallPromptDiv"> </div> </div> <div id="PostInstallGuidance"'; 
	    installExperienceHTML += 'style="width:auto; font-family:sans-serif; height:auto; padding-top:20px;text-align:center; color:#3366ff; ';
	    installExperienceHTML += 'font-weight:normal; font-size:11pt; color:white;">&nbsp;</div> </div>';

        var createSilverlight = function()
        {        
            Silverlight.createHostedObjectEx({
	            source: "streaming:/" + accountId + "/" + appName,parentElement: document.getElementById(divName)});
        };

	    InstallAndCreateSilverlight('1.0', document.getElementById(divName),
	                                installExperienceHTML,'InstallPromptDiv',createSilverlight);

	    var PostInstallGuidance = document.getElementById('PostInstallGuidance');
	    if ( document.getElementById('PostInstallGuidance') )
	    {
		    if ( Silverlight.ua.Browser == "MSIE" )
		    {
			    if ( Silverlight.available )
			    {
				    PostInstallGuidance.innerHTML="When installation is complete, restart your browser to activate your Silverlight content.";
			    } 
			    else 
			    {
				    PostInstallGuidance.innerHTML= "";
			    }
		    }
		    else if ( Silverlight.ua.Browser == "Firefox" || Silverlight.ua.Browser == "Safari")
		    {
			    PostInstallGuidance.innerHTML="Your browser is "+ Silverlight.ua.Browser + ". When installation is complete,<br />restart your browser to activate your Silverlight content.";
		    }
		    else
		    {
			    PostInstallGuidance.innerHTML="Your browser may not be supported by Microsoft Silverlight.<br />Please visit http://www.microsoft.com/silverlight/system-requirements.aspx for more information.";
		    }
	    }
    }


    function InstallAndCreateSilverlight(version, SilverlightDiv, installExperienceHTML, installPromptDivID, createSilverlightDelegate)
    {
        if(!window.Silverlight)
        {
    	    window.Silverlight={};
        }
	    var RetryTimeout=3000; //The interval at which Silverlight instantiation is attempted(ms)	
	    if ( Silverlight.isInstalled(version) )
	    {
		    createSilverlightDelegate();
	    }
	    else
	    {
		    if ( installExperienceHTML && SilverlightDiv )
		    {
		    SilverlightDiv.innerHTML=installExperienceHTML;
		    document.body.innerHTML;
		    }
		    if (installPromptDivID)
		    {
			    var ObjInstallPromptDiv = document.getElementById(installPromptDivID);
			    if ( ObjInstallPromptDiv )
			    {
				    ObjInstallPromptDiv.innerHTML = Silverlight.createObject(null, null, null, {version: version, inplaceInstallPrompt:true},{}, null);
			    }
		    }
		    setTimeout(TimeoutDelegate, RetryTimeout);
	    }
    }

    function TimeoutDelegate()
    {
	    InstallAndCreateSilverlight(version, null, null, null, createSilverlightDelegate);
    }
