﻿// This sets up the resizing of the project
// Make background fill the page
// Center the rest of the elements
var plugin;
var width=1024;
var height= 768;
var number = 0;
var oldX = 0;
var oldY = 0;
firstRun = true;

function onLoaded(sender, args) {
    //Load News and XAML
    initDownloader(sender);
    
    // Retrieve a reference to the plug-in.
    var slPlugin = sender.getHost();
    // Set the event handler function to the OnResize event.
    slPlugin.content.onResize = onResized;

    // Do initial layout of the application based on initial size.
    //onResized(sender, eventArgs);
    
    //Stretch Black background to fill browser
    var screenWidth = pageWidth();
	var screenHeight = pageHeight();
	if (screenHeight <= height) screenHeight = height;
	if (screenHeight <= width) screenHeight = width;
    sender.findName("blackBack").Width = screenWidth;
    sender.findName("blackBack").Height = screenHeight;
    
    //draw lines
    //CHECK FOR FIRST RUN
    
    if (firstRun) {
    
    //Load Thumbnails and movie
    sender.findName("videomain").Source="videos/land/golf/golf_whatisreal.wmv";
    
    //Make thumbNailz
    buildThumbnails(sender, args);
    
    
    // Set spacing here for lines
    var spacing = 10;
    
    var xaml_string='<Canvas xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="' + screenWidth + '" Height="' + screenHeight + '" x:Name="screen" >';
    xaml_string+='<Path Stroke="#3F003990" StrokeThickness="2">';
    xaml_string+='<Path.Data>';
    xaml_string+= ' <GeometryGroup>';
    
    
    for (a=spacing; a<= (screenHeight+screenWidth); a+=spacing) {
    xaml_string+='<LineGeometry StartPoint="0,' + a + '" EndPoint="' + a + ',0" />';
    }
    
    xaml_string+='</GeometryGroup> ';
    xaml_string+='</Path.Data>';
    xaml_string+='</Path>';
    xaml_string+='</Canvas>';
    
    var plugin = sender.getHost();
    xamlDiagonal = plugin.content.createFromXaml(xaml_string);
	sender.findName("lines").children.add(xamlDiagonal);
	
	firstRun = false;
	}
}


function onResized(sender, eventArgs)
{
    number ++;
    //sender.findName("theBackground").X = 1.5;
    //sender.findName("block").setValue("Text", "resized" + number);

	var screenWidth = pageWidth();
	var screenHeight = pageHeight();
	var xMultiplier = screenWidth/width;
	var yMultiplier = screenHeight/height;
	if (yMultiplier >= xMultiplier) {
		multiplier = xMultiplier;
	} else {
		multiplier = yMultiplier;
	}
	//sender.findName("scales").scaleX = multiplier;
	//sender.findName("scales").scaleY = multiplier;
	oldX = screenWidth;
	oldY = screenHeight;
}


function pageWidth() {
	return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?      document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 

function pageHeight() {
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} 
	
