﻿if (!window.Defender2_1)
	window.Defender2_1 = {};

Defender2_1.Scene = function() 
{
}

//var language = "swedish";


//locate the url
var searchString = document.location.search;

// strip off the leading '?' and set the variable
var language = searchString.substring(1);


Defender2_1.Scene.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		var downloader = control.createObject("downloader");
		downloader.addEventListener("downloadProgressChanged", "downloadChanged");
		downloader.addEventListener("completed", "downloadCompleted");
		downloader.open("GET", "content.zip");
		downloader.send();
	}
}

function downloadChanged(sender, args)
{
  var done = Math.floor(sender.downloadProgress * 100);
  var progress = sender.findName("loadingText");
  progress.text = done + "%";
  var progress2 = sender.findName("loadingTextShadow");
  progress2.text = done + "%";
}

function downloadCompleted(sender, args)
{
  // Make sure the download was ok
  if (sender.status != 200) 
  {
    alert("download failed");
    return;
  }

  // Hide the Loading...
  sender.findName("loadingText").opacity = 0;
  sender.findName("loadingTextShadow").opacity = 0;
  sender.findName("loadingImage").opacity = 0;
  sender.findName("innerStrokeLoad").opacity = 0;
  sender.findName("outerStrokeLoad").opacity = 0;
  sender.findName("loadBG").opacity = 0;
  sender.findName("navBarLoad").width = 1;
  sender.findName("navBarLoad").opacity = 0;
  
  // Build the XAML
  var theXaml = sender.getResponseText("Page.xaml");
  var theContent = sender.getHost().content.createFromXaml(theXaml);
  
  // Add to the Root
  var root = sender.findName("root");
  root.children.insert(0, theContent);
  
  // Set the Audio
  var voiceover = theContent.findName("vo_all_mp3");
  voiceover.setSource(sender, "vo_all.mp3")
  
  // Set the Images
  var background = theContent.findName("BG");
  background.setSource(sender, "bg1.jpg");
  
  var castle = theContent.findName("OpenCastle");
  castle.setSource(sender, "openingCastle.png");
  
  var windows = theContent.findName("OpenWindows");
  windows.setSource(sender, "opening_windows.png");
  
  var defender = theContent.findName("OpenDefender");
  defender.setSource(sender, "openingDefender.png");
  
  var desktop = theContent.findName("WindowsDesktop");
  desktop.setSource(sender, "windows_desktop.png");
  
  var startbar = theContent.findName("StartBar");
  startbar.setSource(sender, "startBar.png");
  
  var startmenu1 = theContent.findName("StartMenu1");
  startmenu1.setSource(sender, "startMenu2_1.png");
  
  var startmenu2 = theContent.findName("StartMenu2");
  startmenu2.setSource(sender, "startMenu2_2.png");
  
  // Set the Captions
  var Cap1 = theContent.findName("Caption1Image");
  Cap1.setSource(sender, "Captions/Caption1" + language + ".png");
  
  var Cap1b = theContent.findName("Caption1bImage");
  Cap1b.setSource(sender, "Captions/Caption1b" + language + ".png");
  
  var Cap1c = theContent.findName("Caption1cImage");
  Cap1c.setSource(sender, "Captions/Caption1c" + language + ".png");
  
  var Cap2 = theContent.findName("Caption2Image");
  Cap2.setSource(sender, "Captions/Caption2" + language + ".png");
  
  var Cap2b = theContent.findName("Caption2bImage");
  Cap2b.setSource(sender, "Captions/Caption2b" + language + ".png");

  var Cap3 = theContent.findName("Caption3Image");
  Cap3.setSource(sender, "Captions/Caption3" + language + ".png");
  
  var Cap3b = theContent.findName("Caption3bImage");
  Cap3b.setSource(sender, "Captions/Caption3b" + language + ".png");
  
  var Cap4 = theContent.findName("Caption4Image");
  Cap4.setSource(sender, "Captions/Caption4" + language + ".png");
  
  var Cap5 = theContent.findName("Caption5Image");
  Cap5.setSource(sender, "Captions/Caption5" + language + ".png");
  
  var Cap6 = theContent.findName("Caption6Image");
  Cap6.setSource(sender, "Captions/Caption6" + language + ".png");
  
  var Cap7 = theContent.findName("Caption7Image");
  Cap7.setSource(sender, "Captions/Caption7" + language + ".png");
  
  var Cap8 = theContent.findName("Caption8Image");
  Cap8.setSource(sender, "Captions/Caption8" + language + ".png");
  
  var Cap9 = theContent.findName("Caption9Image");
  Cap9.setSource(sender, "Captions/Caption9" + language + ".png");
  
  var Cap10 = theContent.findName("Caption10Image");
  Cap10.setSource(sender, "Captions/Caption10" + language + ".png");
  
  var Cap10b = theContent.findName("Caption10bImage");
  Cap10b.setSource(sender, "Captions/Caption10b" + language + ".png");
  
  var Cap10c = theContent.findName("Caption10cImage");
  Cap10c.setSource(sender, "Captions/Caption10c" + language + ".png");
  
  var Cap11 = theContent.findName("Caption11Image");
  Cap11.setSource(sender, "Captions/Caption11" + language + ".png");
}
