﻿var win = null;
	
function createSilverlight() {
    var scene = new floor_navigation.Page();
    Silverlight.createObjectEx(
            {
                source: "floor_navigation/floorimages.xaml",
                parentElement: document.getElementById("silverlightControlHost"),
                id: "SilverlightControl",
                properties:
			    {
			        width: "100%",
			        height: "100%",
			        version: "2.0.31005",
			        background: "#00FFFFFF",
			        isWindowless: "true"
			    },  // properties:
                events:
			    {
			        onLoad: Silverlight.createDelegate(scene, scene.handleLoad),
			        onError: function(sender, args) {
			            var errorDiv = document.getElementById("errorLocation");
			            if (errorDiv != null) {
			                var errorText = args.errorType + "- " + args.errorMessage;
			                if (args.ErrorType == "ParserError") {
			                    errorText += "<br\>File: " + args.xamlFile;
			                    errorText += ", line " + args.lineNumber;
			                    errorText += " character " + args.charPosition;
			                }
			                else if (args.ErrorType == "RuntimeError") {
			                    errorText += "<br\>line " + args.lineNumber;
			                    errorText += " character " + args.charPosition;
			                }
			                errorDiv.innerHTML = errorText;
			            } // if (errorDiv != null)
			        } // onError: function(sender, args)
                }   // events:
            }); // Silverlight.createObjectEx(
        }   // function createSilverlight()

    if (!window.Silverlight) {
        Silverlight = {};
    }

    Silverlight.createDelegate = function(instance, method) {
        return function() {
            return method.apply(instance, arguments);
        }
}

var win = null;
var flag = new Boolean();

function showWordWindow(word, parent) {
    var popupWidth = 432;
    var popupSmalHeight = 285;
    var popupMediumHeight = 350;
    var popupLargeHeight = 431;
    var popupXLHeight = 525;
    var popupSmallTop = 240;
    var popupMediumTop = 175;
    var popupLargeTop = 90;
    var popupXLTop = 5;
    var popupColumnSecondLeft = 0;
    var popupColumnThirdLeft = 145;
    var popupColumnFourthRight = 90;
    var popupColumnFifthRight = 0;
    flag = false;
    closeWindow(parent);
    switch(word)
    {
        case "nimble":
            win = new Window({ className: "spread", title: "domus | nimble ad agency", width: popupWidth, height: popupMediumHeight, 
            right: popupColumnFourthRight, top: popupMediumTop, url: "domus_is_nimble.html", closable: true, showEffectOptions: { duration: 1.5} });
            break;
        case "breakthrough":
            win = new Window({ className: "spread", title: "domus | breakthrough ad agency", width: popupWidth, height: popupSmalHeight, 
            top: popupSmallTop, url: "domus_is_breakthrough.html", closable: true, showEffectOptions: { duration: 1.5} });
            flag = true;
            break;
        case "different":
            win = new Window({ className: "spread", title: "domus | different ad agency", width: popupWidth, height: popupSmalHeight, 
            right: popupColumnFifthRight, top: popupSmallTop, url: "domus_is_different.html", closable: true, showEffectOptions: { duration: 1.5} });
            break;
        case "adaptable":
            win = new Window({ className: "spread", title: "domus | adaptable ad agency", width: popupWidth, height: popupMediumHeight,
            right: popupColumnFifthRight, top: popupMediumTop, url: "domus_is_adaptable.html", closable: true, showEffectOptions: { duration: 1.5}});
            break;
        case "turnkey":
            win = new Window({ className: "spread", title: "domus | turnkey ad agency", width: popupWidth, height: popupSmalHeight, 
            top: popupSmallTop, url: "domus_is_turnkey.html", closable: true, showEffectOptions: { duration: 1.5} });
            flag = true;
            break;
        case "focused":
            win = new Window({ className: "spread", title: "domus | focused ad agency", width: popupWidth, height: popupLargeHeight,
            right: popupColumnFourthRight, top: popupLargeTop, url: "domus_is_focused.html", closable: true, showEffectOptions: { duration: 1.5}});
            break;
        case "resourceful":
            win = new Window({ className: "spread", title: "domus | resourceful ad agency", width: popupWidth, height: popupXLHeight,
            left: popupColumnThirdLeft, top: popupXLTop, url: "domus_is_resourceful.html", closable: true, showEffectOptions: { duration: 1.5}});
            break;
        case "efficient":
            win = new Window({ className: "spread", title: "domus | efficient ad agency", width: popupWidth, height: popupLargeHeight,
            left: popupColumnThirdLeft, top: popupLargeTop, url: "domus_is_efficient.html", closable: true, showEffectOptions: { duration: 1.5}});
            break;
        case "expert":
            win = new Window({ className: "spread", title: "domus | expert ad agency", width: popupWidth, height: popupLargeHeight, 
            top: popupLargeTop, url: "domus_is_expert.html", closable: true, showEffectOptions: { duration: 1.5} });
            flag = true;
            break;
        case "integrated":
            win = new Window({ className: "spread", title: "domus | integrated ad agency", width: popupWidth, height: popupMediumHeight, 
            left: popupColumnSecondLeft, top: popupMediumTop, url: "domus_is_integrated.html", closable: true, showEffectOptions: { duration: 1.5} });
            break;
        case "energetic":
            win = new Window({ className: "spread", title: "domus | energetic ad agency", width: popupWidth, height: popupSmalHeight, 
            left: popupColumnThirdLeft, top: popupSmallTop, url: "domus_is_energetic.html", closable: true, showEffectOptions: { duration: 1.5} });
            break;
        case "strategic":
            win = new Window({ className: "spread", title: "domus | strategic ad agency", width: popupWidth, height: popupXLHeight, 
            left: popupColumnSecondLeft, top: popupXLTop, url: "domus_is_strategic.html", closable: true, showEffectOptions: { duration: 1.5} });
            break;
        case "interactive":
            win = new Window({ className: "spread", title: "domus | interactive ad agency", width: popupWidth, height: popupMediumHeight, 
            left: popupColumnSecondLeft, top: popupMediumTop, url: "domus_is_interactive.html", closable: true, showEffectOptions: { duration: 1.5} });
            break;
        case "smart":
            win = new Window({ className: "spread", title: "domus | smart ad agency", width: popupWidth, height: popupSmalHeight, 
            right: popupColumnFourthRight, top: popupSmallTop, url: "domus_is_smart.html", closable: true, showEffectOptions: { duration: 1.5} });
            break;
        case "fast":
            win = new Window({ className: "spread", title: "domus | fast ad agency", width: popupWidth, height: popupSmalHeight, 
            right: popupColumnFifthRight, top: popupSmallTop, url: "domus_is_fast.html", closable: true, showEffectOptions: { duration: 1.5} });
            break;
        default:
            win = new Window({ className: "spread", title: "domus | " + word, width: popupWidth, height: popupMediumHeight, 
            left: popupColumnSecondLeft, top: popupMediumTop, url: "domus_is_" + word + ".html", closable: true, showEffectOptions: { duration: 1.5} });
    }    
    positionWindow();
    win.setDestroyOnClose();
    win.show();
} // function showWordWindow(word)

function positionWindow() {
    if (flag == true && win) {
    
        //get the browser window width
        var PosX = document.body.clientWidth;
        //get the width of the silverlight control host.
        var SilverlightControlHostWidth = document.getElementById('silverlightControlHost').offsetWidth;
        //get the width of the betty video host.
        var VideoHostWidth = document.getElementById('videoHost').offsetWidth;

        var PosY = SilverlightControlHostWidth + VideoHostWidth;        
        
        //check if browser width is greater than sum of silverlight control host and betty video host.
        if (PosX > PosY) {
            PosZ = (PosX - PosY) / 2 + (SilverlightControlHostWidth * .75);
        }
        else {
            PosZ = (SilverlightControlHostWidth * .75);
        }
        win.element.setStyle({ left: parseFloat(PosZ) + 'px' });
    } // function positionWindow()
}

function closeWindow(parent) {
    if (win && !win.closed) {
        win.close();
    } 
    win = null;
    if (window.parent.win && !window.parent.win.closed) {
        window.parent.win.close();     
    }
    if (parent == true) {
        if (window.frames[0].win != null) {
                if( !window.frames[0].win.closed){
                window.frames[0].win.close();
            }
            window.frames[0].win = null;          
        }
    }
    window.parent.win = null; 
}

