﻿///////////////////////////////////////////////////////////////////////////////
//
//  createobjects.js   			version 1.0
//
//  This file is provided by Microsoft as a helper file for websites that
//  incorporate Silverlight Objects. This file is provided under the Silverlight
//  SDK 1.0 license available at http://go.microsoft.com/fwlink/?linkid=94240.
//  You may not use or distribute this file or the code in this file except as
//  expressly permitted under that license.
//
//  Copyright (c) 2007 Microsoft Corporation. All rights reserved.
//
///////////////////////////////////////////////////////////////////////////////

Silverlight.createDelegate = function(instance, method) {
	return function() {
        return method.apply(instance, arguments);
    }
}


function createSLObjects()
{
    Silverlight.createObjectEx( {   source: 'Scene.xaml',
                                        parentElement: document.getElementById("menuDiv"),
                                        id: 'Menu',
                                        properties:{ width:'860px', height:'640px', version:'1.0', background:document.body.style.backgroundColor, isWindowless:'true' },
                                        events:{ onLoad:slConstruct } } );
}


function slConstruct(control, userContext, rootElement) {

	testObject = new Object();

	//load xml
	loadingXML(rootElement);
			//now initializing from the loadingXML() function, so that initialization doesn't happen until after XML loads
			//initialize menu and load skin
			//initMenu(rootElement);
	testObject.control = control;
	//loadLCDSAnimation(rootElement);
	//loadLCDSVideo(rootElement);
	//Add Event Handler
	testObject.progressAnim = rootElement.findName("progressAnim");
	testObject.progressAnim.addEventListener("Completed", Silverlight.createDelegate(testObject, startTimer));
	testObject.splashAniEvent = rootElement.findName("media_splashAnimation");
	testObject.splashAniEvent.addEventListener("mediaOpened", Silverlight.createDelegate(testObject, handleMediaOpened));

	var silverlightInstallImageDiv = document.getElementById( "silverlightInstallImage" );
	if ( silverlightInstallImageDiv != null ) {
		var parentElement = silverlightInstallImageDiv.parentNode;
		parentElement.removeChild( silverlightInstallImageDiv );
	}
}



function silverlightSetup( xamlUri, notInstalledImage, notInstalledHtmlString )
{
	//Create our install experience html
	var installExperienceHTML =  '<div id="silverlightInstallImage" style="position:auto; text-align:left; background-repeat:no-repeat; width:860px; height:640px; background-image:url(silverlightInstallImage.png);">';
	installExperienceHTML += '<div style="padding-left:320px; padding-top:230px;">';
	installExperienceHTML += '<div id="InstallPromptDiv"> </div> </div> <div id="PostInstallGuidance"';
	installExperienceHTML += 'style="width:auto; font-weight:bold; font-size:18px; font-family:sans-serif; height:auto; padding-top:20px;text-align:center; color:#3366ff; ';
	installExperienceHTML += 'font-weight:normal; font-size:11pt">&nbsp;</div> </div>';

	//calls installandcreatesilverlight method to instantiate silverlight once it is installed
	Silverlight.InstallAndCreateSilverlight('1.0',
		document.getElementById('divPlayer_0'),
		installExperienceHTML,
		'InstallPromptDiv',
		createSLObjects);

	//place text below the install medallion to inform the users what to do after installation
	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.";
		}
		//if silverlight is NOT available insert html into the menudiv layer
		if ( !Silverlight.available && typeof notInstalledHtmlString != "undefined" ) {
			var menudiv = document.getElementById('menuDiv');
			menudiv.innerHTML= notInstalledHtmlString;
		}
	}
}
