﻿var index = 0;
var deck = ["a01s01","a01s02","a01s03","a01s04","a01s04b","a01s04c","a01s05","a01s06","a01s07","a01s08","a01s09","a01s10","a01s11","a01s12","a01s13","a02ph01","a02ph02","a02ph03","a02ph04","a02ph05","a02ph06","a02ph10","a02ph11","a02ph12","a02ph16","a02ph17","a03m01","a03m02","a03m03","a03m04","a03m05","a03m06","a03m07","a03m08","a03m09","a03m10","a04n01","a04n02","a04n03","a04n04","a04n05","a04n06","a04n07","a04n08","a04n09","a04n09a","a04n09b","a04n10a","a04n10b","a04n10c","a04n11","a06lm01","a06lm03","a06lm04","a06lm05"];

if (!window.UCPhysician_Demo)
	window.UCPhysician_Demo = {};

UCPhysician_Demo.Page = function() 
{
}

UCPhysician_Demo.Page.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		plugin = rootElement.getHost();
		
		// Sample event hookup:	
		rootElement.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));
	  rootElement.addEventListener("keyUp", Silverlight.createDelegate(this, this.handleKeyUp));
	  
    // Set the event handler function for the OnFullScreenChange event.
    plugin.content.onFullScreenChange = onFullScreenChanged;

    // Do initial layout of the app based on initial size.
    updateLayout(plugin.content.actualWidth, plugin.content.actualHeight);
	},
	
	// Sample event handler
	handleMouseDown: function(sender, eventArgs) 
	{
		// The following line of code shows how to find an element by name and call a method on it.
		// this.control.content.findName("Storyboard1").Begin();
	},
	
  handleKeyUp: function (sender, eventArgs) {
    if (eventArgs.key == 14) { //left arrow key
      if (index - 1 >= 0) {
        index--;
        sender.findname(deck[index]).visibility = "Visible";
      }
    }
    
    else if (eventArgs.key == 16) { //right arrow key
      if (index + 1 < deck.length) {
        sender.findname(deck[index]).visibility = "Collapsed";
        index++;
      }
    }
    
    else if (eventArgs.key == 35) { //f key
      plugin.content.fullScreen = !plugin.content.fullScreen;
    }
  }
}

function forward (sender) {
  var oldElement = sender.findname(deck[index]);
  var hasNextElement = (index + 1 < deck.length);
  
  if (oldElement.tag == "audio")
    oldElement.stop();

  if (sender.tag != "audio") {
    sender.visibility = "Collapsed";
    
    if (hasNextElement)
      index++;
  }
  
  else {
    sender.play();
    //sender.visibility = "Collapsed";
    
    if (hasNextElement)
      index++;  
  }
}

function onFullScreenChanged(sender, eventArgs)
{
    // Do layout resizing of the app whenever the FullScreen property changes.
    updateLayout(plugin.content.actualWidth, plugin.content.actualHeight);
}

// Resize and reposition application elements.
function updateLayout(width, height)
{
    // Perform layout tasks based on width and height.
}