﻿if (!window.IansPortfolio)
    window.IansPortfolio = {};

var uniqueAnimationName = 0;

IansPortfolio.Page = function() {
    this.loadMessage = "Welcome to this application";
}

IansPortfolio.Page.prototype =
{
    handleLoad: function(control, userContext, rootElement) {
        this.control = control;
        this.rootElement = rootElement;
        this.textHolder = this.control.content.FindName("TextHolder");
        this.titleHolder = this.control.content.FindName("TitleHolder");

        //Initialize Text
        this.descText = new Array();
        this.descText[0] = "Welcome to my online Portfolio. Use the buttons at the top to cycle through the different projects I have worked on. You will find projects ranging from the use of Artificial Intelligence, 3D game engines, educational software development, to network programming. Use the links at the right to send me any comments or feedback you have.";
        this.descText[1] = "Lead on the project to create a 3D trading card game playable in a web browser using the Unity3D game engine. Wrote technical documentation, architected a modular solution using OO principles, and managed the project using a Scrum/Agile hybrid. Completed the project on time.";
        this.descText[2] = "Developed a 3D game engine in Visual Studio .Net using C# and managed DirectX as an environment for learning foreign languages. Students interact in the 3D world to solve or play out stories by communicating in the foreign language. Computer characters are controlled by AI. Objects in the 3D environment were designed or modified in 3ds Max studio.";
        this.descText[3] = "This is a tools utility for creating 3D environments for the Axon Spark 3D Game Engine. It allows structures, characters, and other 3D objects to be added to the environment. It also allows character dialogs to be created. This makes it very easy for educators and teachers to create lessons to teach foreign languages.";
        this.descText[4] = "This project uses an Artificial Neural Network with Backdrop Propagation written in C# to play a popular trading card game. The AI player was trained using existing player data to choose an attack card based on the current state of the game. The AI has an 80% efficiency rating, which is remarkable given the fact that two players won’t always choose the same attack card given a similar game state.";
        this.descText[5] = "This is a 2D version of the Chaotic Game Pad using XNA and the Torque Game Engine. Worked on adding new cards and new functionality. Also designed and implemented the Auto Challenge webservice (among other webservices) used to match users based on their ELO score.";
        this.descText[6] = "CILT is a computer-assisted language learning (CALL) program that learns from the user in order to create a customized lesson. It is meant to accompany a traditional class in the language lab. Each lesson is fully customizable by the teacher.The student view, shown above, features a pedagogical agent and the main panel. The pedagogical agent guides the student through the lesson. CILT’s AI determines the next language item to teach based on the progress of the student. It maximizes learning by creating a lesson that is in the students' zone of proximal development";
        this.descText[7] = "The ChaoticGame Website is a Web 2.0 Ajax Portal written in ASP.Net. Worked on the team that brought the site to production in just 4 weeks. The site is unique in that the renderer is overridden and doesn’t use Microsoft controls, but rather uses our custom lighter weight controls making a highly dynamic Ajax driven site fast and scalable.";
        this.titleText = new Array();
        this.titleText[0] = "Welcome to ian.Natzmer.com";
        this.titleText[1] = "Chaotic Unity3D Game Client";
        this.titleText[2] = "Chinese Learning Game Engine";
        this.titleText[3] = "Chinese Learning Game Tool";
        this.titleText[4] = "Artificial Neural Net Player";
        this.titleText[5] = "Chaotic XNA Game Client";
        this.titleText[6] = "Chinese Intelligent Language Tutor (CILT)";
        this.titleText[7] = "ChaoticGame.com Website";

        this.rightArrow = new Button(control, "left", this, this.moveListToLeft, "sounds/Over_5.wma", "sounds/Click_5.wma");
        this.leftArrow = new Button(control, "right", this, this.moveListToRight, "sounds/Over_5.wma", "sounds/Click_5.wma");
        new Button(control, "Ian", null, null, "sounds/Over_2.wma", "sounds/Click_2.wma");
        new Button(control, "Chaotic", null, null, "sounds/Over_2.wma", "sounds/Click_2.wma");
        new Button(control, "AxonSpark", null, null, "sounds/Over_3.wma", "sounds/Click_3.wma");
        //        new Button(control, "arcade", null, null, "sounds/Over_1.wma", "sounds/Click_1.wma");
        //        new Button(control, "lens", null, null, "sounds/Focus.wma", "sounds/Shutter.wma");
        this.totalButtons = 8;

        this.currentButtonIndex = 0;

        this.leftArrow.Visibility = "Collapsed";

        if (null != this.control.content.findName("ResumeLink"))
            this.control.content.findName("ResumeLink").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleHyperlink));


    },
    handleHyperlink: function(sender, eventArgs) {
        window.location = "Docs/natzmerResume.pdf";
    },


    moveListToLeft: function() {
        if (this.currentButtonIndex > ((this.totalButtons * -1) + 1)) {
            this.currentButtonIndex--;
            this.moveList();
            this.textHolder.Text = this.descText[Math.abs(this.currentButtonIndex)];
            this.titleHolder.Text = this.titleText[Math.abs(this.currentButtonIndex)];
            if (this.currentButtonIndex == (this.totalButtons * -1) + 1) this.rightArrow.Visibility = "Collapsed";
        }
        this.leftArrow.Visibility = "Visible";
    },

    moveListToRight: function() {
        if (this.currentButtonIndex < 0) {
            this.currentButtonIndex++;
            this.moveList();
            this.textHolder.Text = this.descText[Math.abs(this.currentButtonIndex)];
            this.titleHolder.Text = this.titleText[Math.abs(this.currentButtonIndex)];
            if (this.currentButtonIndex == 0) this.leftArrow.Visibility = "Collapsed";
        }
        this.rightArrow.Visibility = "Visible";
    },

    moveList: function() {
        this.DoubleAnimationKeyFrame(this.control, this.rootElement, "buttonList", "(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)", this.currentButtonIndex * 300);
    },

    // -----------------------------------------
    // Add a DoubleAnimation for an element, returns the animation created
    // -----------------------------------------
    DoubleAnimationKeyFrame: function(control, root, targetName, targetProperty, value) {
        uniqueAnimationName++;
        var xaml = "<Canvas>" +
                        "<Canvas.Triggers>" +
                            "<EventTrigger>" +
                                "<EventTrigger.Actions>" +
                                    "<BeginStoryboard>" +
                                        "<Storyboard xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='_Generated_Animation_" + uniqueAnimationName + "' BeginTime='0'>" +
                                            "<DoubleAnimationUsingKeyFrames BeginTime='00:00:00' Storyboard.TargetName='" + targetName + "' Storyboard.TargetProperty='" + targetProperty + "'>" +
						                        "<SplineDoubleKeyFrame KeyTime='00:00:00.5' KeySpline='0.5,0,0.5,1' Value='" + value + "'/>" +
					                        "</DoubleAnimationUsingKeyFrames>" +
                                        "</Storyboard>" +
                                    "</BeginStoryboard>" +
                                "</EventTrigger.Actions>" +
                            "</EventTrigger>" +
                        "</Canvas.Triggers>" +
                    "</Canvas>";
        //alert(xaml);
        var animationCanvas = control.content.createFromXaml(xaml);
        root.children.add(animationCanvas);
        return control.content.findName("_Generated_Animation_" + uniqueAnimationName);
    }
}

IansPortfolio.createSilverlight = function(xapUrl, hostId, controlId) {
    if (!window.Silverlight) {
        alert("Silverlight.js can't be found");
        return;
    }

    if (Silverlight.isInstalled("2.0")) {
        var page = new IansPortfolio.Page();

        Silverlight.createObjectEx({
            source: xapUrl,
            parentElement: document.getElementById(hostId),
            id: controlId,
            properties: {
                width: "100%",
                height: "100%",
                version: "2.0",
                isWindowless: "True",
                background: "#00000000"
            },
            events: {
            onLoad: Silverlight.createDelegate(page, page.handleLoad)
            
            }
        });
    }
    else {
        document.writeln("<a href='http://go.microsoft.com/fwlink/?LinkID=124807' style='text-decoration: none;'><img src='images/NoSilverLight.jpg' alt='Get Microsoft Silverlight' style='border-style: none'/></a><p style='Color: #FFFFFF'>Please install Silverlight to view this Portfolio.<p/><p><a href='Docs/natzmerResume.pdf'>You can also click here to view my resume.<a/></p>");
    }
}

Silverlight.createDelegate = function(instance, method) {
return function() {
        return method.apply(instance, arguments);
    }
}

