///////////////////////////////////////////////////////////////////////////////
//
//  Silverlight.js   			version 4.0.50401.0
//
//  This file is provided by Microsoft as a helper file for websites that
//  incorporate Silverlight Objects. This file is provided under the Microsoft
//  Public License available at 
//  http://code.msdn.microsoft.com/silverlightjs/Project/License.aspx.  
//  You may not use or distribute this file or the code in this file except as 
//  expressly permitted under that license.
// 
//  Copyright (c) Microsoft Corporation. All rights reserved.
//
///////////////////////////////////////////////////////////////////////////////

if (!window.Silverlight) {
    window.Silverlight = {};
}

//////////////////////////////////////////////////////////////////
//
// _silverlightCount:
//
// Counter of globalized event handlers
//
//////////////////////////////////////////////////////////////////
Silverlight._silverlightCount = 0;

//////////////////////////////////////////////////////////////////
//
// __onSilverlightInstalledCalled:
//
// Prevents onSilverlightInstalled from being called multiple 
// times
//
//////////////////////////////////////////////////////////////////
Silverlight.__onSilverlightInstalledCalled = false;

//////////////////////////////////////////////////////////////////
//
// fwlinkRoot:
//
// Prefix for fwlink URL's
//
//////////////////////////////////////////////////////////////////
Silverlight.fwlinkRoot = 'http://go2.microsoft.com/fwlink/?LinkID=';

//////////////////////////////////////////////////////////////////
//
// __installationEventFired:
//
// Ensures that only one Installation State event is fired.
//
//////////////////////////////////////////////////////////////////
Silverlight.__installationEventFired = false;

//////////////////////////////////////////////////////////////////
//  
// onGetSilverlight:
//
// Called by Silverlight.GetSilverlight to notify the page that a user
// has requested the Silverlight installer
//
//////////////////////////////////////////////////////////////////
Silverlight.onGetSilverlight = null;

//////////////////////////////////////////////////////////////////
//
// onSilverlightInstalled:
//
// Called by Silverlight.WaitForInstallCompletion when the page detects
// that Silverlight has been installed. The event handler is not called
// in upgrade scenarios.
//
//////////////////////////////////////////////////////////////////
Silverlight.onSilverlightInstalled = function () { window.location.reload(false); };

//////////////////////////////////////////////////////////////////
//
// isInstalled:
//
// Checks to see if the correct version is installed
//
//////////////////////////////////////////////////////////////////
Silverlight.isInstalled = function (version) {
    if (version == undefined)
        version = null;

    var isVersionSupported = false;
    var container = null;

    try {
        var control = null;
        var tryNS = false;

        if (window.ActiveXObject) {
            try {
                control = new ActiveXObject('AgControl.AgControl');
                if (version === null) {
                    isVersionSupported = true;
                }
                else if (control.IsVersionSupported(version)) {
                    isVersionSupported = true;
                }
                control = null;
            }
            catch (e) {
                tryNS = true;
            }
        }
        else {
            tryNS = true;
        }
        if (tryNS) {
            var plugin = navigator.plugins["Silverlight Plug-In"];
            if (plugin) {
                if (version === null) {
                    isVersionSupported = true;
                }
                else {
                    var actualVer = plugin.description;
                    if (actualVer === "1.0.30226.2")
                        actualVer = "2.0.30226.2";
                    var actualVerArray = actualVer.split(".");
                    while (actualVerArray.length > 3) {
                        actualVerArray.pop();
                    }
                    while (actualVerArray.length < 4) {
                        actualVerArray.push(0);
                    }
                    var reqVerArray = version.split(".");
                    while (reqVerArray.length > 4) {
                        reqVerArray.pop();
                    }

                    var requiredVersionPart;
                    var actualVersionPart;
                    var index = 0;


                    do {
                        requiredVersionPart = parseInt(reqVerArray[index]);
                        actualVersionPart = parseInt(actualVerArray[index]);
                        index++;
                    }
                    while (index < reqVerArray.length && requiredVersionPart === actualVersionPart);

                    if (requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart)) {
                        isVersionSupported = true;
                    }
                }
            }
        }
    }
    catch (e) {
        isVersionSupported = false;
    }

    return isVersionSupported;
};
//////////////////////////////////////////////////////////////////
//
// WaitForInstallCompletion:
//
// Occasionally checks for Silverlight installation status. If it
// detects that Silverlight has been installed then it calls
// Silverlight.onSilverlightInstalled();. This is only supported
// if Silverlight was not previously installed on this computer.
//
//////////////////////////////////////////////////////////////////
Silverlight.WaitForInstallCompletion = function () {
    if (!Silverlight.isBrowserRestartRequired && Silverlight.onSilverlightInstalled) {
        try {
            navigator.plugins.refresh();
        }
        catch (e) {
        }
        if (Silverlight.isInstalled(null) && !Silverlight.__onSilverlightInstalledCalled) {
            Silverlight.onSilverlightInstalled();
            Silverlight.__onSilverlightInstalledCalled = true;
        }
        else {
            setTimeout(Silverlight.WaitForInstallCompletion, 3000);
        }
    }
};
//////////////////////////////////////////////////////////////////
//
// __startup:
//
// Performs startup tasks. 
//////////////////////////////////////////////////////////////////
Silverlight.__startup = function () {
    navigator.plugins.refresh();
    Silverlight.isBrowserRestartRequired = Silverlight.isInstalled(null);
    if (!Silverlight.isBrowserRestartRequired) {
        Silverlight.WaitForInstallCompletion();
        if (!Silverlight.__installationEventFired) {
            Silverlight.onInstallRequired();
            Silverlight.__installationEventFired = true;
        }
    }
    else if (window.navigator.mimeTypes) {
        var mimeSL2 = navigator.mimeTypes["application/x-silverlight-2"];
        var mimeSL2b2 = navigator.mimeTypes["application/x-silverlight-2-b2"];
        var mimeSL2b1 = navigator.mimeTypes["application/x-silverlight-2-b1"];
        var mimeHighestBeta = mimeSL2b1;
        if (mimeSL2b2)
            mimeHighestBeta = mimeSL2b2;

        if (!mimeSL2 && (mimeSL2b1 || mimeSL2b2)) {
            if (!Silverlight.__installationEventFired) {
                Silverlight.onUpgradeRequired();
                Silverlight.__installationEventFired = true;
            }
        }
        else if (mimeSL2 && mimeHighestBeta) {
            if (mimeSL2.enabledPlugin &&
                mimeHighestBeta.enabledPlugin) {
                if (mimeSL2.enabledPlugin.description !=
                    mimeHighestBeta.enabledPlugin.description) {
                    if (!Silverlight.__installationEventFired) {
                        Silverlight.onRestartRequired();
                        Silverlight.__installationEventFired = true;
                    }
                }
            }
        }
    }
    if (!Silverlight.disableAutoStartup) {
        if (window.removeEventListener) {
            window.removeEventListener('load', Silverlight.__startup, false);
        }
        else {
            window.detachEvent('onload', Silverlight.__startup);
        }
    }
};

///////////////////////////////////////////////////////////////////////////////
//
// This block wires up Silverlight.__startup to be executed once the page
// loads. This is the desired behavior for most sites. If, however, a site
// prefers to control the timing of the Silverlight.__startup call then it should
// put the following block of javascript into the webpage before this file is
// included:
//
//    <script type="text/javascript">
//        if (!window.Silverlight)
//        {
//            window.Silverlight = {};
//        }
//        Silverlight.disableAutoStartup = true;
//    </script> 
//
/////////////////////////////////////////////////////////////////////////////////

if (!Silverlight.disableAutoStartup) {
    if (window.addEventListener) {
        window.addEventListener('load', Silverlight.__startup, false);
    }
    else {
        window.attachEvent('onload', Silverlight.__startup);
    }
}

///////////////////////////////////////////////////////////////////////////////
// createObject:
//
// Inserts a Silverlight <object> tag or installation experience into the HTML
// DOM based on the current installed state of Silverlight. 
//
/////////////////////////////////////////////////////////////////////////////////

Silverlight.createObject = function (source, parentElement, id, properties, events, initParams, userContext) {
    var slPluginHelper = new Object();
    var slProperties = properties;
    var slEvents = events;

    slPluginHelper.version = slProperties.version;
    slProperties.source = source;
    slPluginHelper.alt = slProperties.alt;

    //rename properties to their tag property names. For bacwards compatibility
    //with Silverlight.js version 1.0
    if (initParams)
        slProperties.initParams = initParams;
    if (slProperties.isWindowless && !slProperties.windowless)
        slProperties.windowless = slProperties.isWindowless;
    if (slProperties.framerate && !slProperties.maxFramerate)
        slProperties.maxFramerate = slProperties.framerate;
    if (id && !slProperties.id)
        slProperties.id = id;

    // remove elements which are not to be added to the instantiation tag
    delete slProperties.ignoreBrowserVer;
    delete slProperties.inplaceInstallPrompt;
    delete slProperties.version;
    delete slProperties.isWindowless;
    delete slProperties.framerate;
    delete slProperties.data;
    delete slProperties.src;
    delete slProperties.alt;


    // detect that the correct version of Silverlight is installed, else display install

    if (Silverlight.isInstalled(slPluginHelper.version)) {
        //move unknown events to the slProperties array
        for (var name in slEvents) {
            if (slEvents[name]) {
                if (name == "onLoad" && typeof slEvents[name] == "function" && slEvents[name].length != 1) {
                    var onLoadHandler = slEvents[name];
                    slEvents[name] = function (sender) { return onLoadHandler(document.getElementById(id), userContext, sender) };
                }
                var handlerName = Silverlight.__getHandlerName(slEvents[name]);
                if (handlerName != null) {
                    slProperties[name] = handlerName;
                    slEvents[name] = null;
                }
                else {
                    throw "typeof events." + name + " must be 'function' or 'string'";
                }
            }
        }
        slPluginHTML = Silverlight.buildHTML(slProperties);
    }
    //The control could not be instantiated. Show the installation prompt
    else {
        slPluginHTML = Silverlight.buildPromptHTML(slPluginHelper);
    }

    // insert or return the HTML
    if (parentElement) {
        parentElement.innerHTML = slPluginHTML;
    }
    else {
        return slPluginHTML;
    }

};

///////////////////////////////////////////////////////////////////////////////
//
//  buildHTML:
//
//  create HTML that instantiates the control
//
///////////////////////////////////////////////////////////////////////////////
Silverlight.buildHTML = function (slProperties) {
    var htmlBuilder = [];

    htmlBuilder.push('<object type=\"application/x-silverlight\" data="data:application/x-silverlight,"');
    if (slProperties.id != null) {
        htmlBuilder.push(' id="' + Silverlight.HtmlAttributeEncode(slProperties.id) + '"');
    }
    if (slProperties.width != null) {
        htmlBuilder.push(' width="' + slProperties.width + '"');
    }
    if (slProperties.height != null) {
        htmlBuilder.push(' height="' + slProperties.height + '"');
    }
    htmlBuilder.push(' >');

    delete slProperties.id;
    delete slProperties.width;
    delete slProperties.height;

    for (var name in slProperties) {
        if (slProperties[name]) {
            htmlBuilder.push('<param name="' + Silverlight.HtmlAttributeEncode(name) + '" value="' + Silverlight.HtmlAttributeEncode(slProperties[name]) + '" />');
        }
    }
    htmlBuilder.push('<\/object>');
    return htmlBuilder.join('');
};



//////////////////////////////////////////////////////////////////
//
// createObjectEx:
//
// takes a single parameter of all createObject 
// parameters enclosed in {}
//
//////////////////////////////////////////////////////////////////

Silverlight.createObjectEx = function (params) {
    var parameters = params;
    var html = Silverlight.createObject(parameters.source, parameters.parentElement, parameters.id, parameters.properties, parameters.events, parameters.initParams, parameters.context);
    if (parameters.parentElement == null) {
        return html;
    }
};

///////////////////////////////////////////////////////////////////////////////////////////////
//
// buildPromptHTML
//
// Builds the HTML to prompt the user to download and install Silverlight
//
///////////////////////////////////////////////////////////////////////////////////////////////
Silverlight.buildPromptHTML = function (slPluginHelper) {
    var slPluginHTML = "";
    var urlRoot = Silverlight.fwlinkRoot;
    var version = slPluginHelper.version;
    if (slPluginHelper.alt) {
        slPluginHTML = slPluginHelper.alt;
    }
    else {
        if (!version) {
            version = "";
        }
        slPluginHTML = "<a href='javascript:Silverlight.getSilverlight(\"{1}\");' style='text-decoration: none;'><img src='{2}' alt='Get Microsoft Silverlight' style='border-style: none'/></a>";
        slPluginHTML = slPluginHTML.replace('{1}', version);
        slPluginHTML = slPluginHTML.replace('{2}', urlRoot + '108181');
    }

    return slPluginHTML;
};

///////////////////////////////////////////////////////////////////////////////////////////////
//
// getSilverlight:
//
// Navigates the browser to the appropriate Silverlight installer
//
///////////////////////////////////////////////////////////////////////////////////////////////
Silverlight.getSilverlight = function (version) {
    if (Silverlight.onGetSilverlight) {
        Silverlight.onGetSilverlight();
    }

    var shortVer = "";
    var reqVerArray = String(version).split(".");
    if (reqVerArray.length > 1) {
        var majorNum = parseInt(reqVerArray[0]);
        if (isNaN(majorNum) || majorNum < 2) {
            shortVer = "1.0";
        }
        else {
            shortVer = reqVerArray[0] + '.' + reqVerArray[1];
        }
    }

    var verArg = "";

    if (shortVer.match(/^\d+\056\d+$/)) {
        verArg = "&v=" + shortVer;
    }

    Silverlight.followFWLink("149156" + verArg);
};


///////////////////////////////////////////////////////////////////////////////////////////////
//
// followFWLink:
//
// Navigates to a url based on fwlinkid
//
///////////////////////////////////////////////////////////////////////////////////////////////
Silverlight.followFWLink = function (linkid) {
    top.location = Silverlight.fwlinkRoot + String(linkid);
};

///////////////////////////////////////////////////////////////////////////////////////////////
//
// HtmlAttributeEncode:
//
// Encodes special characters in input strings as charcodes
//
///////////////////////////////////////////////////////////////////////////////////////////////
Silverlight.HtmlAttributeEncode = function (strInput) {
    var c;
    var retVal = '';

    if (strInput == null) {
        return null;
    }

    for (var cnt = 0; cnt < strInput.length; cnt++) {
        c = strInput.charCodeAt(cnt);

        if (((c > 96) && (c < 123)) ||
                  ((c > 64) && (c < 91)) ||
                  ((c > 43) && (c < 58) && (c != 47)) ||
                  (c == 95)) {
            retVal = retVal + String.fromCharCode(c);
        }
        else {
            retVal = retVal + '&#' + c + ';';
        }
    }

    return retVal;
};
///////////////////////////////////////////////////////////////////////////////
//
//  default_error_handler:
//
//  Default error handling function 
//
///////////////////////////////////////////////////////////////////////////////

Silverlight.default_error_handler = function (sender, args) {
    var iErrorCode;
    var errorType = args.ErrorType;

    iErrorCode = args.ErrorCode;

    var errMsg = "\nSilverlight error message     \n";

    errMsg += "ErrorCode: " + iErrorCode + "\n";


    errMsg += "ErrorType: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError") {
        errMsg += "XamlFile: " + args.xamlFile + "     \n";
        errMsg += "Line: " + args.lineNumber + "     \n";
        errMsg += "Position: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError") {
        if (args.lineNumber != 0) {
            errMsg += "Line: " + args.lineNumber + "     \n";
            errMsg += "Position: " + args.charPosition + "     \n";
        }
        errMsg += "MethodName: " + args.methodName + "     \n";
    }
    alert(errMsg);
};

///////////////////////////////////////////////////////////////////////////////////////////////
//
// __cleanup:
//
// Releases event handler resources when the page is unloaded
//
///////////////////////////////////////////////////////////////////////////////////////////////
Silverlight.__cleanup = function () {
    for (var i = Silverlight._silverlightCount - 1; i >= 0; i--) {
        window['__slEvent' + i] = null;
    }
    Silverlight._silverlightCount = 0;
    if (window.removeEventListener) {
        window.removeEventListener('unload', Silverlight.__cleanup, false);
    }
    else {
        window.detachEvent('onunload', Silverlight.__cleanup);
    }
};

///////////////////////////////////////////////////////////////////////////////////////////////
//
// __getHandlerName:
//
// Generates named event handlers for delegates.
//
///////////////////////////////////////////////////////////////////////////////////////////////
Silverlight.__getHandlerName = function (handler) {
    var handlerName = "";
    if (typeof handler == "string") {
        handlerName = handler;
    }
    else if (typeof handler == "function") {
        if (Silverlight._silverlightCount == 0) {
            if (window.addEventListener) {
                window.addEventListener('unload', Silverlight.__cleanup, false);
            }
            else {
                window.attachEvent('onunload', Silverlight.__cleanup);
            }
        }
        var count = Silverlight._silverlightCount++;
        handlerName = "__slEvent" + count;

        window[handlerName] = handler;
    }
    else {
        handlerName = null;
    }
    return handlerName;
};
//////////////////////////////////////////////////////////////////
//  
// onRequiredVersionAvailable:
//
// Called by version  verification control to notify the page that
// an appropriate build of Silverlight is available. The page 
// should respond by injecting the appropriate Silverlight control
//
//////////////////////////////////////////////////////////////////
Silverlight.onRequiredVersionAvailable = function () {

};
//////////////////////////////////////////////////////////////////
//  
// onRestartRequired:
//
// Called by version verification control to notify the page that
// an appropriate build of Silverlight is installed but not loaded. 
// The page should respond by injecting a clear and visible 
// "Thanks for installing. Please restart your browser and return
// to mysite.com" or equivalent into the browser DOM
//
//////////////////////////////////////////////////////////////////
Silverlight.onRestartRequired = function () {

};
//////////////////////////////////////////////////////////////////
//  
// onUpgradeRequired:
//
// Called by version verification control to notify the page that
// Silverlight must be upgraded. The page should respond by 
// injecting a clear, visible, and actionable upgrade message into
// the DOM. The message must inform the user that they need to 
// upgrade Silverlight to use the page. They are already somewhat
// familiar with the Silverlight product when they encounter this.
// Silverlight should be mentioned so the user expects to see that
// string in the installer UI. However, the Silverlight-powered
// application should be the focus of the solicitation. The user
// wants the app. Silverlight is a means to the app.
// 
// The upgrade solicitation will have a button that directs 
// the user to the Silverlight installer. Upon click the button
// should both kick off a download of the installer URL and replace
// the Upgrade text with "Thanks for downloading. When the upgarde
// is complete please restart your browser and return to 
// mysite.com" or equivalent.
//
// Note: For a more interesting upgrade UX we can use Silverlight
// 1.0-style XAML for this upgrade experience. Contact PiotrP for
// details.
//
//////////////////////////////////////////////////////////////////
Silverlight.onUpgradeRequired = function () {

};
//////////////////////////////////////////////////////////////////
//  
// onInstallRequired:
//
// Called by Silverlight.checkInstallStatus to notify the page
// that Silverlight has not been installed by this user.
// The page should respond by 
// injecting a clear, visible, and actionable upgrade message into
// the DOM. The message must inform the user that they need to 
// download and install components needed to use the page. 
// Silverlight should be mentioned so the user expects to see that
// string in the installer UI. However, the Silverlight-powered
// application should be the focus of the solicitation. The user
// wants the app. Silverlight is a means to the app.
// 
// The installation solicitation will have a button that directs 
// the user to the Silverlight installer. Upon click the button
// should both kick off a download of the installer URL and replace
// the Upgrade text with "Thanks for downloading. When installation
// is complete you may need to refresh the page to view this 
// content" or equivalent.
//
//////////////////////////////////////////////////////////////////
Silverlight.onInstallRequired = function () {

};

//////////////////////////////////////////////////////////////////
//  
// IsVersionAvailableOnError:
//
// This function should be called at the beginning of a web page's
// Silverlight error handler. It will determine if the required 
// version of Silverlight is installed and available in the 
// current process.
//
// During its execution the function will trigger one of the 
// Silverlight installation state events, if appropriate.
//
// Sender and Args should be passed through from  the calling
// onError handler's parameters. 
//
// The associated Sivlerlight <object> tag must have
// minRuntimeVersion set and should have autoUpgrade set to false.
//
//////////////////////////////////////////////////////////////////
Silverlight.IsVersionAvailableOnError = function (sender, args) {
    var retVal = false;
    try {
        if (args.ErrorCode == 8001 && !Silverlight.__installationEventFired) {
            Silverlight.onUpgradeRequired();
            Silverlight.__installationEventFired = true;
        }
        else if (args.ErrorCode == 8002 && !Silverlight.__installationEventFired) {
            Silverlight.onRestartRequired();
            Silverlight.__installationEventFired = true;
        }
        // this handles upgrades from 1.0. That control did not
        // understand the minRuntimeVerison parameter. It also
        // did not know how to parse XAP files, so would throw
        // Parse Error (5014). A Beta 2 control may throw 2106
        else if (args.ErrorCode == 5014 || args.ErrorCode == 2106) {
            if (Silverlight.__verifySilverlight2UpgradeSuccess(args.getHost())) {
                retVal = true;
            }
        }
        else {
            retVal = true;
        }
    }
    catch (e) {
    }
    return retVal;
};
//////////////////////////////////////////////////////////////////
//  
// IsVersionAvailableOnLoad:
//
// This function should be called at the beginning of a web page's
// Silverlight onLoad handler. It will determine if the required 
// version of Silverlight is installed and available in the 
// current process.
//
// During its execution the function will trigger one of the 
// Silverlight installation state events, if appropriate.
//
// Sender should be passed through from  the calling
// onError handler's parameters. 
//
// The associated Sivlerlight <object> tag must have
// minRuntimeVersion set and should have autoUpgrade set to false.
//
//////////////////////////////////////////////////////////////////
Silverlight.IsVersionAvailableOnLoad = function (sender) {
    var retVal = false;
    try {
        if (Silverlight.__verifySilverlight2UpgradeSuccess(sender.getHost())) {
            retVal = true;
        }
    }
    catch (e) {
    }
    return retVal;
};
//////////////////////////////////////////////////////////////////
//
// __verifySilverlight2UpgradeSuccess:
//
// This internal function helps identify installation state by
// taking advantage of behavioral differences between the
// 1.0 and 2.0 releases of Silverlight. 
//
//////////////////////////////////////////////////////////////////
Silverlight.__verifySilverlight2UpgradeSuccess = function (host) {
    var retVal = false;
    var version = "4.0.50401";
    var installationEvent = null;

    try {
        if (host.IsVersionSupported(version + ".99")) {
            installationEvent = Silverlight.onRequiredVersionAvailable;
            retVal = true;
        }
        else if (host.IsVersionSupported(version + ".0")) {
            installationEvent = Silverlight.onRestartRequired;
        }
        else {
            installationEvent = Silverlight.onUpgradeRequired;
        }

        if (installationEvent && !Silverlight.__installationEventFired) {
            installationEvent();
            Silverlight.__installationEventFired = true;
        }
    }
    catch (e) {
    }
    return retVal;
};;
///////////////////////////////////////////////////////////////////////////////
//  SLS.js   			version 1.0
//  Provides Microsoft logging support for Silverlight applications.
//  Copyright (c) Microsoft Corporation. All rights reserved.
///////////////////////////////////////////////////////////////////////////////

if (!window.SLS)
    window.SLS = {};

SLS.logIndex = 0;
SLS.logWaitTime = 1250;
SLS.stateShowInstall = 1;
SLS.stateShowUpgrade = 2;
SLS.stateShowUnsupported = 3;
SLS.stateShowRestart = 4;
SLS.stateChooseInstall = 5;
SLS.stateChooseUpgrade = 6;
SLS.stateChooseReject = 7;
SLS.stateChooseAbandon = 8;
SLS.stateSuccess = 10;
//SLS.hqPlayerMsLogUri = "http://msmmod.orcsweb.com/"; 

SLS.logEntryFlow = function () {
};

SLS.logExitFlow = function () {
};

SLS.logInstall = function (installState) {
//	try
//	{
//		// svc parameters
//		var u = SLS.hqAppSessionId;
//		var i = SLS.logCount++;
//		var t = new Date().getTime();
//
//		// append script tag
//		var src = SLS.hqPlayerMsLogUri + "/appevent.svc/parms?u=" + u + "&i=" + i + '&t=' + t + '&an=' + SLS.appName + '&av=' + SLS.appVersion;
//		SLS.appendScript(i, src);
//	}
//	catch (e)
//	{
//		SLS.handleError("SLS.logInstall", e);
//	}
};


SLS.getClientState = function () {
    try {
        if (!SLS.clientState) {
            var userAgent = SLS.parseUserAgent(navigator.userAgent);
            var version = SLS.parseVersion(SLS.minSilverlightVersion);
            var isMinVersionInstalled = Silverlight.isInstalled(SLS.minSilverlightVersion);

            SLS.clientState =
			{
			    userAgent: userAgent,
			    isInstallRequired: !isMinVersionInstalled,
			    isUpgradeRequired: !isMinVersionInstalled && Silverlight.isInstalled(),
			    isSupportedUserAgent: SLS.isSupportedUserAgent(userAgent, version),
			    isAllowedUnsupportedUserAgent: SLS.isAllowedUnsupportedUserAgent(userAgent, version)
			};
        }

        return SLS.clientState;
    }
    catch (x) {
        SLS.handleError("SLS.getClientState", x);
    }
};

SLS.getSessionCookieName = function () {
    try {
        return SLS.logName + "_session";
    }
    catch (x) {
        SLS.handleError("SLS.getSessionCookieName", x);
    }
};

SLS.getEntryFlowCookieName = function () {
    try {
        return SLS.logName + "_entryFlow";
    }
    catch (x) {
        SLS.handleError("SLS.getEntryFlowCookieName", x);
    }
};

SLS.getInstallCookieName = function () {
    try {
        return SLS.logName + "_install";
    }
    catch (x) {
        SLS.handleError("SLS.getInstallCookieName", x);
    }
};

SLS.getUnsupportedCookieName = function () {
    try {
        return SLS.logName + "_unsupported";
    }
    catch (x) {
        SLS.handleError("SLS.getUnsupportedCookieName", x);
    }
};

SLS.getScriptId = function (index) {
    try {
        return SLS.logName + "_script" + index;
    }
    catch (x) {
        SLS.handleError("SLS.getScriptId", x);
    }
};

SLS.getSessionId = function () {
    try {
        var value = SLS.getCookie(SLS.getSessionCookieName());

        if (!value) {
            value = SLS.getUniqueId();
            SLS.setCookie(SLS.getSessionCookieName(), value);
        }

        return value;
    }
    catch (x) {
        SLS.handleError("SLS.getSessionId", x);
    }
};

SLS.getUniqueId = function () {
    try {
        var value = "";

        for (var j = 0; j < 32; j++) {
            if (j == 8 || j == 12 || j == 16 || j == 20)
                value += "-";

            value += Math.floor(Math.random() * 16).toString(16);
        }

        return value;
    }
    catch (x) {
        SLS.handleError("SLS.getUniqueId", x);
    }
};

SLS.getSilverlight = function () {
    try {
        var state = SLS.getClientState();

        if (state.isAllowedUnsupportedUserAgent && state.userAgent.os == "Windows")
            Silverlight.followFWLink("156091"); // direct download link
        else
            Silverlight.followFWLink("149156&v=" + SLS.minSilverlightVersion);
    }
    catch (x) {
        SLS.handleError("SLS.getSilverlight", x);
    }
};

SLS.getCookie = function (name) {
    try {
        var cookie = document.cookie;

        if (cookie && cookie.length > 0) {
            var items = cookie.split(";");

            for (i = 0; i < items.length; i++) {
                var item = items[i].split("=");

                if (name == SLS.trim(unescape(item[0]))) {
                    var value = item[1];
                    return (value) ? unescape(value) : value;
                }
            }
        }

        return null;
    }
    catch (x) {
        SLS.handleError("SLS.getCookie", x);
    }
};

SLS.setCookie = function (name, value, hours) {
    try {
        if (hours) {
            var now = new Date().getTime();
            var expires = new Date(now + hours * 60 * 60 * 1000).toGMTString();
            document.cookie = name + "=" + value + ";expires=" + expires;
        }
        else {
            document.cookie = name + "=" + value;
        }
    }
    catch (x) {
        SLS.handleError("SLS.setCookie", x);
    }
};

SLS.clearCookie = function (name) {
    try {
        document.cookie = name + "=;expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
    catch (x) {
        SLS.handleError("SLS.clearCookie", x);
    }
};

SLS.appendScript = function (index, src) {
    try {
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.id = SLS.getScriptId(index);
        script.src = src;

        var head = document.getElementsByTagName("head")[0];
        head.appendChild(script);
    }
    catch (x) {
        SLS.handleError("SLS.appendScript", x);
    }
};

SLS.removeScript = function (index) {
    try {
        var id = SLS.getScriptId(index);
        var script = document.getElementById(id);

        if (script) {
            var head = document.getElementsByTagName("head")[0];
            head.removeChild(script);
        }
    }
    catch (x) {
        SLS.handleError("SLS.removeScript", x);
    }
};

SLS.spinWait = function (time) {
    try {
        if (time) {
            var start = new Date();

            while (new Date() - start < time)
                continue;
        }
    }
    catch (x) {
        SLS.handleError("SLS.spinWait", x);
    }
};

SLS.trim = function (value) {
    try {
        return value.replace(/^\s+|\s+$/g, "");
    }
    catch (x) {
        SLS.handleError("SLS.trim", x);
    }
};

SLS.isSupportedUserAgent = function (userAgent, version) {
    try {
        var ua = userAgent || SLS.parseUserAgent();
        var v = version || SLS.parseVersion();

        return !(
			(ua.os == "Unsupported") ||
			(ua.os == "Linux" && v > 1) ||
			(ua.os == "MacPPC" && v > 1) ||
			(ua.os == "MacPPC") ||
			(ua.os == "MacIntel") ||
			(ua.os == "Windows" && ua.browser == "Safari") ||
			(ua.browser == "Unsupported") ||
			(ua.browser == "Chrome") ||
			(ua.value.indexOf("Windows NT 5.0") >= 0 && v < 2));
    }
    catch (x) {
        SLS.handleError("SLS.isSupportedUserAgent", x);
    }
};

SLS.isAllowedUnsupportedUserAgent = function (userAgent, version) {
    try {
        var ua = userAgent || SLS.parseUserAgent();
        var v = version || SLS.parseVersion();

        return (
			(ua.os == "Windows" && ua.browser == "Chrome") ||
			(ua.os == "Linux" && v > 2));
    }
    catch (x) {
        SLS.handleError("SLS.isAllowedUnsupportedUserAgent", x);
    }
};

SLS.warnUnsupportedUserAgent = function (message) {
    try {
        var state = SLS.getClientState();

        if (!state.isSupportedUserAgent && SLS.getCookie(SLS.getUnsupportedCookieName()) != "1") {
            // prevent multiple calls
            SLS.setCookie(SLS.getUnsupportedCookieName(), "1", 8760);
            alert(message);
        }
    }
    catch (x) {
        SLS.handleError("SLS.warnUnsupportedUserAgent", x);
    }
};

SLS.parseUserAgent = function (value) {
    try {
        var ua = { value: value, os: "Unsupported", browser: "Unsupported" };

        if (ua.value.indexOf("Windows NT") >= 0 || ua.value.indexOf("Mozilla/4.0 (compatible; MSIE 6.0)") >= 0)
            ua.os = "Windows";
        else if (ua.value.indexOf("PPC Mac OS X") >= 0)
            ua.os = "MacPPC";
        else if (ua.value.indexOf("Intel Mac OS X") >= 0)
            ua.os = "MacIntel";
        else if (ua.value.indexOf("Linux") >= 0)
            ua.os = "Linux";

        if (ua.os != "Unsupported") {
            if (ua.value.indexOf("MSIE") >= 0) {
                if (ua.value.indexOf("Win64") == -1) {
                    if (parseInt(ua.value.split("MSIE")[1]) >= 6)
                        ua.browser = "MSIE";
                }
            }
            else if (ua.value.indexOf("Firefox") >= 0) {
                var array = ua.value.split("Firefox/")[1].split(".");
                var major = parseInt(array[0]);

                if (major >= 2) {
                    ua.browser = "Firefox";
                }
                else {
                    var minor = parseInt(array[1]);

                    if (major == 1 && minor >= 5)
                        ua.browser = "Firefox";
                }
            }
            else if (ua.value.indexOf("Chrome") >= 0) {
                ua.browser = "Chrome";
            }
            else if (ua.value.indexOf("Safari") >= 0) {
                ua.browser = "Safari";
            }
        }

        return ua;
    }
    catch (x) {
        SLS.handleError("SLS.parseUserAgent", x);
    }
};

SLS.parseVersion = function (value) {
    try {
        if (value) {
            var array = value.split(".");

            if (array.length > 1) {
                var major = parseInt(array[0]);

                if (isNaN(major) || major < 2)
                    return 1;
                else
                    return parseFloat(array[0] + "." + array[1]);
            }
        }

        return NaN;
    }
    catch (x) {
        SLS.handleError("SLS.parseVersion", x);
    }
};

SLS.handleError = function (source, error) {
    if (SLS.suppressErrors || !error)
        return;

    var msg = "Oops! An unexpected error occurred.\n";

    if (error.errorType) {
        if (error.errorType == "ImageError" || error.errorType == "MediaError")
            return;

        msg += "    \nSource: " + source;
        msg += "    \nCode: " + error.errorCode;
        msg += "    \nType: " + error.errorType;
        msg += "    \nMessage: " + error.errorMessage;

        if (error.errorType == "ParserError") {
            msg += "    \nFile: " + error.xamlFile;
            msg += "    \nLine: " + error.lineNumber;
            msg += "    \nPosition: " + error.charPosition;
        }
        else if (error.errorType == "RuntimeError") {
            if (error.lineNumber != 0) {
                msg += "    \nLine: " + error.lineNumber;
                msg += "    \nPosition: " + error.charPosition;
            }

            msg += "    \nMethod: " + error.methodName;
        }
    }
    else {
        msg += "    \nSource: " + source;
        msg += "    \nError: " + error;
    }

    throw new Error(msg);
};;
// namespaces
var Default = {};

//var bypass = false;
Default.progressBarWidth = 340;
Default.progressBarFudgeFactor = 1.05;
Default.stallLaunch = 750;
Default.displayRegions = ['startup','promptUnsupported','promptWarning','promptInstall','promptUgrade','promptFinishInstall','promptFinishUpgrading','threeDTV'];//,'silverlightControlHost'
Default.launch = function(){
	setTimeout("Default.showApp()",750);
}
//Default.showRegion = function(id) {
//	Default.hideRegions();
//	if(document.getElementById(id)){
//		document.getElementById(id).style.display='block';
//	}else{
//		//document.write('Missing '+id+' container - fatal error in web page elements');
//	}
//}
Default.hideRegions = function() {
	for(r in Default.displayRegions){
		var d = Default.displayRegions[r];
		//if(!document.getElementById(d)){
		//	var dc = document.createElement('div');
		//	dc.setAttribute('id',d);
		//	document.getElementById('wrapper').appendChild(dc);
		//}
		if(document.getElementById(d)){
			document.getElementById(d).style.display = 'none';
		}
	}
};

Default.showApp = function () {
//	var ua = navigator.userAgent;
//	if(ua.indexOf('Mac')>0){
//		Default.showRegion('threeDTV');
//		 $('#video-details').hide();
//         $('#catalog-wrapper').hide();
//	}else{
		try {
			var state = SLS.getClientState();
			//alert(state.isSupportedUserAgent + '\n'+state.isAllowedUnsupportedUserAgent);
			if (state.isSupportedUserAgent) {
				var slob =  '<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="640" height="360">\n';
					slob += '<param name="source" value="/files/PluginTester.xap"/>\n';
					slob += '<param name="onError" value="onSilverlightError" />\n';
					slob += '<param name="background" value="black" />\n';
					slob += '<param name="minRuntimeVersion" value="4.0.50303.0" />\n';
					slob += '<param name="autoUpgrade" value="true" />\n';
//					slob += '<param name="windowless" value="true" />\n';
					slob += '<param name="enableGPUAcceleration" value="true"/>\n';
//					slob += '<param name="onLoad" value="isLoaded" />\n';
					slob += '<param name="enablehtmlaccess" value="true"/>\n';
					slob += '<div id="SilverlightAlt"></div>\n';
					slob += '</object>\n';
					slob += '<script type="text/javascript">\n';
					slob += 'var SilverlightObject_OnLoad = Default.onSilverlightLoad;\n';
					slob += 'var SilverlightObject_OnError = Default.onSilverlightError;\n';
					slob += '</script>\n';
					document.getElementById('silverlightPluginTest').innerHTML = slob;
				
				document.getElementById('silverlightControlHost').style.display='block';
				$('#video-details').show();
	            $('#catalog-wrapper').show();	
				document.getElementById('install').style.display='none';
					
			}
			else {
				//Default.showPrompt('promptUnsupported');
				SLS.logInstall(SLS.stateShowUnsupported);
			}
		}
		catch (x) {
			SLS.handleError("Default.showApp", x);
		}
//	}
};

Default.showPrompt = function (prompt) {
	try {
		//Default.showRegion(prompt);
	}
	catch (x) {
		SLS.handleError("Default.showPrompt", x);
	}
};

Default.showHeader = function () {
	try {
	}
	catch (x) {
		SLS.handleError("Default.showHeader", x);
	}
};

Default.hideHeader = function () {
	try {
	}
	catch (x) {
		SLS.handleError("Default.hideHeader", x);
	}
};

Default.showSkinHeader = function (url) {
	try {
	}
	catch (x) {
		SLS.handleError("Default.showSkinHeader", x);
	}

}

Default.onPlayerLoaded = function () {
	try {
		window.setTimeout(Default.showHeader, 1200);
		SLS.warnUnsupportedUserAgent(Default.promptWarning);
	}
	catch (x) {
		SLS.handleError("Default.onPlayerLoaded", x);
	}
};


Default.onAdLoaded = function () {
	try {
	}
	catch (x) {
		SLS.handleError("Default.onAdLoaded", x);
	}
};

Default.showCompanionAd = function (url) {
	try {
	}
	catch (x) {
		SLS.handleError("Default.showCompanionAd", x);
	}
};

Default.onInstallSilverlightLinkClicked = function () {
	try {
		Default.showPrompt('promptFinishInstall');
		SLS.logInstall(SLS.stateChooseInstall);
		SLS.getSilverlight();
	}
	catch (x) {
		SLS.handleError("Default.onInstallSilverlightLinkClicked", x);
	}
};

Default.onUpgradeSilverlightLinkClicked = function () {
	try {
		Default.showPrompt('promptFinishUpgrade');
		SLS.logInstall(SLS.stateChooseUpgrade);
		SLS.getSilverlight();
	}
	catch (x) {
		SLS.handleError("Default.onUpgradeSilverlightLinkClicked", x);
	}
};

Default.onCancelSilverlightLinkClicked = function () {
	try {
		SLS.logInstall(SLS.stateChooseReject);
		//window.close();
	}
	catch (x) {
		SLS.handleError("Default.onCancelSilverlightLinkClicked", x);
	}
};

Default.onGetSilverlightLinkClicked = function () {
	try {
		SLS.getSilverlight();
	}
	catch (x) {
		SLS.handleError("Default.onGetSilverlightLinkClicked", x);
	}
};

Default.onStandardPlayerLinkClicked = function () {
	try {
	    window.close();
	}
	catch (x) {
		SLS.handleError("Default.onStandardPlayerLinkClicked", x);
	}
};

Default.onExternalLinkClicked = function () {
	try {
	}
	catch (x) {
		SLS.handleError("Default.onExternalLinkClicked", x);
	}
};

Default.onSilverlightLoad = function (sender) {
	try {
		if (Silverlight.IsVersionAvailableOnLoad(sender))
			SLS.logInstall(SLS.stateSuccess);
	}
	catch (x) {
		SLS.handleError("Default.onSilverlightLoad", x);
	}
};

Default.onSilverlightError = function (sender, e) {
	if (Silverlight.IsVersionAvailableOnError(sender, e))
		SLS.handleError("Default.onSilverlightError", e);
};

Silverlight.IsVersionAvailableOnLoad = function (sender) {
	try {
		var host = (sender) ? sender.getHost() : document.getElementById("SilverlightObject");
		return Silverlight.__verifySilverlight2UpgradeSuccess(host);
	}
	catch (x) {
		SLS.handleError("Silverlight.IsVersionAvailableOnLoad", x);
	}
};

Silverlight.onInstallRequired = function () {
	try {
		Default.showPrompt('promptInstall');
		SLS.logInstall(SLS.stateShowInstall);
	}
	catch (x) {
		SLS.handleError("Silverlight.onInstallRequired", x);
	}
};

Silverlight.onUpgradeRequired = function () {
	try {
		Default.showPrompt('promptUpgrade');
		SLS.logInstall(SLS.stateShowUpgrade);
	}
	catch (x) {
		SLS.handleError("Silverlight.onUpgradeRequired", x);
	}
};

Silverlight.onRestartRequired = function () {
	try {
		Default.showPrompt('promptRestart');
		SLS.logInstall(SLS.stateShowRestart);
	}
	catch (x) {
		SLS.handleError("Silverlight.onRestartRequired", x);
	}
};

Silverlight.onSilverlightInstalled = function () {
	try {
		var uri = Default.appLauncherPath;
		var query = window.location.search;

		if (query.length > 1)
			uri += "&" + query.substring(1);
		window.location.replace(uri);
	}
	catch (x) {
		SLS.handleError("Silverlight.onSilverlightInstalled", x);
	}
};

function onProgressChanged(sender, eventArgs) {	
}

function onDownloadComplete(sender, eventArgs) {
}
