﻿var AnimationRunning = true;

if (!window.CollageDisplay)
	CollageDisplay = {};

CollageDisplay.Page = function() 
{
}

CollageDisplay.Page.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		// Preload the resources using a zip
		var downloader = rootElement.getHost().createObject("downloader");
		downloader.addEventListener("downloadProgressChanged", onDownloadProgressChanged);
		downloader.addEventListener("completed", onDownloadCompleted);
		downloader.open("GET", "content/animation/Animation.zip");
		downloader.send();
	}
}


function onDownloadCompleted(sender, eventArgs)
{
	// Retrieve references to the Image objects
	var IMG0024 = sender.findName("IMG_0024");
	var IMG0028 = sender.findName("IMG_0028");
	var IMG0051 = sender.findName("IMG_0051");
	var IMG0157 = sender.findName("IMG_0157");
	var IMG0169 = sender.findName("IMG_0169");
	var IMG0177 = sender.findName("IMG_0177");
	var IMG0230 = sender.findName("IMG_0230");
	var IMG0246 = sender.findName("IMG_0246");
	var IMG0281 = sender.findName("IMG_0281");
	var COLLAGE = sender.findName("Collage");

	// Set the Source properties to the resources from the downloaded Zip package file.
	IMG0024.setSource(sender, "IMG_0024.JPG");
	IMG0028.setSource(sender, "IMG_0028.JPG");
	IMG0051.setSource(sender, "IMG_0051.JPG");
	IMG0157.setSource(sender, "IMG_0157.JPG");
	IMG0169.setSource(sender, "IMG_0169.JPG");
	IMG0177.setSource(sender, "IMG_0177.JPG");
	IMG0230.setSource(sender, "IMG_0230.JPG");
	IMG0246.setSource(sender, "IMG_0246.JPG");
	IMG0281.setSource(sender, "IMG_0281.JPG");
	COLLAGE.setSource(sender, "collage.JPG");

	// Hide the progress
	sender.findName("ProgressHide").Begin();

	// Start the animation
	sender.findName("Animation").Begin();
	
	// Show the play/pause button
	sender.findName("btnPlayStop").Visibility = "Visible";
}

function onDownloadProgressChanged(sender, eventArgs)
{
	// Calculate the downloaded percentage.
	var percentage = Math.floor(sender.downloadProgress * 100);

	// Update the Rectangle and TextBlock objects of the visual progress indicator.
	var progressText = sender.findName("progress");
	progressText.text = percentage + "%";
}

function btn_MouseEnter(sender, args) 
{
	sender.findName("MouseEnter").Begin();
}

function btn_MouseLeave(sender, args)
{
	sender.findName("MouseLeave").Begin();
}

function btn_MouseLeftButtonDown(sender, args)
{
	sender.findName("btnClickHighlight").opacity = 1.0;
	if (AnimationRunning)
	{
		sender.findName("PlayIcon").opacity = 1.0;
		sender.findName("PauseIcon").opacity = 0.0;
		sender.findName("Animation").Pause();
	}
	else
	{
		sender.findName("PlayIcon").opacity = 0.0;
		sender.findName("PauseIcon").opacity = 1.0;
		sender.findName("Animation").Resume();
	}
	AnimationRunning = !AnimationRunning;
}

function btn_MouseLeftButtonUp(sender, args)
{
	sender.findName("btnClickHighlight").opacity = 0.0;
}
