
///////////////////////////////////////////////////////////////////////////////////////////////////////
//
//     *****   MainWindow.js    *****
//     A class defining a main window
//
//     © CM Group Ltd. All rights reserved.
//     Version 1.0
///////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////
//      Main Window Class & Methods
////////////////////////////////////////////////////////////////////////////


contentmaster.MainWindow = function(xamlobject, title, posX, posY, contentSrc, sceneClass, windowNum)
{
    this.xamlObject = xamlobject;
    this.title = title;
    this.posX = posX;
    this.posY = posY;
    this.contentSrc = contentSrc;
    this.sceneClass = sceneClass;
    this.contentURL;
    this.htmlPage = "";
    
    this.width = 0;
    this.height = 0;
    
    this.type = "main";
    this.control = document.getElementById("silverlightControl1");
    this.windowNum = windowNum; //unique number
    this.scrollNum = 0;
    
    this.layoutType = "splash"; // for resizer
    this.scrollControl = null; // scroll bar
    
    this.contentTypes = new Array();
    this.contentHeight = 0;

    this.breadCrumbs ={
        modTitle: "Module",
        modXaml: this.xamlObject.children.getItem(9).children.getItem(0),
        modPath: "",
        topTitle: "Topic",
        topXaml: this.xamlObject.children.getItem(9).children.getItem(2),
        topPath: "",
        arrow: this.xamlObject.children.getItem(9).children.getItem(1)
    }

	
    this.configureWindow();
    
}

contentmaster.MainWindow.prototype.configureWindow = function()  // sets windows position, assigns dragbar, assigns resizer
{
    var wpfControl = document.getElementById("silverlightControl1");
    var window = this.xamlObject;
    
    window["Canvas.Left"] = this.posX;
    window["Canvas.Top"] = this.posY;
    window.children.getItem(2).text = this.title;
    
    //assign restore events
    var restButton = window.children.getItem(11);
    restButton.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.adjustSize));
    
    //assign drag events 
    var dragBar = window.children.getItem(3);
    dragBar.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.onMouseDown));
    dragBar.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.onMouseUp));
    dragBar.addEventListener("MouseMove", Silverlight.createDelegate(this, this.onMouseMoveForChild));
    
    // assign close events
    window.children.getItem(6).addEventListener("MouseEnter", Silverlight.createDelegate(this, this.controls_close_enter));
    window.children.getItem(6).addEventListener("MouseLeave", Silverlight.createDelegate(this, this.controls_close_leave));
    // assign restore events
    window.children.getItem(11).addEventListener("MouseEnter", Silverlight.createDelegate(this, this.controls_rest_enter));
    window.children.getItem(11).addEventListener("MouseLeave", Silverlight.createDelegate(this, this.controls_rest_leave));
    // assign minimize events
    window.children.getItem(5).addEventListener("MouseEnter", Silverlight.createDelegate(this, this.controls_min_enter));
    window.children.getItem(5).addEventListener("MouseLeave", Silverlight.createDelegate(this, this.controls_min_leave));
    
    //assign breadcrumb events
    this.breadCrumbs.modXaml.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.clickBC));
    this.breadCrumbs.modXaml.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.hoverMod));
    this.breadCrumbs.modXaml.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.hoverLeave));
    
    this.breadCrumbs.modXaml.Cursor = "Hand";
    
    //assign resize control
    var resizeXamlControl = window.children.getItem(7)
    this.resizeControl = new contentmaster.Resizer(resizeXamlControl, window, this);
    
    //assign html button events
    var htmlBtn = window.children.getItem(13);
    htmlBtn.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.open_html));
    htmlBtn.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.html_enter));
    htmlBtn.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.html_leave));
}

contentmaster.MainWindow.prototype.scrollCheck = function(contentHeight, shapeHeight) //checks if scrollbar needed
{
    // if holder > contentshape, add scrollbar
    if (contentHeight+40 > shapeHeight){
        if (this.scrollControl == null){
            this.scrollControl = new contentmaster.scrollBarNav(this.xamlObject, this.xamlObject.children.getItem(8).children.getItem(0), contentHeight, shapeHeight, this.xamlObject.children.getItem(1), 5, this.windowNum, this.scrollNum, null, true);
            this.scrollNum++;
        }
        else{
            this.scrollControl.configureScrollBar(contentHeight, shapeHeight);
        }
    }
    else if (contentHeight+40 <= shapeHeight){
        if (this.scrollControl != null){
            this.scrollControl.removeScrollBar();
            delete this.scrollControl;
            this.scrollControl = null;
        }
    }
}

contentmaster.MainWindow.prototype.scrollCheckHor = function(contentWidth, shapeWidth) //checks if horizontal scrollbar needed
{
    if (contentWidth+10 > shapeWidth){
        if (this.scrollControlHor == null){
            this.scrollControlHor = new contentmaster.scrollBarHor(this.xamlObject, this.xamlObject.children.getItem(8).children.getItem(0), contentWidth, shapeWidth, this.xamlObject.children.getItem(1), -85, this.windowNum, this.scrollNum);
            this.scrollNum++;
        }
        else{
            this.scrollControlHor.configureScrollBar(contentWidth, shapeWidth);
        }
    }
    else if (contentWidth+10 <= shapeWidth){
        if (this.scrollControlHor != null){
            this.scrollControlHor.removeScrollBar();
            delete this.scrollControlHor;
            this.scrollControlHor = null;
        }
    }
}

contentmaster.MainWindow.prototype.open_html = function(sender)
{
    var path = "HTML_site/" + this.htmlPage;
    window.open(path,'');
}


contentmaster.MainWindow.prototype.setZIndex = function(sender)
{
    var windows = sender.findName("windows");
    var zindex = 0;
    for (i=0; i<windows.children.count; i++){
        if (windows.children.getItem(i)["Canvas.ZIndex"] > zindex){
        zindex = windows.children.getItem(i)["Canvas.ZIndex"];
        }else{
        continue;
        }  
    }
    if (zindex != sender.getParent()["Canvas.ZIndex"]) sender.getParent()["Canvas.ZIndex"] = (zindex+1);
}


// Start drag and drop operation.
contentmaster.MainWindow.prototype.onMouseDown = function(sender, mouseEventArgs) // to drag window
{
    this.setZIndex(sender);
    // Set the beginning position of the mouse.
    this.beginX = mouseEventArgs.getPosition(null).x;
    this.beginY = mouseEventArgs.getPosition(null).y;
    this.isMouseDown = true;
    // Ensure this object is the only one receiving mouse events.
    sender.captureMouse();
    this.objectToDrag = sender.getParent();

    if (this.sceneClass.hotWindow) this.sceneClass.hotWindow.children.getItem(0).Fill = this.getActiveHighlight(sender, "off");
    this.objectToDrag.children.getItem(0).Fill = this.getActiveHighlight(sender, "on");
    this.sceneClass.hotWindow = this.objectToDrag;

}

// Reposition object during drag and drop operation.
contentmaster.MainWindow.prototype.onMouseMoveForChild = function(sender, mouseEventArgs) // window being dragged
{
    // Determine whether the mouse button is down.
    // If so, move the object.
    if (this.isMouseDown == true)
    {
        // Retrieve the current position of the mouse.
        var currX = mouseEventArgs.getPosition(null).x;
        var currY = mouseEventArgs.getPosition(null).y;
        
        sender.getParent()["Canvas.Left"] += currX - this.beginX;
        sender.getParent()["Canvas.Top"] += currY - this.beginY;
        
        if (sender.getParent()["Canvas.Left"] < 0) sender.getParent()["Canvas.Left"] = 0;
        if (sender.getParent()["Canvas.Top"] < 0) sender.getParent()["Canvas.Top"] = 0;

        sender.getParent().opacity = 0.5;

        this.beginX = currX >= 0 ? currX : 0;
        this.beginY = currY >= 0 ? currY : 0;
    }
}

// Stop drag and drop operation.
contentmaster.MainWindow.prototype.onMouseUp = function(sender, mouseEventArgs) // release drag
{
    sender.getParent().opacity = 1;
    this.isMouseDown = false;
    // Allow all objects to receive mouse events.
    sender.releaseMouseCapture();
}

contentmaster.MainWindow.prototype.getActiveHighlight = function(object, state)
{
    var brushString = '';

    if (state == "off"){ // NEW STYLE
        brushString += '<LinearGradientBrush EndPoint="0.5,0.012" StartPoint="0.5,0.995">';
        brushString += '<GradientStop Color="#FFBDBDBD" Offset="1"/>';
        brushString += '<GradientStop Color="#FFD3D4D5" Offset="1"/>';
        brushString += '<GradientStop Color="#FFCFCFCF" Offset="0"/>';
        brushString += '<GradientStop Color="#FFF4F4F4" Offset="0.942"/>';
        brushString += '</LinearGradientBrush>';
    }
    else if (state == "on"){ // NEW STYLE
        brushString += '<LinearGradientBrush EndPoint="0.5,0.012" StartPoint="0.5,0.995">';
        brushString += '<GradientStop Color="#FFBDBDBD" Offset="1"/>';
        brushString += '<GradientStop Color="#FFFFFFFF" Offset="1"/>';
        brushString += '<GradientStop Color="#FFCFCFCF" Offset="0"/>';
        brushString += '<GradientStop Color="#FFF4F4F4" Offset="0.942"/>';
        brushString += '</LinearGradientBrush>';
    }

    return this.control.content.createFromXaml(brushString);
}


contentmaster.MainWindow.prototype.confBC = function()
{
    var oldString = "";
    var textToChange = null;

    if (this.sceneClass.history == 0){
        this.breadCrumbs.arrow.Visibility = "Collapsed";
        this.breadCrumbs.topXaml.Visibility = "Collapsed";
    }
    if (this.layoutType != "splash"){
        this.breadCrumbs.modTitle = this.sceneClass.xmlRoot.childNodes[this.sceneClass.moduleRoute].childNodes[0].childNodes[0].nodeValue;
        this.breadCrumbs.modXaml.children.getItem(1).Text = this.breadCrumbs.modTitle;
        this.breadCrumbs.modPath = this.sceneClass.xmlRoot.childNodes[this.sceneClass.moduleRoute];
        
        oldString = this.breadCrumbs.modTitle;
        textToChange = this.breadCrumbs.modXaml.children.getItem(1);
        
        for (var l=0; l<this.breadCrumbs.modTitle.length; l++){
            if (this.breadCrumbs.modXaml.children.getItem(1).actualWidth <= this.breadCrumbs.modXaml.children.getItem(0).Width - 12){
                break;
            }
            else {
                checkLengthConcat(this.breadCrumbs.modXaml.children.getItem(1), l);
            }
        }
    }
    
    if (this.layoutType == "splash"){
        this.breadCrumbs.modTitle = "Introduction";
        this.breadCrumbs.modXaml.children.getItem(1).Text = this.breadCrumbs.modTitle;
        this.breadCrumbs.modPath = this.sceneClass.xmlRoot;
        }
    
    if (this.sceneClass.history > 0){
        this.breadCrumbs.arrow.Visibility = "Visible";
        this.breadCrumbs.topXaml.Visibility = "Visible";
        this.breadCrumbs.topTitle = this.xamlObject.children.getItem(2).Text;
        this.breadCrumbs.topXaml.children.getItem(1).Text = this.breadCrumbs.topTitle;
        oldString = this.breadCrumbs.topTitle;
        textToChange = this.breadCrumbs.topXaml.children.getItem(1);
        
        for (var k=0; k<this.breadCrumbs.topTitle.length; k++){
            if (this.breadCrumbs.topXaml.children.getItem(1).actualWidth <= this.breadCrumbs.topXaml.children.getItem(0).Width - 12){
                break;
            }
            else {
                checkLengthConcat(this.breadCrumbs.topXaml.children.getItem(1), k);
            }
        }
    }
    
    if (this.sceneClass.linearPlace.nodeName == "course") this.breadCrumbs.modXaml.children.getItem(1).Text = "Introduction";
    
    function checkLengthConcat(buttonText, index)
    {
        var clipAmount = 1;
        if (index>0) clipAmount = 4;
        var oldString = buttonText.Text;
        var newString = "";
        newString = oldString.slice(0, oldString.length-clipAmount);
        var addString = "...";
        buttonText.Text = newString.concat(addString);
    } 

}

contentmaster.MainWindow.prototype.clickBC = function(sender)
{
    if (this.sceneClass.menuType == "stack"){
    
        if (this.sceneClass.history > 0){
            this.sceneClass.linearPlace = this.sceneClass.linearPlace.parentNode.childNodes[2];

            if (this.breadCrumbs.modTitle == "Introduction") this.sceneClass.linearContent = "Content/courseintro.xml";
            else this.sceneClass.linearContent = this.breadCrumbs.modPath.childNodes[1].childNodes[0].nodeValue;
            if (this.sceneClass.MenuHistory[this.sceneClass.history-1].childNodes[0].nodeName == "module"){
                this.sceneClass.titleButton.titletext = "Introduction";
                this.sceneClass.titleButton.pageurl = this.sceneClass.MenuHistory[this.sceneClass.history-1].childNodes[1].childNodes[0].nodeValue;
            }
            this.sceneClass.lessonRoute = 0;
            this.sceneClass.topicRoute = 0;
            this.sceneClass.populateChildrenLinear(this.breadCrumbs.modPath);
            this.sceneClass.sendContentLinear(this.sceneClass.linearContent);
            var route = this.sceneClass.moduleRoute.toString().length == 1 ? "0"+this.sceneClass.moduleRoute : this.sceneClass.moduleRoute;
            var route2 = this.sceneClass.topicRoute.toString().length == 1 ? "0"+this.sceneClass.topicRoute : this.sceneClass.topicRoute;
            if (sender.findName("button_main"+route+"_click")) sender.findName("button_main00_click").Begin();
            if (this.sceneClass.activeTreeTopicButton) sender.findName(this.sceneClass.activeTreeTopicButton+"_leave").Begin();
            if (sender.findName("button_main"+route2)) sender.findName("button_main"+route2+"_leave").Begin();
        }
    
    }
    else if (this.sceneClass.menuType == "tree"){
            this.sceneClass.linearPlace = this.breadCrumbs.modPath;
            this.sceneClass.topicRoute = 0;
            this.sceneClass.lessonRoute = 0;
            if (this.sceneClass.activeTreeTopicButton) sender.findName(this.sceneClass.activeTreeTopicButton+"_leave").Begin();
            var route = this.sceneClass.moduleRoute.toString().length == 1 ? "0"+this.sceneClass.moduleRoute : this.sceneClass.moduleRoute;
            this.sceneClass.activeTreeTopicButton = sender.findName("button_main"+route).Name;
            this.sceneClass.MenuHistory.splice(0,this.sceneClass.MenuHistory.length);
            if (this.breadCrumbs.modTitle == "Introduction") this.sceneClass.linearContent = "Content/courseintro.xml";
            else this.sceneClass.linearContent = this.breadCrumbs.modPath.childNodes[1].childNodes[0].nodeValue;
            this.sceneClass.sendContentLinear(this.sceneClass.linearContent);
            this.sceneClass.MenuHistory[0] = this.sceneClass.xmlRoot;
    }
}

contentmaster.MainWindow.prototype.hoverMod = function(sender)
{
    if (this.sceneClass.history > 0) sender.children.getItem(0).Fill = "Crimson";
}

contentmaster.MainWindow.prototype.hoverTop = function(sender)
{
    sender.children.getItem(0).Fill = "PowderBlue";
}

contentmaster.MainWindow.prototype.hoverLeave = function(sender)
{
    sender.children.getItem(0).Fill = "LightGray";
}

contentmaster.MainWindow.prototype.html_enter = function(sender)
{
    sender.children.getItem(0).Fill = "#FFD3DDF2";
    sender.children.getItem(1).children.getItem(0).Stroke = "#FF32415F";
    sender.children.getItem(1).children.getItem(1).Stroke = "#FF32415F";
    sender.children.getItem(1).children.getItem(2).Fill = "#FF32415F";
    this.sceneClass.toolTip.infoText = "Accessible & printer friendly version";
    this.sceneClass.toolTip_enter(sender);
}

contentmaster.MainWindow.prototype.html_leave = function(sender)
{
    sender.children.getItem(0).Fill = "#FFF0F0F0";
    sender.children.getItem(1).children.getItem(0).Stroke = "#FFB4B4B4";
    sender.children.getItem(1).children.getItem(1).Stroke = "#FFB4B4B4";
    sender.children.getItem(1).children.getItem(2).Fill = "#FFB4B4B4";
    this.sceneClass.toolTip_leave(sender);
}

contentmaster.MainWindow.prototype.controls_close_enter = function(sender)
{
    this.xamlObject.children.getItem(4).children.getItem(0).children.getItem(0).fill = this.controls_getColor("red");
}

contentmaster.MainWindow.prototype.controls_rest_enter = function(sender)
{
    this.xamlObject.children.getItem(4).children.getItem(1).children.getItem(0).fill = this.controls_getColor("blue");
}

contentmaster.MainWindow.prototype.controls_min_enter = function(sender)
{
    this.xamlObject.children.getItem(4).children.getItem(2).children.getItem(0).fill = this.controls_getColor("blue");
}

contentmaster.MainWindow.prototype.controls_close_leave = function(sender)
{
    this.xamlObject.children.getItem(4).children.getItem(0).children.getItem(0).fill = this.controls_getColor("gray");
}

contentmaster.MainWindow.prototype.controls_rest_leave = function(sender)
{
    this.xamlObject.children.getItem(4).children.getItem(1).children.getItem(0).fill = this.controls_getColor("gray");
}

contentmaster.MainWindow.prototype.controls_min_leave = function(sender)
{
    this.xamlObject.children.getItem(4).children.getItem(2).children.getItem(0).fill = this.controls_getColor("gray");
}

contentmaster.MainWindow.prototype.controls_getColor = function(setColor)
{
    var xamlFragment = "";
    var control = document.getElementById("silverlightControl1");
    if (setColor == "blue"){
    xamlFragment += '<LinearGradientBrush StartPoint="0.499981,0.0151515" EndPoint="0.499981,0.984848">';
    xamlFragment += '<LinearGradientBrush.GradientStops>';
    xamlFragment += '<GradientStop Color="#FF12273E" Offset="0"/>';
    xamlFragment += '<GradientStop Color="#FF70A3D1" Offset="0.400002"/>';
    xamlFragment += '<GradientStop Color="#FF88BAE9" Offset="1"/>';
    xamlFragment += '</LinearGradientBrush.GradientStops>';
    xamlFragment += '</LinearGradientBrush>';                 
    }
    else if (setColor == "gray"){
    xamlFragment += '<LinearGradientBrush StartPoint="0.499981,0.0151515" EndPoint="0.499981,0.984848">';
    xamlFragment += '<LinearGradientBrush.GradientStops>';
    xamlFragment += '<GradientStop Color="#FF231F20" Offset="0"/>';
    xamlFragment += '<GradientStop Color="#FF666666" Offset="0.400002"/>';
    xamlFragment += '<GradientStop Color="#FFAAAAAA" Offset="1"/>';
    xamlFragment += '</LinearGradientBrush.GradientStops>';
    xamlFragment += '</LinearGradientBrush>';                 
    }
    else if (setColor == "red"){
    xamlFragment += '<LinearGradientBrush StartPoint="0.499981,0.0151515" EndPoint="0.499981,0.984848">';
    xamlFragment += '<LinearGradientBrush.GradientStops>';
    xamlFragment += '<GradientStop Color="#FF300A0A" Offset="0"/>';
    xamlFragment += '<GradientStop Color="#FF943F3F" Offset="0.400002"/>';
    xamlFragment += '<GradientStop Color="#FFE97F7F" Offset="1"/>';
    xamlFragment += '</LinearGradientBrush.GradientStops>';
    xamlFragment += '</LinearGradientBrush>';                 
    }
    
    return control.content.createFromXaml(xamlFragment);

}


contentmaster.MainWindow.prototype.adjustSize = function(new_width, new_height)
{
    var mainShape = this.xamlObject.children.getItem(0);
    var mainShapeC = this.xamlObject.children;
    var defaultHeight = 490; //590
    var defaultWidth = 580; //670
    
    var maxedWidth = 680; //800
    var maxedHeight = 550; //600
    
    if ((mainShape.Width != maxedWidth)&&(mainShape.Height != maxedHeight)){
        mainShape.Width = maxedWidth;
        mainShape.Height = maxedHeight;
    }
    else if ((mainShape.Width == maxedWidth)&&(mainShape.Height == maxedHeight)){
        mainShape.Width = defaultWidth;
        mainShape.Height = defaultHeight;
    }
       
        var mainShapeH = mainShape.Height;
        var mainShapeW = mainShape.Width;
        
        var innerShape = mainShapeC.getItem(1);
        var titleBar = mainShapeC.getItem(2);
        var dragBar = mainShapeC.getItem(3);
        var winButtons = mainShapeC.getItem(4);
        var winControl_min = mainShapeC.getItem(5);
        var winControl_close = mainShapeC.getItem(6);
        var winControl_rest = mainShapeC.getItem(11);
        var resizeControl = mainShapeC.getItem(7);
        var textArea = mainShapeC.getItem(8);
        var bcLine = mainShapeC.getItem(10);
        var cmLogo = mainShapeC.getItem(12);
        var htmlBtn = mainShapeC.getItem(13);
        
        innerShape.Height = mainShapeH - 60;
        innerShape.Width = mainShapeW - 20;
        titleBar.Width = mainShapeW - 94;
        dragBar.Width = mainShapeW - 59;
        winButtons["Canvas.Left"] = mainShapeW - 97;
        winControl_min["Canvas.Left"] = mainShapeW - 96;
        winControl_rest["Canvas.Left"] = mainShapeW - 65;
        winControl_close["Canvas.Left"] = mainShapeW - 33;
        resizeControl["Canvas.Left"] = mainShapeW - 24;
        resizeControl["Canvas.Top"] = mainShapeH - 24;
        cmLogo["Canvas.Top"] = mainShapeH - 15;
        htmlBtn["Canvas.Left"] = mainShapeW - 61;
        
        var clipString = "0,20,"+(mainShapeW - 31)+","+(mainShapeH - 90);
        textArea.Clip.Rect = clipString;
        
        bcLine.X2 = mainShapeW - 10;
        
        //resposition page elements
        var contentObjects = textArea.children.getItem(0).children.getitem(0);
        var newPageHeight = this.resizeControl.arrangePage(this.layoutType, contentObjects);
    
    //}

}



///////////////////////////////////////////////////////////
//
// Main Window Utility Class
//
///////////////////////////////////////////////////////////
contentmaster.MainWindowUtils = function(control, sceneClass) 
{   
    this.totalWindowCount = 1;
    this.maxWindowCount = 4;
    this.taskBarItems = new Array(); // stores all elements in the task bar
    this.activeMainWindows = new Array(); // stores reference to all open main windows
    this.control = control; // reference activeX control
    var initialWindow = this.control.content.findName("mainWindowCanvas");
    var initialWindowTitle = initialWindow.children.getItem(2).Text;
    var initialWindowX = initialWindow["Canvas.Left"];
    var initialWindowY = initialWindow["Canvas.Top"];
    var initialSource = "Intro text here 123";
    this.sceneClass = sceneClass;
    this.windowNum = 0; //counter for unique window number

    this.addPrimaryEvents(initialWindow);
    
    // create new window instance and add to array
    this.activeMainWindows.push(new contentmaster.MainWindow(initialWindow, initialWindowTitle, initialWindowX, initialWindowY, initialSource, this.sceneClass, this.windowNum));
    this.windowNum++;
}

contentmaster.MainWindowUtils.prototype.minimizeWindow = function(sender)  // minimize a window
{   
    sender.getParent().Visibility = "Collapsed";
    var windowID = sender.getParent().children.getItem(2).Text;
    
    //find taskbar, create visual object and add to it
    var taskBar = sender.findName("taskBar");
    var xamlFragment = '<Canvas Width="150" Height="24" Canvas.Left="20" Canvas.Top="3" ><Rectangle Width="150" Height="24" RadiusX="6" RadiusY="6" Stroke="LightGray"><Rectangle.Fill><LinearGradientBrush StartPoint="0.529076,0.998838" EndPoint="0.529076,-0.00193658"><LinearGradientBrush.GradientStops><GradientStop Color="#FFFFFFFF" Offset="0"/><GradientStop Color="#FFEFF1EF" Offset="1"/></LinearGradientBrush.GradientStops></LinearGradientBrush></Rectangle.Fill></Rectangle><TextBlock Text="Minimized Window" Canvas.Left="6" Canvas.Top="5" FontFamily="Arial" FontSize="12" /></Canvas>';
    var newItem = this.control.content.createFromXaml(xamlFragment);
    taskBar.children.add(newItem);
    
    var windowName = sender.getParent().name;
    var windowPosition = sender.getParent()["Canvas.Left"];
    var arrayPosition = taskBar.children.count-1;
    var createdItem = taskBar.children.getItem(arrayPosition); //define newly created item
    createdItem.children.getItem(1).Text = windowID; //sets item text to window name
    if (createdItem.children.getItem(1).actualWidth > 140){
        var oldString = createdItem.children.getItem(1).Text;
        var newString = oldString.slice(0, 21);
        var addString = "...";
        var combString = newString.concat(addString);
        createdItem.children.getItem(1).Text = combString;
        }
    createdItem.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.maximizeWindow));
    createdItem.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.barItem_enter));
    createdItem.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.barItem_leave));
    createdItem.Cursor = "Hand";
    
    var windowReference = { // creates new object with window's text name and window's XAML x:Name reference
        //window: oldString,
        newID: windowID,
        //windowname: windowName,
        winXaml: sender.getParent(),
        taskXaml: createdItem
        //position: windowPosition
    }
    
    this.taskBarItems.push(windowReference); //push object onto end of items array
    this.posElement(createdItem, arrayPosition);   
}

contentmaster.MainWindowUtils.prototype.posElement = function(item, arrayPosition)
{
    item["Canvas.Left"] = (item.width+10)*(arrayPosition);
}


contentmaster.MainWindowUtils.prototype.maximizeWindow = function(sender) // maximize a window
{
   var taskBar = sender.findName("taskBar");
   var windows = sender.findName("windows");
   
   this.sceneClass.toolTip_leave(sender);
   

   
   for (j=0; j<this.taskBarItems.length; j++){
        if (sender["Canvas.Left"] == this.taskBarItems[j].taskXaml["Canvas.Left"]){
            this.taskBarItems[j].winXaml.Visibility = "Visible";
            this.taskBarItems[j].winXaml["Canvas.Left"] += 1;
			this.taskBarItems[j].winXaml["Canvas.Left"] -= 1;
			
            taskBar.children.removeAt(j);
            this.taskBarItems.splice(j, 1);
        }
    }

    // re-arrange task bar
    for (k=0; k<this.taskBarItems.length; k++){
        var itemToArrange = taskBar.children.getItem(k);
        this.posElement(itemToArrange, k);
    }

    
}
  
contentmaster.MainWindowUtils.prototype.barItem_enter = function(sender, args)
{
    sender.children.getItem(0).Stroke = "Gray";
    for (var j=0; j<this.taskBarItems.length; j++){
        if (sender["Canvas.Left"] == this.taskBarItems[j].taskXaml["Canvas.Left"]){
            this.sceneClass.toolTip.infoText = this.taskBarItems[j].newID;
            this.sceneClass.toolTip_enter(sender, args);
        }
    }
}

contentmaster.MainWindowUtils.prototype.barItem_leave = function(sender)
{
    sender.children.getItem(0).Stroke = "LightGray";
    this.sceneClass.toolTip_leave(sender);
}


contentmaster.MainWindowUtils.prototype.closeWindow = function(sender) // close a window
{
   var root = sender.findName("windows");
   var winName = sender.getParent().Name;
   var winXaml = sender.getParent();
   root.children.remove(winXaml);
   this.removeWindow(winName);
}

contentmaster.MainWindowUtils.prototype.removeWindow = function(winName) // remove window instance from array
{
    for (i=0; i<this.activeMainWindows.length; i++){
          if (this.activeMainWindows[i].xamlObject.Name == winName){
                this.activeMainWindows.splice(i, 1);
                this.totalWindowCount--;
                if (this.sceneClass.hotWindow != null && this.sceneClass.hotWindow.Name == winName)
                {
					this.sceneClass.hotWindow = null;
                }
          }
    }
}


contentmaster.MainWindowUtils.prototype.createMainWindow = function(sender)  // creates new window from XAML
{
	if (this.totalWindowCount < this.maxWindowCount)
	{
		this.totalWindowCount++;
		DownloadItem(this.control, "mainWindow.xaml", Silverlight.createDelegate(this, this.onCompleted ));
		return true;
	}
	return false;
}

contentmaster.MainWindowUtils.prototype.handleParseError = function(line, col, hr, string)
{
	alert(string + " at: " + line + ", " + col);
}

contentmaster.MainWindowUtils.prototype.onCompleted = function(sender, eventArgs)
{
  var control = document.getElementById("silverlightControl1");
  var downloadedXaml = ""
	if (IS_USING_DOWNLOADER)
	{
		downloadedXaml = sender.responseText;
	}
	else
	{
		downloadedXaml = sender; 
	}
  var updatedXaml = downloadedXaml.replaceName("$num", this.windowNum);
  var xamlFragment = control.content.createFromXaml(updatedXaml); 
	
  
  // Add the XAML object as a child of the 'windows' Canvas object.
  var windows = control.content.findName("windows");
  windows.children.add(xamlFragment);
  var newItemIndex = windows.children.count-1;
  var newWindow = windows.children.getItem(newItemIndex); //get last item (newest)
  var newTitle = "New Window ("+this.totalWindowCount+")";
  var newSrc = "Congratulations, you have just created a spiffing new window. Horrah.";

  this.activeMainWindows.push(new contentmaster.MainWindow(newWindow, newTitle, "315", "10", newSrc, this.sceneClass, this.windowNum));
  this.windowNum++;

  this.addPrimaryEvents(newWindow); // add main event handlers

    ////////////////set zindex top//////////////////////////
    var windows = control.content.findName("windows");
    var zindex = 0;
    for (i=0; i<windows.children.count; i++){
        if (windows.children.getItem(i)["Canvas.ZIndex"] > zindex){
        zindex = windows.children.getItem(i)["Canvas.ZIndex"];
        }else{
        continue;
        }  
    }
    newWindow["Canvas.ZIndex"] = (zindex+1);
    /////////////////////////////////////////////////////////
    for (k=0; k<windows.children.count; k++){
        if (k == windows.children.count-1){
            continue;
            }
        else if (windows.children.getItem(k)["Canvas.Left"] == newWindow["Canvas.Left"]){
            newWindow["Canvas.Left"] = windows.children.getItem(k)["Canvas.Left"] + 10;
            newWindow["Canvas.Top"] = windows.children.getItem(k)["Canvas.Top"] + 10;
        }else{
        continue;
        }  
    }
    
  this.setActiveWindow(this.pageArray, this.pageLayout, this.contentURL);
    
}

contentmaster.MainWindowUtils.prototype.addPrimaryEvents = function(object) // adds main events to window
{
    var minimizeButton = object.children.getItem(5);
    minimizeButton.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.minimizeWindow));
    var closeButton = object.children.getItem(6);
    closeButton.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.closeWindow));
}



contentmaster.MainWindowUtils.prototype.loadPageXML = function(url, type) // loads XML for page content (page url, type of window ("default", "new"))
{   

	if (!window.Temp_Loading_Xml_Check)
	{
		window.Temp_Loading_Xml_Check = true;
		window.Temp_Loading_Xml_Next_Storage = null;
	}
	else
	{
		window.Temp_Loading_Xml_Next_Storage = {Url:url, Type: type};
		return;
	}
   
    var pageArray = new Array();
    var pageLayout;
	
    var pageDoc = XML_LoadXml(url);


	
    var htmlPage;

	//function sortPageXML(pageDoc){   
        var pageRoot = pageDoc.documentElement;       
        for (i=0; i<pageRoot.childNodes.length; i++){
            pageArray[i] = pageRoot.childNodes[i];
        }
        pageLayout = pageRoot.attributes.getNamedItem("layoutstyle").nodeValue;
        htmlPage = pageRoot.attributes.getNamedItem("plainText") ? pageRoot.attributes.getNamedItem("plainText").nodeValue : "index.html"; 
    //}
    this.htmlPage = htmlPage;
    // if current/existing window
    
    var openCheck = this.checkForOpen(url); // see if window is open with this content
    
    if (openCheck == false){
        if ((type == "default")||(!type)){
            this.setActiveWindow(pageArray, pageLayout, url); //finds active window, sends content
        }
        // if open new window
        if (type == "new"){
            this.pageArray = pageArray;
            this.pageLayout = pageLayout;
            this.contentURL = url;
            if (!this.createMainWindow())
            {
				if (!this.setActiveWindow(pageArray, pageLayout, url)) //finds active window, sends content
				{
					var taskBarItem = document.getElementById("silverlightControl1").content.findName("taskBar").children.getItem(0);
					this.maximizeWindow(taskBarItem);
					this.setActiveWindow(pageArray, pageLayout, url);
				}
            }
        }
    }
    
    //pause(1000);
    
    window.Temp_Loading_Xml_Check = false;
    if (window.Temp_Loading_Xml_Next_Storage != null)
    {
		this.loadPageXML(window.Temp_Loading_Xml_Next_Storage.Url, window.Temp_Loading_Xml_Next_Storage.Type);
		return;
    }
}

contentmaster.MainWindowUtils.prototype.checkForOpen = function(contentURL)
{
    var windowArray = this.activeMainWindows;
    
    for (var l=0; l<windowArray.length; l++){
        var windowTitle = windowArray[l].xamlObject.children.getItem(2).Text;
        if ((windowTitle.substring(0,13) == "Demonstration")||(windowTitle.substring(0,9) == "Animation")) continue;
        else if (windowArray[l].contentURL == contentURL){
            //match
            var match = windowArray[l];
            if (windowArray[l].xamlObject.Visibility == "Collapsed"){ // if minimized, maximize and arrange task bar
                // unhide
                
                var taskBar = this.control.content.findName("taskBar");
                var windows = this.control.content.findName("windows");
                
                for (var j=0; j<this.taskBarItems.length; j++){
                    var windowName = this.taskBarItems[j].winXaml.Name;
                    if (windowName == match.xamlObject.Name){
                        this.taskBarItems[j].winXaml.Visibility = "Visible";
                        taskBar.children.removeAt(j);
                        this.taskBarItems.splice(j, 1);
                        break;
                    }
                }
                for (var k=0; k<this.taskBarItems.length; k++){
                    var itemToArrange = taskBar.children.getItem(k);
                    this.posElement(itemToArrange, k);
                }
            }
            var index = 0;
            for (var m=0; m<windowArray.length; m++){               // bring window to front
                if (windowArray[m].xamlObject["Canvas.ZIndex"] > index){
                    index = windowArray[m].xamlObject["Canvas.ZIndex"];
                }
            }
            if (match.xamlObject["Canvas.ZIndex"] < index){
                    match.xamlObject["Canvas.ZIndex"] = index + 1;
            }
            
            if (this.sceneClass.hotWindow) this.sceneClass.hotWindow.children.getItem(0).Fill = windowArray[windowArray.length-1].getActiveHighlight(match.xamlObject, "off");
            match.xamlObject.children.getItem(0).Fill = windowArray[windowArray.length-1].getActiveHighlight(match.xamlObject, "on");
            this.sceneClass.hotWindow = match.xamlObject;
            
            return true;

        }else{
            continue;
        }
      }
      return false;
}

contentmaster.MainWindowUtils.prototype.setActiveWindow = function(content, layout, contentURL)
{ // when button clicked, find active window, loop through array to find window instance, apply content
    
    var windows = this.control.content.findName("windows");
    var zindex = 0;
    var activeWindow = null;
    for (var i=0; i<windows.children.count; i++)
    {
        if (windows.children.getItem(i)["Canvas.ZIndex"] > zindex)
        {
            var windowTitle = windows.children.getItem(i).children.getItem(2).Text;
            if (windowTitle == "Navigation") continue; //if nav window, skip
            if ((windowTitle.substring(0,13) == "Demonstration")||(windowTitle.substring(0,9) == "Animation")) continue; // if ani/demo, skip
            if (windows.children.getItem(i).Visibility == "Collapsed") continue; // if not visible (minimized), skip
            zindex = windows.children.getItem(i)["Canvas.ZIndex"];
            activeWindow = windows.children.getItem(i);
        }
    }
    
    if (activeWindow == null) return false;
    
    var windowArray = this.activeMainWindows;
    
    for (var l = 0; l < windowArray.length; l++)
    {
        if (windowArray[l].xamlObject.Name == activeWindow.Name)
        {
                this.defineContent(layout, content, windowArray[l]);
                windowArray[l].contentURL = contentURL;
                windowArray[l].layoutType = layout;
        }
        else
        {
			continue;
        }
    }
       
    if (this.sceneClass.hotWindow)
    {	
		this.sceneClass.hotWindow.children.getItem(0).Fill = windowArray[windowArray.length-1].getActiveHighlight(activeWindow, "off");
    }
    if (activeWindow != null)
    {
		activeWindow.children.getItem(0).Fill = windowArray[windowArray.length-1].getActiveHighlight(activeWindow, "on");
		this.sceneClass.hotWindow = activeWindow;
	}
	
	return true;
}


contentmaster.MainWindowUtils.prototype.defineContent = function(layout, content, windowArray) // adds content to page; defines layout structure and adds in required page elements
{ 
    var contentArray = content; //array of page elements from XML
    //var targetWindow = target; // target window
    var targetWindow = windowArray.xamlObject;
    var target = windowArray.xamlObject;
    var layoutStyle = layout;
    var contentArea = targetWindow.children.getItem(8).children.getItem(0);
    contentArea["Canvas.Top"] = 0;
    contentArea["Canvas.Left"] = 0;
    if (contentArea.children) contentArea.children.clear();
    
    windowArray.htmlPage = this.htmlPage;

    function defineLayout(layoutStyle)
    {
        if (layoutStyle == "layout01"){
            return '<Canvas><Canvas Canvas.Top="46" Canvas.Left="140"></Canvas><Canvas Canvas.Top="30" Canvas.Left="15"></Canvas><Canvas Canvas.Left="140" Canvas.Top="90"></Canvas><Canvas Canvas.Left="140" Canvas.Top="130"></Canvas></Canvas>';
            // Title, Image, Element, Element
        }    
        else if (layoutStyle == "layout02"){
            return '<Canvas><Canvas Canvas.Top="46" Canvas.Left="15"></Canvas><Canvas Canvas.Left="15" Canvas.Top="90"></Canvas><Canvas Canvas.Left="15" Canvas.Top="130"></Canvas></Canvas>';
            // Title, Text, Media
        }
        else if (layoutStyle == "layout03"){
            return '<Canvas><Canvas Canvas.Top="46" Canvas.Left="140"></Canvas><Canvas Canvas.Top="30" Canvas.Left="15"></Canvas><Canvas Canvas.Left="140" Canvas.Top="90"></Canvas><Canvas Canvas.Left="140" Canvas.Top="130"></Canvas><Canvas Canvas.Left="140" Canvas.Top="170"></Canvas></Canvas>';
            // Title, Image, Element, Element, Element
        }
        else if (layoutStyle == "layout04"){
            return '<Canvas><Canvas Canvas.Top="46" Canvas.Left="15"></Canvas><Canvas Canvas.Left="15" Canvas.Top="90"></Canvas><Canvas Canvas.Left="15" Canvas.Top="130"></Canvas><Canvas Canvas.Left="15"></Canvas><Canvas Canvas.Left="15"></Canvas></Canvas>';
            // Title, Element, Element, Element
        }
        else if (layoutStyle == "layout05"){
            return '<Canvas><Canvas Canvas.Top="7" Canvas.Left="0"></Canvas><Canvas Canvas.Left="0" Canvas.Top="90"></Canvas><Canvas Canvas.Left="15" Canvas.Top="130"></Canvas></Canvas>';
            // Title, Element, Element, Element, Element
        }
        else if (layoutStyle == "splash"){
            return '<Canvas><Canvas Canvas.Top="20" Canvas.Left="-5"><MediaElement Source="Media/Splash_new.wmv" Width="650" Height="520"/></Canvas><Canvas Canvas.Top="170" Canvas.Left="60"><Rectangle Width="500" Height="290" Fill="White" Opacity="0.6" RadiusX="4" RadiusY="4" /><TextBlock Canvas.Left="10" Canvas.Top="50" Width="460" FontFamily="Arial" FontSize="12" Text="Content" TextWrapping="Wrap" /><TextBlock Canvas.Left="10" Canvas.Top="16" Width="460" FontFamily="Arial" FontSize="16" Text="Welcome" TextWrapping="Wrap" /><Rectangle Canvas.Left="582" Canvas.Top="-180" Width="4" Height="544" Fill="White" /></Canvas></Canvas>';
            // Splash page
        }
        else{
            alert("Error: No layout style found");
            return false;
        }
    }

    var layoutStructure = defineLayout(layoutStyle);
    var layoutXaml = this.control.content.CreateFromXaml(layoutStructure);
    contentArea.children.add(layoutXaml);
    
    var sizeShape = target.children.getItem(1);
    
    this.mainHolderHeight = 0;
    
    windowArray.contentTypes = null;
    windowArray.contentTypes = new Array();
        
    //loop through array to add content elements depending on type
    for (i=0; i<contentArray.length; i++){
       this.heightCount = 0;
       try
       {
        var elementType = contentArray[i].attributes.getNamedItem("type").nodeValue;
       }
       catch(e)
       {
        alert("Type error: "+e.description);
       }
       windowArray.contentTypes.push(elementType);

       var contentElements = contentArea.children.getItem(0).children.getItem(i).children;

       var parentHolder = contentArea.children.getItem(0).children.getItem(i);
       var lineSpace = 10;       
           if (elementType == "splash"){
           //var splash = defineElement(elementType, contentElements);
           var splashMedia = contentArea.children.getItem(0).children.getItem(0).children.getItem(0);
           var splashText = contentArea.children.getItem(0).children.getItem(1).children.getItem(1);
           splashText.Text = contentArray[i].childNodes[0].childNodes[0].childNodes[0].nodeValue;
           splashMedia.addEventListener("MediaEnded", Silverlight.createDelegate(this, this.loop_Splash));
           }
       
       
           if ((elementType == "rollover")||(elementType == "rolloverLarge")||(elementType == "rolloverMedium")){
           var rolloverInfo = contentArray[i];
           var rolloverContent = rolloverInfo.childNodes[1];
           var rolloverXAML = rolloverInfo.childNodes[0].childNodes[0].nodeValue;
           var mediaElement = new contentmaster.rollover(rolloverXAML, rolloverContent, contentElements, target, i, windowArray);
           }
           
           if (elementType == "clicktable"){
           var clickInfo = contentArray[i];
           var clickContent = clickInfo.childNodes;
           var clickElement = new contentmaster.clickTable(clickContent, contentElements, target, "click", windowArray);
           }
           
           if (elementType == "explorer"){
           var expSrc = contentArray[i].childNodes[0].childNodes[0].nodeValue;
           var expElement = new contentmaster.explorer(expSrc, contentArray[i], contentElements);
           }
           
           if (elementType == "anigram"){
           var agSrc = contentArray[i].childNodes[0].childNodes[0].nodeValue;
           var agElement = new contentmaster.anigram(agSrc, contentElements);
           }
           
           if (elementType == "table"){
           var tableSrc = contentArray[i].childNodes[0].childNodes[0].nodeValue;
           var tableElement = new contentmaster.infoTable(contentElements, tableSrc);
           }
           
           if (elementType == "tabtable_new"){
           var clickInfo = contentArray[i];
           var header1 = clickInfo.attributes.getNamedItem("header1").nodeValue;
           var header2 = clickInfo.attributes.getNamedItem("header2").nodeValue;
           var header3 = null;
           if (clickInfo.attributes.getNamedItem("header3")) header3 = clickInfo.attributes.getNamedItem("header3").nodeValue;
           var clickContent = clickInfo.childNodes;
           var clickElement = new contentmaster.tabTable(clickContent, contentElements, target, windowArray, header1, header2, header3);
           }
           
           if (elementType == "tabtable"){
           var clickInfo = contentArray[i];
           var clickContent = clickInfo.childNodes;
           var clickElement = new contentmaster.clickTable(clickContent, contentElements, target, "tab", windowArray);
           }
           
           if (elementType == "selftest"){
           var testInfo = contentArray[i];
           var testElement = new contentmaster.selfTest(testInfo, contentElements, target, windowArray);
           }
           
           if (elementType == "textcomplex"){
                for (j=0; j<contentArray[i].childNodes[0].childNodes.length; j++){
                  // add content
                  var complexType = contentArray[i].childNodes[0].childNodes[j].nodeName;
                  if (complexType == "list"){
                    var holder = defineElement(complexType, contentElements);
                    var numberCount = 1; //for numbered list
                        for (k=0; k<contentArray[i].childNodes[0].childNodes[j].childNodes.length; k++){
                            var bulletNode = contentArray[i].childNodes[0].childNodes[j].childNodes[k].nodeName;
                            var bulletItem = defineElement(bulletNode, holder.children);
                            bulletItem.children.getItem(1).Text = contentArray[i].childNodes[0].childNodes[j].childNodes[k].childNodes[0].nodeValue;
                            bulletItem.children.getItem(1).Width = sizeShape.Width - 170;
                            if (bulletNode == "number"){
                                bulletItem.children.getItem(0).Text = numberCount+"."; // numberCount was (k+1)
                                numberCount++;
                                }
                        }
                    }
                    else if (complexType == "paraLink1"){
                        var paraEl = defineElement(complexType, contentElements);
                        paraEl.Text = contentArray[i].childNodes[0].childNodes[j].childNodes[0].nodeValue;
                        paraEl.Width = sizeShape.Width - 170;
                        paraEl.Foreground = "MediumBlue";
                        paraEl.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.open_link1));
                        paraEl.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.fwdLink_enter));
                        paraEl.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.fwdLink_leave));
                        paraEl.Cursor = "Hand";
                    }
                  else{ // if == "para"
                    var paraEl = defineElement(complexType, contentElements);
                    paraEl.Text = contentArray[i].childNodes[0].childNodes[j].childNodes[0].nodeValue;
                    paraEl.Width = sizeShape.Width - 170;
                    }
                  
                }
           }
               
           if ((elementType == "image")||(elementType == "imagelarge")){
           var image = defineElement(elementType, contentElements);
           image.Source = contentArray[i].childNodes[0].childNodes[0].nodeValue;
           }
           
           if (elementType == "imagelarge2"){
           var image = defineElement(elementType, contentElements);
           image.children.getItem(2).Source = contentArray[i].childNodes[0].childNodes[0].nodeValue;
           image.children.getItem(3).Text = contentArray[i].childNodes[1].childNodes[0].nodeValue;
           }
           if (elementType == "imagelarge3"){
           var image = defineElement("imagelarge2", contentElements);
           var heightAdjust = 200;
           image.children.getItem(0).children.getItem(0).Height -= heightAdjust;
           image.children.getItem(0).children.getItem(1).Height -= heightAdjust;
           image.children.getItem(2).Height -= heightAdjust;
           image.children.getItem(1)["Canvas.Top"] -= heightAdjust;
           image.children.getItem(3)["Canvas.Top"] -= heightAdjust;
           image.children.getItem(2).Source = contentArray[i].childNodes[0].childNodes[0].nodeValue;
           image.children.getItem(3).Text = contentArray[i].childNodes[1].childNodes[0].nodeValue;
           }
           
           if (elementType == "lablink"){
           var link = defineElement(elementType, contentElements);
           this.labLink = contentArray[i].childNodes[0].childNodes[0].nodeValue;
           link.Cursor = "Hand";
           link.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.open_labLink));
           link.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.labLink_enter));
           link.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.labLink_leave));
			target.children.getItem(13).Visibility = "Collapsed";
           }
           else
           {
	           target.children.getItem(13).Visibility = "Visible";
           }
           
           if ((elementType == "text")||(elementType == "title")){
           var textBlock = defineElement(elementType, contentElements);
           textBlock.Text = contentArray[i].childNodes[0].nodeValue;
           textBlock.Width = sizeShape.Width - 170;
           }
           
           if (elementType == "animation")
           {
			   var tempElement = defineElement(elementType, contentElements);
			   this.launchHolder = contentElements.getItem(0);
			   var demoImage = this.getLaunchImage(elementType);
			   contentElements.getItem(0).addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.launchDemo));
			   contentElements.getItem(0).addEventListener("MouseEnter", Silverlight.createDelegate(this, this.anim_enter));
			   contentElements.getItem(0).addEventListener("MouseLeave", Silverlight.createDelegate(this, this.anim_leave));
			   this.demoURL = contentArray[i].childNodes[0].childNodes[0].nodeValue;
			   if (contentArray[i].childNodes[1]) this.demoTrans = contentArray[i].childNodes[1].childNodes[0].nodeValue;
			   if (!contentArray[i].childNodes[1]) this.demoTrans = null;
			   this.demoTitle = "Animation: "+contentArray[0].childNodes[0].nodeValue;
			   this.demoType = "animation";
			   contentElements.getItem(0).Cursor = "Hand";
	           
			   if (window.Temp_Video_Button_Storage == null)
			   {
					window.Temp_Video_Button_Storage = new Array();
			   }
			   var indexToUse = window.Temp_Video_Button_Storage.length;
			   for (var k = 0; k <  window.Temp_Video_Button_Storage.length; k++)
			   {
					if (window.Temp_Video_Button_Storage[k].Id == tempElement)
					{
						indexToUse = k;
						break;
					}
					
			   }
			   //setup a unique width so we can recognise this element again
			   if (window.Temp_Unique_Width == null) window.Temp_Unique_Width = 0;
			   window.Temp_Unique_Width ++;
			   tempElement.Width=window.Temp_Unique_Width;
			   
			   window.Temp_Video_Button_Storage[indexToUse] = {Id:tempElement.Width, Url:this.demoURL, Title:this.demoTitle, Trans:this.demoTrans, Type:this.demoType};
           }
           
           if (elementType == "demo")
           {
			   var tempElement = defineElement(elementType, contentElements);
			   this.launchHolder = contentElements.getItem(0);
			   var demoImage = this.getLaunchImage(elementType);

			   contentElements.getItem(0).addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.launchDemo));
			   contentElements.getItem(0).addEventListener("MouseEnter", Silverlight.createDelegate(this, this.demo_enter));
			   contentElements.getItem(0).addEventListener("MouseLeave", Silverlight.createDelegate(this, this.demo_leave));
			   this.demoURL = contentArray[i].childNodes[0].childNodes[0].nodeValue;
			   if (contentArray[i].childNodes[1]) this.demoTrans = contentArray[i].childNodes[1].childNodes[0].nodeValue;
			   if (!contentArray[i].childNodes[1]) this.demoTrans = null;
			   this.demoTitle = "Demonstration: "+contentArray[0].childNodes[0].nodeValue;
			   this.demoType = "demo";
			   contentElements.getItem(0).Cursor = "Hand";
			   
			   if (window.Temp_Video_Button_Storage == null)
			   {
					window.Temp_Video_Button_Storage = new Array();
			   }
			   var indexToUse = window.Temp_Video_Button_Storage.length;
			   for (var k = 0; k <  window.Temp_Video_Button_Storage.length; k++)
			   {
					if (window.Temp_Video_Button_Storage[k].Id == tempElement)
					{
						indexToUse = k;
						break;
					}
					
			   }
			   //setup a unique width so we can recognise this element again
			   if (window.Temp_Unique_Width == null) window.Temp_Unique_Width = 0;
			   window.Temp_Unique_Width ++;
			   tempElement.Width=window.Temp_Unique_Width;

			   window.Temp_Video_Button_Storage[indexToUse] = {Id:tempElement.Width, Url:this.demoURL, Title:this.demoTitle, Trans:this.demoTrans, Type:this.demoType};			   
           } 
    }
    
    var contentObjects = target.children.getItem(8).children.getItem(0).children.getitem(0);
    windowArray.resizeControl.arrangePage(layoutStyle, contentObjects); // send page contents to be arranged
    
    function applyTitle() // adds title to titlebar
    {

        if (layout == "splash"){
            target.children.getItem(2).Text = "Introduction";
            windowArray.title = "Introduction";
        }
        else
        {
            target.children.getItem(2).Text = contentObjects.children.getItem(0).children.getItem(0).Text;
            windowArray.title = contentObjects.children.getItem(0).children.getItem(0).Text;
        }
    }
    
    applyTitle();
    windowArray.confBC();
}

contentmaster.MainWindowUtils.prototype.open_link1 = function(sender)
{
    window.open('http://go.microsoft.com/fwlink/?LinkId=94695','');
}

contentmaster.MainWindowUtils.prototype.fwdLink_enter = function(sender)
{
    sender.Foreground = "Blue";
}
contentmaster.MainWindowUtils.prototype.fwdLink_leave = function(sender)
{
    sender.Foreground = "MediumBlue";
}

contentmaster.MainWindowUtils.prototype.loop_Splash = function(sender)
{
    sender.Stop();
    sender.Play();
}

contentmaster.MainWindowUtils.prototype.demo_enter = function(sender)
{
    sender.children.getItem(0).children.getItem(0).children.getItem(0).Fill = "#FFE13333";
}

contentmaster.MainWindowUtils.prototype.demo_leave = function(sender)
{
    sender.children.getItem(0).children.getItem(0).children.getItem(0).Fill = "#FFFF6E6E";
}

contentmaster.MainWindowUtils.prototype.anim_enter = function(sender)
{
    sender.children.getItem(0).children.getItem(0).children.getItem(0).children.getItem(0).Fill = "#FF5AA2EC";
}

contentmaster.MainWindowUtils.prototype.anim_leave = function(sender)
{
    sender.children.getItem(0).children.getItem(0).children.getItem(0).children.getItem(0).Fill = "#FF7DBDFF";
}

contentmaster.MainWindowUtils.prototype.addCMLogo = function(target)
{
    var logoString = '';
    logoString += '<Canvas Width="226.768" Height="50" Canvas.Left="35" Canvas.Top="90">';
    logoString += '<Rectangle Width="140" Height="40" Fill="White" RadiusX="6" RadiusY="6" />';
    logoString += '<Canvas Width="129.428" Height="20.7448" Canvas.Left="2" Canvas.Top="12.1198">';
    logoString += '<Canvas Width="129.428" Height="20.7448">';
    logoString += '<Path Width="12.125" Height="14.25" Canvas.Left="0" Canvas.Top="0.937458" Stretch="Fill" Fill="#FFFF9C00" Data="F1 M 11.1536,4C 10.8412,3.39185 10.362,2.88281 9.71611,2.47131C 9.07292,2.05985 8.41667,1.85413 7.75264,1.85413C 6.16931,1.85413 4.90894,2.39067 3.97131,3.4648C 3.03133,4.53772 2.5625,5.98173 2.5625,7.79692C 2.5625,9.65104 3.05212,11.1588 4.02865,12.3203C 5.00785,13.4817 6.28906,14.0625 7.8724,14.0625C 8.65356,14.0625 9.36719,13.9205 10.0131,13.6367C 10.6589,13.3529 11.2839,12.8972 11.8907,12.2708L 12.125,12.3295L 12.0365,13.625C 10.7656,14.6667 9.17973,15.1875 7.28133,15.1875C 5.04944,15.1875 3.27865,14.5429 1.96611,13.2526C 0.65625,11.9623 0,10.203 0,7.97518C 0,5.84371 0.700521,4.13932 2.09892,2.85811C 3.49744,1.57813 5.35156,0.937458 7.66146,0.937458C 9.24479,0.937458 10.7136,1.31905 12.0625,2.08333L 11.448,4L 11.1536,4 Z "/>';
    logoString += '<Path Width="19.9792" Height="13.8542" Canvas.Left="14.974" Canvas.Top="0.958374" Stretch="Fill" Fill="#FFFF9C00" Data="F1 M 16.0885,1.21358L 17.4532,1.12504C 17.3932,1.4128 17.3541,1.79814 17.336,2.27734C 17.3151,2.75907 17.3073,3.20052 17.3073,3.60413C 18.3229,1.83984 19.8256,0.958374 21.8202,0.958374C 24.0079,0.958374 25.3855,1.88932 25.9505,3.75C 26.9218,1.88932 28.5156,0.958374 30.7292,0.958374C 32.0494,0.958374 33.0833,1.32678 33.8308,2.0612C 34.5781,2.79692 34.9532,3.8112 34.9532,5.10547L 34.9532,11.3711L 34.9532,14.8125C 34.7161,14.7735 34.5156,14.7434 34.3489,14.7252C 34.1823,14.7044 33.9713,14.6953 33.7161,14.6953C 33.3437,14.6953 32.9218,14.7344 32.4532,14.8125C 32.5286,14.2461 32.5989,13.3802 32.6563,12.2161C 32.7136,11.0521 32.7448,9.89319 32.7448,8.73824L 32.7448,6.50907C 32.7448,5.04171 32.5,3.97518 32.0131,3.30985C 31.5234,2.64453 30.7344,2.31254 29.6407,2.31254C 27.5912,2.31254 26.4584,3.44666 26.2448,5.71614L 26.0964,10.5872L 26.2448,14.8125C 26.0079,14.7735 25.8046,14.7434 25.6355,14.7252C 25.4688,14.7044 25.2448,14.6953 24.9688,14.6953C 24.612,14.6953 24.198,14.7344 23.724,14.8125C 23.8437,13.8099 23.9193,12.6211 23.948,11.2461C 23.9792,9.86971 23.9948,8.91667 23.9948,8.38546C 23.9948,6.14453 23.9218,4.72518 23.7786,4.12626C 23.6328,3.526 23.2839,3.07426 22.7265,2.76961C 22.1693,2.4648 21.5833,2.31254 20.9688,2.31254C 19.526,2.31254 18.5808,2.81384 18.1302,3.81641C 17.677,4.81905 17.4532,6.15491 17.4532,7.82548L 17.4532,10.1549C 17.4532,10.8815 17.4532,11.6133 17.4532,12.3503C 17.4532,13.0872 17.4532,13.8203 17.4532,14.5469L 17.4817,14.8125C 17.2786,14.7735 17.0494,14.7434 16.7942,14.7252C 16.5391,14.7044 16.3593,14.6953 16.2579,14.6953C 16.0131,14.6953 15.7786,14.6953 15.5546,14.6953C 15.3308,14.7539 15.1355,14.7929 14.974,14.8125L 15.2656,8.05733C 15.2656,6.72518 15.2552,5.32548 15.2344,3.85681C 15.2136,2.38798 15.1927,1.59505 15.1718,1.47786L 15.1407,1.12504C 15.2579,1.14453 15.4349,1.16414 15.6745,1.18359C 15.9115,1.20304 16.0494,1.21358 16.0885,1.21358 Z "/>';
    logoString += '<Path Width="15.4167" Height="15.4167" Canvas.Left="39.3021" Canvas.Top="0" Stretch="Fill" Fill="#FFC1BBAD" Data="F1 M 39.3021,7.70837C 39.3021,5.58199 40.0546,3.76558 41.5599,2.25907C 43.0651,0.753864 44.8802,0 47.0052,0C 49.1302,0 50.9453,0.753864 52.4557,2.25907C 53.9636,3.76558 54.7188,5.58199 54.7188,7.70837C 54.7188,9.83468 53.9636,11.6524 52.4557,13.1576C 50.9453,14.6641 49.1302,15.4167 47.0052,15.4167C 44.8802,15.4167 43.0651,14.6641 41.5599,13.1576C 40.0546,11.6524 39.3021,9.83468 39.3021,7.70837 Z "/>';
    logoString += '<Path Width="12.7084" Height="19.75" Canvas.Left="58.7317" Canvas.Top="0.958374" Stretch="Fill" Fill="#FF474FA1" Data="F1 M 69.8776,5.26961C 69.8776,6.54171 69.3698,7.58984 68.3541,8.4128C 67.3385,9.23438 66.0365,9.64587 64.4557,9.64587L 63.3698,9.64587C 62.2369,9.64587 61.6693,10.026 61.6693,10.7852C 61.6693,11.194 61.8202,11.4817 62.125,11.6472C 62.427,11.8138 62.9401,11.8959 63.6641,11.8959L 65.7474,11.8959C 67.4688,11.8959 68.8489,12.082 69.8855,12.4519C 70.9218,12.8229 71.4401,13.7213 71.4401,15.1459C 71.4401,16.7461 70.776,18.0729 69.4453,19.1276C 68.1147,20.1809 66.4401,20.7084 64.427,20.7084C 62.6849,20.7084 61.2994,20.3697 60.2734,19.694C 59.2448,19.0169 58.7317,18.1107 58.7317,16.974C 58.7317,16.1497 59.0052,15.4844 59.5546,14.9752C 60.1016,14.4648 60.8256,14.0142 61.7265,13.6211L 61.7265,13.4752C 60.4948,13.2019 59.8776,12.5885 59.8776,11.6341C 59.8776,11.1863 60.0234,10.7969 60.3177,10.4661C 60.612,10.1341 61.1302,9.77478 61.8724,9.38411L 61.8724,9.23958C 60.9923,8.98572 60.2865,8.52478 59.7579,7.85933C 59.2265,7.19401 58.9609,6.42053 58.9609,5.53906C 58.9609,4.11068 59.474,2.98958 60.5026,2.17704C 61.5313,1.36454 62.9453,0.958374 64.7474,0.958374L 68.6224,1.10413C 69.388,1.10413 69.9401,1.08467 70.2813,1.04561C 70.625,1.00651 70.9141,0.977863 71.1484,0.958374L 71.0599,1.43225C 71.0599,1.53121 71.0912,1.74866 71.1484,2.08333L 67.862,1.97921C 69.2057,2.66532 69.8776,3.76172 69.8776,5.26961 Z M 64.4844,19.7917C 65.9505,19.7917 67.1432,19.4688 68.0625,18.8216C 68.9817,18.1757 69.4401,17.3333 69.4401,16.2956C 69.4401,14.474 67.9349,13.5625 64.9245,13.5625C 63.5156,13.5625 62.4297,13.8268 61.6667,14.3555C 60.9063,14.8841 60.5234,15.6393 60.5234,16.6185C 60.5234,17.5976 60.875,18.3711 61.5808,18.9401C 62.2839,19.5079 63.2526,19.7917 64.4844,19.7917 Z M 64.427,1.77079C 63.4869,1.77079 62.7213,2.09505 62.1355,2.74215C 61.5469,3.38932 61.2526,4.25264 61.2526,5.33199C 61.2526,7.66532 62.3202,8.83333 64.4557,8.83333C 65.474,8.83333 66.2579,8.48572 66.8046,7.78906C 67.3541,7.09241 67.6276,6.23438 67.6276,5.21358C 67.6276,4.23307 67.3593,3.41414 66.8202,2.75651C 66.2813,2.10026 65.4844,1.77079 64.427,1.77079 Z "/>';
    logoString += '<Path Width="7" Height="13.8751" Canvas.Left="74.1804" Canvas.Top="0.937458" Stretch="Fill" Fill="#FF474FA1" Data="F1 M 74.3053,4.47266L 74.1804,1.44788L 74.1804,1.12504C 74.5684,1.18359 74.9485,1.21358 75.3184,1.21358L 75.7559,1.21358C 75.9304,1.21358 76.1829,1.18359 76.5137,1.12504L 76.3886,3.47131L 76.3886,3.94145C 76.9381,3.27999 77.4876,2.61853 78.0345,1.95837C 78.7012,1.27734 79.4668,0.937458 80.3288,0.937458C 80.623,0.937458 80.9069,1.00651 81.1804,1.14319C 81.1023,1.3776 81.0449,1.64717 81.0059,1.95052C 80.9668,2.25386 80.946,2.55212 80.946,2.84505L 80.9746,3.37374L 80.7689,3.52079C 80.3184,3.18746 79.8496,3.02079 79.36,3.02079C 77.3783,3.02079 76.3886,4.56641 76.3886,7.65491L 76.3886,10.2369L 76.5137,14.8125C 76.1257,14.7344 75.7949,14.6953 75.5214,14.6953C 75.2299,14.6953 74.7845,14.7344 74.1804,14.8125L 74.1804,14.5196L 74.3053,11.3464L 74.3053,8.02734L 74.3053,4.47266 Z "/>';
    logoString += '<Path Width="14.0416" Height="14.2292" Canvas.Left="83.0137" Canvas.Top="0.833332" Stretch="Fill" Fill="#FF474FA1" Data="F1 M 89.8157,15.0625C 87.7819,15.0625 86.1413,14.4076 84.8913,13.0976C 83.6386,11.7864 83.0137,10.0456 83.0137,7.87504C 83.0137,5.74345 83.6829,4.03638 85.0214,2.75521C 86.36,1.474 88.1335,0.833332 90.3418,0.833332C 92.3366,0.833332 93.9537,1.4648 95.1933,2.72518C 96.4356,3.98694 97.0553,5.71358 97.0553,7.9036C 97.0553,9.9388 96.3913,11.6393 95.0632,13.0091C 93.7324,14.3776 91.9851,15.0625 89.8157,15.0625 Z M 89.8678,14.1459C 91.2741,14.1459 92.3965,13.5599 93.2351,12.388C 94.0736,11.2148 94.4928,9.64319 94.4928,7.66931C 94.4928,5.91146 94.1126,4.48572 93.3523,3.39185C 92.5892,2.29692 91.584,1.75 90.3366,1.75C 88.8132,1.75 87.6335,2.33199 86.7949,3.49345C 85.9537,4.65625 85.5345,6.29293 85.5345,8.40238C 85.5345,10.0429 85.9408,11.4101 86.7506,12.5052C 87.5605,13.5989 88.5996,14.1459 89.8678,14.1459 Z "/>';
    logoString += '<Path Width="11.8333" Height="14.047" Canvas.Left="100.48" Canvas.Top="1.11971" Stretch="Fill" Fill="#FF474FA1" Data="F1 M 105.256,15.1667C 103.764,15.1667 102.602,14.7305 101.769,13.8593C 100.933,12.9869 100.516,11.7669 100.516,10.2005L 100.605,3.67574L 100.605,2.67704C 100.605,2.34505 100.605,2.00134 100.605,1.6484C 100.542,1.43359 100.501,1.25651 100.48,1.11971C 100.717,1.15881 100.917,1.1888 101.084,1.20837C 101.251,1.22786 101.462,1.23694 101.717,1.23694C 102.05,1.23694 102.493,1.19788 103.042,1.11971C 103.003,1.45304 102.964,1.79171 102.925,2.13411C 102.886,2.47786 102.868,2.83467 102.868,3.20707L 102.751,8.47001C 102.751,10.5481 103.053,11.9309 103.659,12.6172C 104.266,13.3033 105.147,13.6459 106.3,13.6459C 107.628,13.6459 108.555,13.1601 109.084,12.1901C 109.613,11.22 109.876,10.0196 109.876,8.58854L 109.876,5.97131L 109.876,3.6484L 109.876,3.1484C 109.876,2.61971 109.857,2.20837 109.818,1.91414C 109.779,1.61971 109.751,1.35547 109.73,1.11971C 110.219,1.19788 110.631,1.23694 110.964,1.23694C 111.316,1.23694 111.766,1.19788 112.313,1.11971C 112.118,2.86332 112.021,5.27213 112.021,8.34757L 112.147,14.8125C 111.912,14.7344 111.657,14.6953 111.383,14.6953C 111.149,14.6953 110.967,14.6953 110.839,14.6953C 110.712,14.6953 110.383,14.7344 109.855,14.8125C 109.865,14.5781 109.87,14.2357 109.87,13.7864C 109.87,13.3372 109.87,12.9752 109.876,12.7019L 109.959,12.4961L 109.876,12.4375C 108.855,14.2565 107.316,15.1667 105.256,15.1667 Z "/>';
    logoString += '<Path Width="13.1667" Height="19.8698" Canvas.Left="116.261" Canvas.Top="0.87504" Stretch="Fill" Fill="#FF474FA1" Data="F1 M 116.407,4.44401L 116.261,1.47786L 116.261,1.12504C 116.456,1.14453 116.667,1.16414 116.891,1.18359C 117.115,1.20304 117.295,1.21358 117.433,1.21358C 117.607,1.21358 117.988,1.18359 118.574,1.12504C 118.532,1.97131 118.511,2.91532 118.511,3.95837C 119.133,2.92053 119.844,2.14717 120.641,1.63932C 121.441,1.12895 122.412,0.87504 123.561,0.87504C 125.292,0.87504 126.704,1.50134 127.792,2.75134C 128.883,4.00264 129.428,5.65491 129.428,7.70707C 129.428,9.91532 128.842,11.7044 127.667,13.0729C 126.493,14.4414 124.967,15.125 123.087,15.125C 121.128,15.125 119.631,14.2917 118.594,12.625L 118.654,15.0964C 118.654,16.3516 118.667,17.401 118.696,18.2434C 118.727,19.0872 118.79,19.9205 118.886,20.7448C 118.633,20.7057 118.402,20.6757 118.199,20.6576C 117.993,20.6367 117.792,20.6276 117.597,20.6276C 117.225,20.6276 116.816,20.6667 116.365,20.7448L 116.407,17.4557L 116.49,10.9648L 116.407,4.44401 Z M 122.704,14.0625C 124.248,14.0625 125.326,13.4375 125.943,12.1875C 126.558,10.9375 126.865,9.46228 126.865,7.76306C 126.865,5.94666 126.508,4.5352 125.795,3.52999C 125.081,2.52478 124.092,2.02079 122.821,2.02079C 121.295,2.02079 120.196,2.59757 119.521,3.75C 118.85,4.90238 118.511,6.28906 118.511,7.91011C 118.511,9.6484 118.811,11.1081 119.404,12.2904C 120.001,13.4713 121.1,14.0625 122.704,14.0625 Z "/>';
    logoString += '</Canvas>';
    logoString += '</Canvas>';
    logoString += '</Canvas>';
    
    var xamlFragment = this.control.content.createFromXaml(logoString); 
    target.children.add(xamlFragment);

}

contentmaster.MainWindowUtils.prototype.resetWindows = function()
{
   var navWindow = this.control.content.findName("NavWindow");
   navWindow["Canvas.Left"] = 5;
   navWindow["Canvas.Top"] = 1;
   
   var winPosX = 305;
   var winPosY = 1;
   
   for (var winCount = 0; winCount < this.activeMainWindows.length; winCount++){
       if (this.activeMainWindows[winCount].xamlObject.Visibility == "Visible"){
            this.activeMainWindows[winCount].xamlObject["Canvas.Left"] = winPosX;
            this.activeMainWindows[winCount].xamlObject["Canvas.Top"] = winPosY;
            winPosX += 10;
            winPosY += 10;
       }else{
           continue;
       }
   }

}

contentmaster.MainWindowUtils.prototype.getLaunchImage = function(type, url)
{
    var launchURL = "";
    if (type == "animation"){
        //return '<Canvas><Rectangle Width="300" Height="100" Fill="LightGray" RadiusX="4" RadiusY="4" /></Canvas>'
        launchURL = "XAML/Launch/launch-animation.xaml";
    }
    if (type == "demo"){
        launchURL = "XAML/Launch/launch-demo.xaml";
    }

	DownloadItem(this.control, launchURL, Silverlight.createDelegate(this, this.launchLoaded ));

}

contentmaster.MainWindowUtils.prototype.launchLoaded = function(sender, eventArgs)
{
	try
	{
		var xamlFragment = ""
		if (IS_USING_DOWNLOADER)
		{
			xamlFragment = this.control.content.createFromXamlDownloader(sender, ""); 
		}
		else
		{
			xamlFragment = this.control.content.createFromXaml(sender); 
		}
		this.launchHolder.children.add(xamlFragment);
	}
	catch (ex)
	{
		return;
	}
}


contentmaster.MainWindowUtils.prototype.open_labLink = function(sender)
{
    window.open(this.labLink,'Lab')
}

contentmaster.MainWindowUtils.prototype.labLink_enter = function(sender)
{
    sender.children.getItem(0).Stroke = "#FF922222";
}

contentmaster.MainWindowUtils.prototype.labLink_leave = function(sender)
{
    sender.children.getItem(0).Stroke = "LightGray";
}

/////////////////////////
// Launch DEMO
////////////////////////

contentmaster.MainWindowUtils.prototype.launchDemo = function(sender)
{
   var control = document.getElementById("silverlightControl1");
   var controlWidth = control.clientWidth > 0 ? control.clientWidth : 1024;
   var controlHeight = control.clientHeight > 0 ? control.clientHeight : 768;

           
   var newURL = this.demoURL;
   var newTitle = this.demoTitle;
   var newTrans = this.demoTrans;
   var newType = this.demoType;
   
   
   if (window.Temp_Video_Button_Storage != null)
   {
	   for (var k = 0; k <  window.Temp_Video_Button_Storage.length; k++)
	   {
			if (window.Temp_Video_Button_Storage[k].Id == sender.Width)
			{
				newURL = window.Temp_Video_Button_Storage[k].Url;
				newTitle = window.Temp_Video_Button_Storage[k].Title;
				newTrans = window.Temp_Video_Button_Storage[k].Trans;
				newType = window.Temp_Video_Button_Storage[k].Type;
				break;
			}
			
	   }
   }


    if (!this.vidWinUtils){
        var vidWinUtil = new contentmaster.VideoWindowUtils(controlWidth, controlHeight, this.activeMainWindows, newTitle, newURL, sender, this, newType, newTrans, this.sceneClass);
        this.vidWinUtils = vidWinUtil;
    }
    else if (this.vidWinUtils.activeVidWin){
    
        if (this.vidWinUtils.activeVidWin.xamlObject.Visibility == "Collapsed"){

            var taskBar = sender.findName("taskBar");
            var windows = sender.findName("windows");
            
            for (var j=0; j<this.taskBarItems.length; j++){
                var windowTitle = this.taskBarItems[j].winXaml.children.getItem(2).Text;
                if ((windowTitle.substring(0,13) == "Demonstration")||(windowTitle.substring(0,9) == "Animation")){
                    this.taskBarItems[j].winXaml.Visibility = "Visible";
                    taskBar.children.removeAt(j);
                    this.taskBarItems.splice(j, 1);
                }
            }
            
            for (var k=0; k<this.taskBarItems.length; k++){
                var itemToArrange = taskBar.children.getItem(k);
                this.posElement(itemToArrange, k);
            }
        }
        
        this.vidWinUtils.activeVidWin.title = newTitle;
        this.vidWinUtils.activeVidWin.source = newURL;
        this.vidWinUtils.activeVidWin.htmlPage = newTrans;
        
        this.vidWinUtils.activeVidWin.configureWindowVideo(newType);
        
        var windows = sender.findName("windows");
        var zindex = 0;
        for (i=0; i<windows.children.count; i++){
            if (windows.children.getItem(i)["Canvas.ZIndex"] > zindex){
            zindex = windows.children.getItem(i)["Canvas.ZIndex"];
            }else{
            continue;
            }  
        }
        this.vidWinUtils.activeVidWin.xamlObject["Canvas.ZIndex"] = (zindex+1);
        }
    else if (!this.vidWinUtils.activeVidWin){
            this.vidWinUtils.newTitle = newTitle;
            this.vidWinUtils.source = newURL;
            this.vidWinUtils.htmlPage = newTrans;
            this.vidWinUtils.demoType = newType;
            this.vidWinUtils.createVideoWindow();
        }
}





///////////////////////////
// Create IFrame
//////////////////////////
// IFrame to host Flash media elements

contentmaster.MainWindowUtils.prototype.launchAnim = function(sender)
{
   var control = document.getElementById("silverlightControl1");
   var controlWidth = control.content.findName("MainCanvas").Width;
   var controlHeight = control.content.findName("MainCanvas").Height;
   
   var iFrameWidth = 760;
   var iFrameHeight = 570;
   
   var medWinWidth = 800;
   var medWinHeight = 600;
   
   var middleOffset = (controlWidth * 0.5) - (medWinWidth * 0.5);
   var topOffset = (controlHeight * 0.5) - (medWinHeight * 0.5);
   
   var newURL = this.aniURL;
   
   function makeFrame() { 
       var ifrm = document.createElement("IFRAME"); 
       ifrm.setAttribute("src", newURL);
       ifrm.setAttribute("frameborder", "0"); 
       ifrm.setAttribute("scrolling", "no");
       ifrm.setAttribute("name", "mediaFrame");
       ifrm.setAttribute("id", "mediaFrame");
       ifrm.style.width = iFrameWidth+"px"; 
       ifrm.style.height = iFrameHeight+"px";
       ifrm.style.position = "absolute";
       ifrm.style.top = (topOffset+56)+"px";
       ifrm.style.left = (middleOffset+30)+"px";
       document.body.appendChild(ifrm); 
    } 
    
    var mediaHolder = control.content.findName("mediaHolder");
    var fader = '<Canvas Background="#ccFFFFFF" Width="100" Height="100" ></Canvas>';
    var xamlFragment = control.content.createFromXaml(fader); 
    mediaHolder.children.add(xamlFragment);

    var fader = mediaHolder.children.getItem(0);
    fader.Width = controlWidth;
    fader.height = controlHeight;
    
    makeFrame();
    var medWinUtil = new contentmaster.MediaWindowUtils(middleOffset, topOffset);
    var medWinXAML = medWinUtil.createMediaWindow();


}
